web-dev-qa-db-ja.com

Systemdサービススクリプトがエコーしない

最近、Fedora 22をマシンにセットアップし、systemdinitシステムを使用しています。

私はそれを読んでいます、そして今私はpostgresqlのためのsystemd起動スクリプトを作成する必要があります

テストのために、次のシェルスクリプトhello_worldを作成しました

#! /bin/sh
#  testing systemctl script

start() {
   echo "Executing Start"
   echo "Testing 01"
   echo "Testing 02"
   echo "Testing 03"
}

stop() {
   echo "Stopping Hello World Script"
}

case "$1" in
   start)
      start
   ;;
   stop)
      stop
   ;;
   restart)
      stop
      sleep 2
      start
   ;; 
   *) exit 1
esac

ターミナルを使用して実行すると、期待どおりに実行され、文字列がエコーされます。

. hello_world start

これは「StartingHelloWorld Script」をエコーし​​、それを/ usr/lib/systemd/scripts内に配置しました

次に、次のようにsystemdサービススクリプトを作成しようとしました。hello_world.service

[Unit]
Description=Hello World Testing Script

[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/hello_world start
ExecStop=/usr/lib/systemd/scripts/hello_world stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

/ usr/lib/systemd/system内に配置し、で実行しようとしました

systemctl start hello_world.service

エラーは発生しませんでしたが、hello_worldスクリプトを単独で実行したときに期待したエコー文字列が得られませんでした。

それで、それが実際に機能しているかどうかわかりません、私は何かを逃しましたか? systemctlコマンドがスクリプトから文字列をエコーし​​ないのはなぜですか?

4

スクリプトの出力は端末に送信されず、代わりにstatusコマンドにリダイレクトされるようです。

サービスの実行後

# systemctl start hello_world.service

ステータスで出力を表示できます

# systemctl status hello_world.service

以下のようなスクリプトからの出力が含まれます

Apr 28 10:18:00 centos7.adminserv systemd[1]: Starting Hello World Testing S....
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Executing Start
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 01
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 02
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 03
Apr 28 10:18:00 centos7.adminserv systemd[1]: Started Hello World Testing Sc.... 
1