LoginSignup
3
3

More than 5 years have passed since last update.

ディレクトリ/ファイルを監視してsupervisorで再起動(自動化

Last updated at Posted at 2015-05-17

コードを修正して再起動ってよくあるじゃないですか。
開発時だと尚更多いのでsh書いた。

auto_restart.sh
#!/bin/sh
if [[ $# -ne 3 ]] ; then
    echo argument is invalid.
    exit
fi

while :
do
    after=`ls -l $1`
    if [[ $after != $before && $before != "" ]] ; then
        supervisorctl restart $2 > /dev/null
    fi
    before=$after
    sleep $3
done

使うときは
$ sh auto_restart.sh target app_name 10 &
とか。
第1引数が監視対象パス、第2引数が再起動するアプリ名、第3引数が監視間隔。
あとは最後に&つけてバックグラウンドにして使ってます。

監視対象はディレクトリでもファイルでも行けるので、プロジェクト全体のディレクトリを指定するのが良いかも。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3