トップ «前の日記(2019-12-26) 最新 次の日記(2019-12-28)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

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 - システムデーモンプログラムの起動、停止