![Systemd服务没有重新启动,没有失败的解释](https://linux22.com/image/141649/Systemd%E6%9C%8D%E5%8A%A1%E6%B2%A1%E6%9C%89%E9%87%8D%E6%96%B0%E5%90%AF%E5%8A%A8%EF%BC%8C%E6%B2%A1%E6%9C%89%E5%A4%B1%E8%B4%A5%E7%9A%84%E8%A7%A3%E9%87%8A.png)
当我的服务失败时,我得到以下输出:
Nov 06 10:23:55 irgprod2 systemd[1]: emsxsub.service: Unit entered failed state.
Nov 06 10:23:55 irgprod2 systemd[1]: emsxsub.service: Failed with result 'exit-code'.
Nov 06 10:23:58 irgprod2 systemd[1]: emsxsub.service: Service hold-off time over, scheduling restart.
Nov 06 10:23:58 irgprod2 systemd[1]: Stopped EMSX API Subscription.
没有解释出了什么问题或为什么服务没有重新启动,也没有提到“启动限制”或任何内容。这是过程:
[Unit]
Description=EMSX API Subscription
After=multi-user.target
[Service]
Type=simple
Restart=always
RestartSec=3
User=root
Environment=PYTHONPATH=/k/svn_prod
Environment=LD_LIBRARY_PATH=/opt/lib
ExecStart=/usr/bin/python /k/svn_prod/com_wrappers/bbg_emsxsub.py
RemainAfterExit=no
[Install]
WantedBy=multi-user.target
我尝试过不使用 User arg、不使用 RemainAfterExit arg 等。systemctl 进程已启用,当我执行“service emsxsub restart”时,该进程运行并成功重新启动。只有当失败时,systemd 才会安排重新启动,然后停止服务而无法成功重新启动它。我找不到其他人遇到这个问题 - 其他问题似乎是“开始限制”错误,但这里不是这种情况。以前有人见过这个问题吗?我不明白为什么手动重新启动时一切正常,但服务在失败时无法自行重新启动。
这是journalctl 输出:
Nov 06 10:23:55 irgprod2 python[18451]: Traceback (most recent call last):
Nov 06 10:23:55 irgprod2 python[18451]: File "/k/svn_prod/com_wrappers/bbg_emsxsub.py", line 533, in <module>
Nov 06 10:23:55 irgprod2 python[18451]: main()
Nov 06 10:23:55 irgprod2 python[18451]: File "/k/svn_prod/com_wrappers/bbg_emsxsub.py", line 505, in main
Nov 06 10:23:55 irgprod2 python[18451]: raise RuntimeError() # raise error so process restarts
Nov 06 10:23:55 irgprod2 python[18451]: RuntimeError
Nov 06 10:23:55 irgprod2 systemd[1]: emsxsub.service: Main process exited, code=exited, status=1/FAILURE
Nov 06 10:23:55 irgprod2 systemd[1]: emsxsub.service: Unit entered failed state.
Nov 06 10:23:55 irgprod2 systemd[1]: emsxsub.service: Failed with result 'exit-code'.
Nov 06 10:23:58 irgprod2 systemd[1]: emsxsub.service: Service hold-off time over, scheduling restart.
Nov 06 10:23:58 irgprod2 systemd[1]: Stopped EMSX API Subscription.
输出systemctl status emsxsub.service
:
* emsxsub.service - EMSX API Subscription
Loaded: loaded (/lib/systemd/system/emsxsub.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Wed 2018-11-07 08:18:49 EST; 40s ago
Process: 3936 ExecStart=/usr/bin/python /k/svn_prod/com_wrappers/bbg_emsxsub.py (code=exited, status=1/FAILURE)
Main PID: 3936 (code=exited, status=1/FAILURE)
Nov 07 08:18:45 irgprod2 systemd[1]: emsxsub.service: Unit entered failed state.
Nov 07 08:18:45 irgprod2 systemd[1]: emsxsub.service: Failed with result 'exit-code'.
Nov 07 08:18:49 irgprod2 systemd[1]: emsxsub.service: Service hold-off time over, scheduling restart.
Nov 07 08:18:49 irgprod2 systemd[1]: Stopped EMSX API Subscription.
输出systemctl show emsxsub.service | grep -i restart
:
[trading@irgprod2 ~]$ systemctl show emsxsub.service | grep -i restart
Restart=always
RestartUSec=3s
系统控制版本:
systemd 229
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN
发行版详细信息:
[trading@irgprod2 ~]$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
答案1
删除After=multi-user.target
解决了问题。 Filipe 对循环依赖的观察似乎是正确的。