systemdでデーモンとして実行(実行可能)しているC++ベースのアプリケーションがあります。
ユニットファイル:
[Unit]
Description=Console Service
After=network.target
[Service]
Environment="USER=ubuntu" "Path=/home/ubuntu/console/bin"
WorkingDirectory=/home/ubuntu/console/bin
ExecStart=/bin/sh -ec "exec /sbin/start-stop-daemon -S -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --oknodo --exec consoleExecutable " #2>/dev/null
ExecStop=/bin/sh -ec "exec /sbin/start-stop-daemon -K --quiet -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --retry=TERM/30/KILL/5 --oknodo --exec consoleExecutable" #2>/dev/null
Restart=on-failure
RemainAfterExit=no
TimeoutStopSec=10
SuccessExitStatus=0 1
TimeoutStartSec=360
[Install]
WantedBy=multi-user.target
startコマンドを発行すると、サービスは起動していますが、すぐにシャットダウンシグナルを受信して終了します。
手がかりはありますか?
sudo systemctl status console.service
● console.service - Console Service
Loaded: loaded (/etc/systemd/system/console.service; enabled; vendor preset: enabled)
Active: deactivating (stop-sigterm) since Mon 2017-09-25 19:58:58 UTC; 1s ago
Process: 8706 ExecStop=/bin/sh -ec exec /sbin/start-stop-daemon -K --quiet -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --retry=TERM/30/KILL/5 --oknodo --exec consoleExecutable #2>/dev/null (code=exited, status=0/SUCCESS)
Process: 8701 ExecStart=/bin/sh -ec exec /sbin/start-stop-daemon -S -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --oknodo --exec consoleExecutable #2>/dev/null (code=exited, status=0/SUCCESS)
Main PID: 8701 (code=exited, status=0/SUCCESS)
Tasks: 1
Memory: 1.8M
CPU: 53ms
CGroup: /system.slice/console.service
└─8705 consoleExecutable
Sep 25 19:58:58 mgmt1 systemd[1]: Started Console Service.
sudo systemctl status console.service
● console.service - Console Service
Loaded: loaded (/etc/systemd/system/console.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2017-09-25 19:59:01 UTC; 947ms ago
Process: 8706 ExecStop=/bin/sh -ec exec /sbin/start-stop-daemon -K --quiet -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --retry=TERM/30/KILL/5 --oknodo --exec consoleExecutable #2>/dev/null (code=exited, status=0/SUCCESS)
Process: 8701 ExecStart=/bin/sh -ec exec /sbin/start-stop-daemon -S -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --oknodo --exec consoleExecutable #2>/dev/null (code=exited, status=0/SUCCESS)
Main PID: 8701 (code=exited, status=0/SUCCESS)
Sep 25 19:58:58 mgmt1 systemd[1]: Started Console Service.
承認された回答:
Environment="USER=ubuntu" "Path=/home/ubuntu/console/bin"
WorkingDirectory=/home/ubuntu/console/bin
ExecStart=/bin/sh -ec "exec /sbin/start-stop-daemon -S -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --oknodo --exec consoleExecutable " #2>/dev/null
ExecStop=/bin/sh -ec "exec /sbin/start-stop-daemon -K --quiet -c ${USER} -d ${Path} --pidfile=/var/run/console.pid --retry=TERM/30/KILL/5 --oknodo --exec consoleExecutable" #2>/dev/null これは、systemdのHouseofHorrorにほぼ値します。これを行うホラーストーリーがすでにそこにあるわけではありませんでした。
start-stop-daemonは使用しないでください サービスユニットでサービスユニットがすでに実行しているすべてのことを実行する 。不要なPIDファイルとExecStartという誤った想定 シェル構文コメントを受け入れます。
そして、他の答えが言っていることをしないで、Type=forkingでそれを覆い隠そうとします 。それは事態を悪化させますが、良くはしません。
start-stop-daemonのナンセンス 物事がうまくいかない理由です。 start-stop-daemonを実行しているプロセスが にならない サービスですが、実際にはほとんどすぐに終了します。systemdは、サービスが終了していると考えています。最初のsystemctl status 出力を見ると、systemdがSIGTERMを送信している途中であることがわかります。 ExecStopを実行した後、残りの実行中のプロセスをすべてクリーンアップします アクション。これは、サービスが終了したと見なしたときに実行されます。
単純に物事を行う:
Type=simple WorkingDirectory=/home/ubuntu/console/bin User=ubuntu ExecStart=/home/ubuntu/console/bin/consoleExecutable
ExecStopはありません Environmentも 実際に必要です。
さらに読む
- ジョナサンデボインポラード(2015)。 実際にデーモン化する必要はありません。本当に。 。システム化されたHouseofHorror。
- ジョナサンデボインポラード(2016)。 2つのサービスがある場合は、2つのサービスを定義します。 。システム化されたHouseofHorror。
- ジョナサンデボインポラード(2015)。 Unixデーモンの準備プロトコルの問題 。頻繁に与えられる回答。
- Systemdは開始直後にサービスを強制終了します