前提
systemdにてサービスファイルを作成しています。(OSはCentOSです)
そのサービスファイルでシェルをExecStartすることによって起動、
ExecStopすることによって停止させる、という処理をしています。
ひとつのサービスファイルのなかでひとつのシェルを起動及び停止させるのは
まったく問題なくできるのですが、ひとつのサービスファイルのなかで複数のシェルを
起動及び停止させる方法がわからず困っており、力を貸していただきたいのです。
実現したいこと
「/etc/systemd/system/」に存在するserviceファイルによって、
「/data/app/service/」に存在する複数のシェル(.sh)を起動したいのです。
最終的には10個程度のシェルについて起動と停止をいったりきたりしたいのです。
①/etc/systemd/system/all.service
②/data/app/service/hoge.sh
③/data/app/service/fuga.sh
…
⑨/data/app/service/foo.sh
⑩/data/app/service/bar.sh
①をsystemctlでstartやstopさせることにより、②~⑩のシェルたちが起動と停止を往復できれば成功となります!!
発生している問題・エラーメッセージ
[user@hoshino ~]$ systemctl status all.service ● all.service - Hoge All Loaded: error (Reason: Invalid argument) Active: inactive (dead) 8月 29 13:31:07 hoshino systemd[1]: start request repeated too quickly for all.service 8月 29 13:31:07 hoshino systemd[1]: Failed to start Hoge All. 8月 29 13:31:07 hoshino systemd[1]: Unit all.service entered failed state. 8月 29 13:31:07 hoshino systemd[1]: all.service failed. 8月 29 13:31:37 hoshino systemd[1]: Starting Hoge All... 8月 29 13:31:37 hoshino systemd[1]: Started Hoge All. 8月 29 13:31:48 hoshino systemd[1]: Stopping Hoge All... 8月 29 13:31:48 hoshino systemd[1]: Stopped Hoge All. 8月 29 13:32:16 hoshino systemd[1]: all.service has more than one ExecStart= setting, which is only allowed...fusing. 8月 29 13:36:47 hoshino systemd[1]: all.service has more than one ExecStart= setting, which is only allowed...fusing. Hint: Some lines were ellipsized, use -l to show in full.
該当のソースコード
all.service
1[Unit] 2Description=Hoge All 3#After=httpd.serice 4 5[Service] 6ExecStart=/data/app/service/hoge.sh 7ExecStop=/bin/kill -WINCH ${MAINPID} 8ExecStart=/data/app/service/fuga.sh 9ExecStop=/bin/kill -WINCH ${MAINPID} 10Restart=always 11Type=forking 12User=hoshino 13Group=hoshino 14 15[Install] 16WantedBy=multi-user.target 17
動くソースコード(複数ではなく単数のシェル(hoge.sh)を動かすため、正常に動作する。PIDも取得可能)
all.service
1[Unit] 2Description=Hoge 3#After=httpd.serice 4 5[Service] 6ExecStart=/data/app/service/hoge.sh 7ExecStop=/bin/kill -WINCH ${MAINPID} 8Restart=always 9Type=forking 10User=hoshino 11Group=hoshino 12 13[Install] 14WantedBy=multi-user.target 15
↑こちらは正常にうごきます。ExecStartで指定しているシェルが複数ではなく「hoge.sh」のみのためそちらが起動します。systemctlでstopを実行すると、「hoge.sh」に割り当てられたプロセスIDを用いて正常にkillされます。
result(all.serviceによってhoge.shが正常に起動できているようす)
1[user@hoshino ~]$ sudo systemctl status all.service 2● all.service - Hoge 3 Loaded: loaded (/etc/systemd/system/all.service; disabled; vendor preset: disabled) 4 Active: active (running) since 月 2022-08-29 14:23:58 JST; 3min 13s ago 5 Process: 8204 ExecStart=/data/app/service/hoge.sh (code=exited, status=0/SUCCESS) 6 Main PID: 8206 (php) 7 Tasks: 1 8 CGroup: /system.slice/all.service 9 mq8206 php /data/app/develop/bin/cake.php Hoge 10 11 8月 29 14:23:58 hoshino systemd[1]: Starting Hoge... 12 8月 29 14:23:58 hoshino systemd[1]: Hoge.
試したこと
「サービス」「service」「systemd」「複数」「ExecStart」あたりの単語を組み合わせて検索を続けてはみたのですが、
これというサービスファイル内でのシェル複数起動の情報にたどりつくことができず、今回の質問を投稿させていただきました。
不足情報がございましたら追記したいので、ご指摘をお願いしたいです。
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/08/29 09:29
2022/08/30 01:56