2019-12-27 :-|
_ [Linux][ubuntu][start-stop-daemon]start-stop-daemon を試す
ref. Ubuntu Manpage: start-stop-daemon - システムデーモンプログラムの起動、停止
こんな
#!/bin/bash
main()
{
  while true
  do
    sleep 5
    echo hoge
  done
}
main
開始
start-stop-daemon \
  --start --oknodo \
  --background \
  --make-pidfile \
  --pidfile ${PWD}/daemon.pid \
  --exec ${PWD}/daemon0.sh
停止
start-stop-daemon \
  --stop --oknodo \
  --remove-pidfile \
  --pidfile ${PWD}/daemon.pid
start-stop-daemon のバージョンが古い場合 pid ファイルは削除してくれないので自分で削除する。
rm ${PWD}/daemon.pid
オプション
--oknodo
-S, --start [--] arguments
      指定されたプロセスの存在を確認する。該当するプロセスが存在する場合、
      start-stop-daemon  は何もせず、エラーステータス 1 を返して終了する (--oknodo が指定
      された場合は、0 を返す)。
-o, --oknodo
      処理が何も行われない (又は、行なわれないと想定される) 場合、終了ステータス 1 のかわ
      りに 0 を返す。
bash の if は、 0 が成功で、非0 が失敗を示す(C言語と逆なので注意)。
Conditional Constructs (Bash Reference Manual)
The test-commands list is executed, and if its return status is zero, the consequent-commands list is executed.
なので、たとえばこのように書く。
if start-stop-daemon -S -o ナントカコマンド then echo 成功 else echo 失敗 fi
oknodo があると、すでにナントカコマンドが起動していても成功とみなす、という使い方となる。
--remove-pidfile
ubuntu 18 のマニュアルには --remove-pidfile があるんだが、
--remove-pidfile
      Used when stopping a program that does not remove its own pid file  (since  version
      1.17.19).   This option will make start-stop-daemon remove the file referenced with
      --pidfile after terminating the process.
ubuntu 14 には無い Ubuntu Manpage: start-stop-daemon - システムデーモンプログラムの起動、停止
[ツッコミを入れる]








