为什么我可以清楚地看到服务已正确启动,但却超时了?

为什么我可以清楚地看到服务已正确启动,但却超时了?

这是我的日志:

Feb 10 10:19:25 ip-172-31-47-29 systemd[1]: Starting TNR Photo Download Service...
Feb 10 10:19:26 ip-172-31-47-29 tnr-photos[67938]: Server running on port 2200
Feb 10 10:20:56 ip-172-31-47-29 systemd[1]: tnr-photos.service: start operation timed out. Terminating.
Feb 10 10:20:56 ip-172-31-47-29 systemd[1]: tnr-photos.service: Failed with result 'timeout'.
Feb 10 10:20:56 ip-172-31-47-29 systemd[1]: Failed to start TNR Photo Download Service.
Feb 10 10:21:01 ip-172-31-47-29 systemd[1]: tnr-photos.service: Scheduled restart job, restart counter is at 14.
Feb 10 10:21:01 ip-172-31-47-29 systemd[1]: Stopped TNR Photo Download Service.
Feb 10 10:21:01 ip-172-31-47-29 systemd[1]: Starting TNR Photo Download Service...
Feb 10 10:21:01 ip-172-31-47-29 tnr-photos[67988]: Server running on port 2200
Feb 10 10:22:31 ip-172-31-47-29 systemd[1]: tnr-photos.service: start operation timed out. Terminating.
Feb 10 10:22:31 ip-172-31-47-29 systemd[1]: tnr-photos.service: Failed with result 'timeout'.
Feb 10 10:22:31 ip-172-31-47-29 systemd[1]: Failed to start TNR Photo Download Service.
Feb 10 10:22:36 ip-172-31-47-29 systemd[1]: tnr-photos.service: Scheduled restart job, restart counter is at 15.
Feb 10 10:22:36 ip-172-31-47-29 systemd[1]: Stopped TNR Photo Download Service.
Feb 10 10:22:36 ip-172-31-47-29 systemd[1]: Starting TNR Photo Download Service...
Feb 10 10:22:37 ip-172-31-47-29 tnr-photos[68036]: Server running on port 2200
Feb 10 10:24:07 ip-172-31-47-29 systemd[1]: tnr-photos.service: start operation timed out. Terminating.
Feb 10 10:24:07 ip-172-31-47-29 systemd[1]: tnr-photos.service: Failed with result 'timeout'.
Feb 10 10:24:07 ip-172-31-47-29 systemd[1]: Failed to start TNR Photo Download Service.
Feb 10 10:24:12 ip-172-31-47-29 systemd[1]: tnr-photos.service: Scheduled restart job, restart counter is at 16.
Feb 10 10:24:12 ip-172-31-47-29 systemd[1]: Stopped TNR Photo Download Service.
Feb 10 10:24:12 ip-172-31-47-29 systemd[1]: Starting TNR Photo Download Service...
Feb 10 10:24:12 ip-172-31-47-29 tnr-photos[68068]: Server running on port 2200
Feb 10 10:25:42 ip-172-31-47-29 systemd[1]: tnr-photos.service: start operation timed out. Terminating.
Feb 10 10:25:42 ip-172-31-47-29 systemd[1]: tnr-photos.service: Failed with result 'timeout'.
Feb 10 10:25:42 ip-172-31-47-29 systemd[1]: Failed to start TNR Photo Download Service.
Feb 10 10:25:47 ip-172-31-47-29 systemd[1]: tnr-photos.service: Scheduled restart job, restart counter is at 17.
Feb 10 10:25:47 ip-172-31-47-29 systemd[1]: Stopped TNR Photo Download Service.
Feb 10 10:25:47 ip-172-31-47-29 systemd[1]: Starting TNR Photo Download Service...
Feb 10 10:25:48 ip-172-31-47-29 tnr-photos[68101]: Server running on port 2200

该服务定义如下:

[Unit]
Description=TNR Photo Download Service
After=network.target

[Service]
Type=forking
User=ubuntu
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Restart=always
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=tnr-photos
WorkingDirectory=/home/ubuntu/tnr-web-photos
ExecStart=sudo /usr/bin/node /home/ubuntu/tnr-web-photos/index.js

[Install]
WantedBy=multi-user.target

这是一个非常简单的nodeJS服务器,所有的行都tnr-photos[68101]: Server running on port 2200表明它实际上正在正常启动。

怎么老是超时?

答案1

在我的评论中解释解决方案:某些应用程序不fork()按预期使用系统调用(或根本不使用),这可能会让人混淆systemd何时Type=forking设置。通常,可以通过设置来避免这种情况Type=simple

相关内容