CentOS 7 将多​​进程初始化脚本转换为 systemd 服务

CentOS 7 将多​​进程初始化脚本转换为 systemd 服务

我有一个初始化脚本,如下所示

#!/bin/bash
# description: connect start | stop | restart | install
# processname: tomcat
# chkconfig: 234 99 01
JAVA_HOME=/
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/
ulimit -v unlimited -m..
LOG_COPY_FOLDER=$(date +"%Y-%m-%d_%H%M")

case $1 in
start)
JAVA_OPTS='-Xms160g -Xmx160g -XX:+ResetSignal_MaskAtLaunch -Xloggc:/tom....'
    export JAVA_OPTS
    echo "Using JAVA_OPTS:       $JAVA_OPTS"
find $CATALINA_HOME/logs_prev/* -type d -ctime +180 | xargs rm -rf
mv $CATALINA_HOME/logs $CATALINA_HOME/logs_prev/$LOG_COPY_FOLDER
    mkdir $CATALINA_HOME/logs
    nohup sh $CATALINA_HOME/bin/startup.sh
  less $CATALINA_HOME/logs/catalina.out
;;
stop)
    sh $CATALINA_HOME/bin/shutdown.sh
;;
install)
MySQLConfirmation() {
    while :
    do
        read -p 'Have you run MySQL commands? (y/n): ' answer
            case "${answer}" in
                    y|Y|yes|Yes) exit 0 ;;
                    n|N|no|No) exit 1 ;;
            esac
    done
}

if $( MySQLConfirmation ); then
        JAVA_OPTS='-Xms160g -Xmx160g -XX:+ResetSignalMaskAtLaunch -Xloggc:/tom...
        export JAVA_OPTS
        echo "Using JAVA_OPTS:       $JAVA_OPTS"
    find $CATALINA_HOME/logs_prev/* -type d -ctime +30 | xargs rm -rf
    mv $CATALINA_HOME/logs $CATALINA_HOME/logs_prev/$LOG_COPY_FOLDER
        **rm -R $CATALINA_HOME/website.com/ROOT**
        mkdir $CATALINA_HOME/logs
        **mv -f /root/website.war $CATALINA_HOME/websitcom/ROOT.war**
        nohup sh $CATALINA_HOME/bin/startup.sh
        less $CATALINA_HOME/logs/catalina.out
else
            echo "See you when you're done with MySQL updates!"
    fi
;;
esac
exit 0

如您所见,我已经启动、停止、重新启动和安装进程。而安装进程需要删除和 mkdir 命令,我不知道如何在 systemd 进程上实现这些命令,因为我看不到添加进程以便能够像“systemctl qinstall service”那样运行的方法。有没有办法向 systemd 添加 Execinstall 和 ExecinstallPre 参数?谢谢

答案1

systemd不支持自定义动作名称install,它专注于流程管理。

相关内容