使用systemctl stop XXX停止脚本失败后,将不会调用systemctl stop脚本

时间:2017-12-12 05:00:15

标签: centos7 systemctl

我使用squid.service文件,例如:

[Service]
Type=forking
ExecStart=/usr/local/squid/bin/squid start
ExecReload=/usr/local/squid/bin/squid reload
ExecStop=/usr/local/squid/bin/squid stop
KillMode=none

'/ usr / local / squid / bin / squid'是一个带有stop函数的shell脚本,在停止squid之前先检查squid.conf。

stop) { 
   $SQUID -k check >/dev/null 2>&1            
   RETVAL=$?
   if [ $RETVAL -eq 0 ] ; then
     do shutdown
   else
     echo "squid.conf is error"
   fi
   return $RETVAL
}

我们不会直接停止squid进程,因为担心首先squid.conf是正确的,squid的进程将正常运行,然后我们用错误的项修改squid.conf后重启squid,如果我们停止鱿鱼的进程成功,启动squid将因为错误的conf而失败。然后该服务将不可用。但是如果我们先检查squid.conf,进程就不会停止,所以服务仍然可用。

但是在centos7系统中,当我采取这些步骤时,会出现问题:

1. systemctl start squid with correct squid.conf , systemctl status squid will be active running;
2. modify squid.conf with wrong, type in 'systemctl stop squid', 'systemctl status squid' will show failed because of stop script checking conf and exiting with code 1;
3. I modify squid.conf correctly again, when I type in  'systemctl stop squid',the stop script will not be invoked at all(I have a test with echoing in stop function,but noting is echoed ). "ExecStop=/usr/local/squid /bin/squid stop" ;

所以如果那时我不能重启squid,我怎样才能在步骤3中再次启用'systemctl stop squid'调用'/ usr / local / squid / bin / squid stop'?

0 个答案:

没有答案