質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

Q&A

解決済

2回答

389閲覧

CentOS 7でスクリプトをサービス起動するとプロセスが落ちてしまいます

programmer010

総合スコア14

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

0グッド

0クリップ

投稿2017/12/22 02:35

編集2017/12/22 04:42

CentOS 7でスクリプトをサービス起動するとプロセスが落ちてしまいます。
ただし、スクリプトを単体で実行するとプロセスは落ちません。

もし原因がおわかりの方がおられましたら、ご教授いただけると幸いです。

何卒、よろしくお願い申し上げます。

###対象ファイル
■スクリプト(/opt/Server.sh)

#!/bin/bash dotnet /opt/Server/Server.Service.dll

■.serviceファイル(/etc/systemd/system/Server.service)

[Unit] Description = Server daemon After = postgresql-9.6.service [Service] ExecStart = /opt/Server.sh Restart = no Type = simple RemainAfterExit = yes [Install] WantedBy = multi-user.target

###実行結果
■スクリプト実行

[root@localhost ~]# /opt/Server.sh [root@localhost ~]# ps aux | grep -e Server -e postgres postgres 970 0.0 1.4 358712 15492 ? Ss 12月21 0:01 /usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data/ postgres 1073 0.0 0.1 211588 1736 ? Ss 12月21 0:00 postgres: logger process postgres 1075 0.0 0.3 358832 3452 ? Ss 12月21 0:00 postgres: checkpointer process postgres 1076 0.0 0.2 358712 2732 ? Ss 12月21 0:01 postgres: writer process postgres 1077 0.0 0.1 358712 1704 ? Ss 12月21 0:01 postgres: wal writer process postgres 1078 0.0 0.2 359136 2912 ? Ss 12月21 0:01 postgres: autovacuum launcher process postgres 1079 0.0 0.1 213844 1984 ? Ss 12月21 0:02 postgres: stats collector process root 4026 0.0 0.1 113128 1188 pts/2 S+ 10:58 0:00 /bin/bash /opt/Server.sh root 4027 13.4 32.1 3045132 355180 pts/2 SLl+ 10:58 0:50 dotnet /opt/Server/Server.Service.dll postgres 4034 0.0 0.6 360536 7364 ? Ss 10:58 0:00 postgres: db_admin testdb ::1(37332) idle root 4103 0.0 0.0 112676 980 pts/3 R+ 11:04 0:00 grep --color=auto -e Server -e postgres

■サービス起動

[root@localhost ~]# systemctl start Server [root@localhost ~]# systemctl status Server ● Server.service - Server daemon Loaded: loaded (/etc/systemd/system/Server.service; enabled; vendor preset: disabled) Active: active (exited) since 金 2017-12-22 11:11:46 JST; 8s ago Process: 4139 ExecStart=/opt/Server.sh (code=exited, status=0/SUCCESS) Main PID: 4139 (code=exited, status=0/SUCCESS) [root@localhost ~]# ps aux | grep -e Server -e postgres postgres 970 0.0 1.4 358712 15492 ? Ss 12月21 0:01 /usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data/ postgres 1073 0.0 0.1 211588 1736 ? Ss 12月21 0:00 postgres: logger process postgres 1075 0.0 0.3 358832 3452 ? Ss 12月21 0:00 postgres: checkpointer process postgres 1076 0.0 0.2 358712 2732 ? Ss 12月21 0:01 postgres: writer process postgres 1077 0.0 0.1 358712 1704 ? Ss 12月21 0:01 postgres: wal writer process postgres 1078 0.0 0.2 359136 2912 ? Ss 12月21 0:01 postgres: autovacuum launcher process postgres 1079 0.0 0.1 213844 1984 ? Ss 12月21 0:02 postgres: stats collector process root 4172 0.0 0.0 112676 980 pts/3 R+ 11:19 0:00 grep --color=auto -e Server -e postgres

<追記>
ちなみに、同じようなスクリプトをサービス起動するとプロセスは起動したままになります。

###対象ファイル
■スクリプト(/opt/Send.sh)

#!/bin/bash dotnet /opt/Send/Send.Service.dll

■.serviceファイル(/etc/systemd/system/Send.service)

[Unit] Description = Send daemon After = Server.service [Service] ExecStart = /opt/Send.sh Restart = no Type = simple RemainAfterExit = yes [Install] WantedBy = multi-user.target

###実行結果
■スクリプト実行

[root@localhost ~]# /opt/Send.sh [root@localhost ~]# ps aux | grep -e Send root 4552 0.0 0.1 113128 1188 pts/2 S+ 13:20 0:00 /bin/bash /opt/Send.sh root 4553 0.5 4.6 2653372 51032 pts/2 SLl+ 13:20 0:00 dotnet /opt/Send/Send.Service.dll root 4567 0.0 0.0 112676 980 pts/3 R+ 13:21 0:00 grep --color=auto -e Send

■サービス起動

[root@localhost ~]# systemctl start Send [root@localhost ~]# systemctl status Send ● Send.service - Send daemon Loaded: loaded (/etc/systemd/system/Send.service; enabled; vendor preset: disabled) Active: active (running) since 金 2017-12-22 13:26:01 JST; 2min 20s ago Main PID: 4588 (Send.sh) CGroup: /system.slice/Send.service ├─4588 /bin/bash /opt/Send.sh └─4589 dotnet /opt/Send/Send.Service.dll 12月 22 13:26:01 localhost.localdomain systemd[1]: Started Send daemon. 12月 22 13:26:01 localhost.localdomain systemd[1]: Starting Send daemon... [root@localhost ~]# ps aux | grep -e Send root 4588 0.0 0.1 115252 1448 ? Ss 13:26 0:00 /bin/bash /opt/Send.sh root 4589 0.2 4.5 2653236 50428 ? SLl 13:26 0:00 dotnet /opt/Send/Send.Service.dll root 4612 0.0 0.0 112676 980 pts/3 R+ 13:31 0:00 grep --color=auto -e Send

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

systemdから起動される環境では、環境変数やPATHなどが必要最小限しか設定されていないので、必要なものはスクリプトの中で自前で設定して下さい。
例えば、dotnetコマンドにはパスが通っていますか?

スクリプトの中に、以下のコマンドを入れて確認して下さい。

printenv > /tmp/Server.log

投稿2017/12/22 02:45

編集2017/12/22 02:46
hichon

総合スコア5737

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

programmer010

2017/12/22 04:48

早速のご回答ありがとうございます。 教えていただいた内容を確認しましたが、dotnetコマンドにはパスは通っています。 サービス起動すると、アプリログ出力およびDB書き込みはされていますので、 一旦はプロセスが起動し、直後に停止しているようです。 </tmp/Server.log> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin PWD=/ LANG=ja_JP.UTF-8 SHLVL=1 _=/usr/bin/printenv 内容を追記しましたが、同じようなスクリプトをサービス起動するとプロセスは起動したままになります。 よろしくお願い申し上げます。
hichon

2017/12/22 12:54

なるほど。スクリプトのコマンドの後ろに以下を追加してエラーが出ていないか確認して下さい。 dotnet /opt/Send/Send.Service.dll > /tmp/Server.log 1>&2
programmer010

2017/12/25 02:22

度々のご回答ありがとうございます。 その後、いろいろと確認したところ、アプリ側の問題であることがわかりました。 お手数をお掛けして、申し訳ございませんでした。
guest

0

自己解決

アプリ側の問題でした。
大変失礼いたしました。

投稿2017/12/25 02:20

programmer010

総合スコア14

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問