我的 systemd/system/my_service.service 有什么问题吗?

我的 systemd/system/my_service.service 有什么问题吗?

这是我的服务文件。

[Unit]
Description=my_service

[Service]
ExecStart=/home/ubuntu/my_scripts/script.sh
Restart=always
Type=simple

这是/home/ubuntu/my_scripts/script.sh

#!/bin/bash

export PYTHONPATH=/home/ubuntu/my_app
cd /home/ubuntu/my_app
python /home/ubuntu/my_app/my_python_script.py

/home/ubuntu/my_scripts/script.sh当在终端中输入命令时,它运行良好。

但像这样的 systemd 服务却失败了。

● my_service.service - my_service
   Loaded: loaded (/etc/systemd/system/my_service.service; static; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2020-07-14 07:12:15 UTC; 4s ago
  Process: 20713 ExecStart=/home/ubuntu/my_scripts/script.sh (code=exited, status=1/FAILURE)
 Main PID: 20713 (code=exited, status=1/FAILURE)

Jul 14 07:12:15 ip-172-31-4-214 systemd[1]: my_service.service: Service hold-off time over, scheduling restart.
Jul 14 07:12:15 ip-172-31-4-214 systemd[1]:my_service.service: Scheduled restart job, restart counter is at 5.
Jul 14 07:12:15 ip-172-31-4-214 systemd[1]: Stopped job_executor.
Jul 14 07:12:15 ip-172-31-4-214 systemd[1]: my_service.service: Start request repeated too quickly.
Jul 14 07:12:15 ip-172-31-4-214 systemd[1]: my_service.service: Failed with result 'exit-code'.
Jul 14 07:12:15 ip-172-31-4-214 systemd[1]: Failed to start my_service.

怎么了?


谢谢你的评论!所以我将我的服务文件更改为以下内容,

[Unit]
Description=my_service

[Service]
ExecStart=/home/ubuntu/my_scripts/script.sh
Restart=always
Type=forking

错误消息已更改。

Job for my_service.service failed because the control process exited with error code.
See "systemctl status my_service.service" and "journalctl -xe" for details.

所以我输入了systemctl status my_service.service

● my_service.service - my_service
   Loaded: loaded (/etc/systemd/system/my_service.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2020-07-14 07:38:27 UTC; 3s ago
  Process: 26815 ExecStart=/home/ubuntu/my_scripts/script.sh (code=exited, status=1/FAILURE)

相关内容