当服务器进入待机状态并再次启动时,我的 systemd 服务(类型为通知)不会启动

当服务器进入待机状态并再次启动时,我的 systemd 服务(类型为通知)不会启动

我第一次设置 systemd 服务时,它运行良好。

但是,当我重新启动服务器时,systemd 服务并没有启动,但它仍然保持开启状态activating

有人可以提示一下为什么会发生这种情况吗?

单元文件:

[Unit]
Description=My App
After=network.service
StopWhenUnneeded=yes

[Service]
Type=notify
NotifyAccess=all
User=ubuntu
Group=ubuntu

WorkingDirectory=/opt/app
KillMode=process
PIDFile=/tmp/app%I.pid
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=app%I
Environment=SOCKET=/tmp/thin-%I.socket
ExecStart=/opt/app/bin/start
ExecReload=/opt/app/bin/reload
ExecStop=/opt/app/bin/stop
Restart=always
LimitNOFILE=10240
CPUQuota=90%

[Install]
WantedBy=app.target

日志来自journalctl -xe

Nov 10 20:51:35 hostname systemd[1]: [email protected]: Start operation timed out. Terminating.
Nov 10 20:51:35 hostname systemd[1]: [email protected]: Failed with result 'timeout'.
Nov 10 20:51:35 hostname systemd[1]: Failed to start My App.
-- Subject: Unit [email protected] has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit [email protected] has failed.
--
-- The result is RESULT.
Nov 10 20:51:35 hostname systemd[1]: [email protected]: Service hold-off time over, scheduling restart.
Nov 10 20:51:35 hostname systemd[1]: [email protected]: Scheduled restart job, restart counter is at 4.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Automatic restarting of the unit [email protected] has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Nov 10 20:51:35 hostname systemd[1]: Stopped My App.
-- Subject: Unit [email protected] has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit [email protected] has finished shutting down.
Nov 10 20:51:35 hostname systemd[1]: Starting My App...
-- Subject: Unit [email protected] has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit [email protected] has begun starting up.

我不确定我能提供什么信息来帮助你帮助我。如果我可以提供任何信息,你可以在评论中问我。

答案1

我发现了发生了什么事。

应用程序需要更多时间才能启动,但 systemd 总是在它启动并通知之前将其终止。这种情况只发生在启动时,因为应用程序在系统启动时需要更多时间才能启动。

所以我需要添加一个更大的TimeoutSec,然后它就可以正常工作。

相关内容