私の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端末に命令を入力するとうまく動作します。

ただし、このようなシステムサービスは失敗します。

● 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)

ベストアンサー1

おすすめ記事