systemd即使使用不正确的ExecStop也会停止进程

时间:2017-09-05 09:31:49

标签: linux redis systemd

我正在尝试使用systemd管理多个redis实例。下面是我的systemd单元文件

[Unit]
Description=Redis instances
After=network.target

[Service]
Type=simple
ExecStart=/home/redis/bin/redis-server /home/redis/conf/redis-%i.conf
ExecStop=/home/redis/bin/redis-cli -p %i INFO   # <= INFO should not stop redis process
User=redis
Group=redis

[Install]
WantedBy=multi-user.target

我可以通过

成功启动redis-server
$ sudo systemctl start redis@6379

$ systemctl status redis@6379
● redis@6379.service - Redis instances
   Loaded: loaded (/usr/lib/systemd/system/redis@.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-09-05 17:48:42 JST; 2h 52min ago
 Main PID: 86962 (redis-server)
   CGroup: /system.slice/system-redis.slice/redis@6379.service
           └─86962 /home/redis/bin/redis-server 0.0.0.0:6379 [cluster]

作为停止redis-server的测试,我故意在ExecStop行使用INFO而不是SHUTDOWN。

但是当我执行下面的命令时,systemd仍然杀死了我的redis进程。

sudo systemctl stop redis@6379

并且没有输出:

sudo journalctl -f -u redis@6379

我想知道这怎么可能发生?

PS:

我用不存在的redis-cli替换了redis-cli:

ExecStop=/tmp/nonexist

journalctl显示错误日志,如:

Sep 05 20:51:57 myhost systemd[96306]: Failed at step EXEC spawning /tmp/nonexist: No such file or directory
Sep 05 20:51:57 myhost systemd[1]: redis@6379.service: control process exited, code=exited status=203
Sep 05 20:51:57 myhost systemd[1]: Unit redis@6379.service entered failed state.
Sep 05 20:51:57 myhost systemd[1]: redis@6379.service failed.

但正在运行的redis进程仍然被杀死。

0 个答案:

没有答案