Linux平台需要自定义一个服务文件.
假如应用所在目录为:/usr/local/FreeCert_CertDeployTool/,下面是配置脚本:
首先需要给应用目录设置执行权限.
sudo chmod 777 -R /usr/local/FreeCert_CertDeployTool
接着创建服务定义文件.
sudo vim /etc/systemd/system/freecert-certdeploytool
[Unit]
Description=FreeCert_CertDeployTool
[Service]
WorkingDirectory=/usr/local/FreeCert_CertDeployTool
ExecStart=/usr/local/FreeCert_CertDeployTool/FreeSSL.CertDeployTool
Restart=always
RestartSec=60
KillSignal=SIGINT
SyslogIdentifier=FreeCert_CertDeployTool
User=root
[Install]
WantedBy=multi-user.target
保存该文件并启用该服务.
sudo systemctl enable freecert-certdeploytool
启动服务,并确认服务为运行状态.
sudo systemctl start freecert-certdeploytool
sudo systemctl status freecert-certdeploytool
以上是CentOS 7+版本的脚本,如果是CentOS 6.x版本的操作系统,下面是参考代码.
假如应用所在目录为:/usr/local/FreeCert_CertDeployTool/,下面是配置脚本:
首先需要给应用目录设置执行权限.
sudo chmod 777 -R /usr/local/FreeCert_CertDeployTool
接着创建服务定义文件.
sudo vim /etc/init.d/freecert-certdeploytool
#!/bin/sh
#chkconfig: 2345 90 10
# description: CertDeployTool
# Source function library.
. /etc/init.d/functions
# 请输入应用所在目录
WorkingDirectory=/usr/local/FreeCert_CertDeployTool
# 以下参数无需关注
prog=FreeSSL.CertDeployTool
LockFile=/var/lock/subsys/FreeCert.CertDeployTool
start() {
[ -f $LockFile ] && echo "$prog Already Started " && exit 0
cd $WorkingDirectory
echo "Starting $prog ..."
daemon ./$prog &
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LockFile && echo -e "\e[31m Press Enter to exit the message display \e[0m"
echo
return $RETVAL
exit 0;
}
stop() {
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LockFile
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
保存该文件并启动服务.
service freecert-certdeploytool start
并确认服务为运行状态.
service freecert-certdeploytool status
停止服务脚本.
service freecert-certdeploytool stop