我使用 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' 是一个带有停止功能的 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 的进程,由于配置错误,启动squid会失败,然后服务将不可用。但是如果我们先检查squid.conf,进程不会停止,所以服务仍然可用。
但是在centos7系统中,当我这样做的时候,就会出错:</p>
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' call '/usr/local/squid /bin/squid stop'?