WEBrickでRedmineのテストをするときに使いたいデーモン起動・停止の超簡易スクリプト

コマンドを数珠つなぎした超簡易スクリプトです。コマンド名はお好きに。
ざっくりとテストはしました。

起動
[takeken@centos /home/takeken/redmine]$ service-redmine start
rails start [OK]

状態確認
[takeken@centos /home/takeken/redmine]$ service-redmine status
kidochu pid=7386

状態確認 停止中
[takeken@centos /home/takeken/redmine]$ service-redmine status
teishichu

起動 すでに起動済み
[takeken@centos /home/takeken/redmine]$ service-redmine start
rails start [NG] already started

停止
[takeken@centos /home/takeken/redmine]$ service-redmine stop
rails stop[OK]

停止 すでに停止済み というか動いてなかった時
[takeken@centos /home/takeken/redmine]$ service-redmine stop
rails stop[NG] teishichu

ソース。

[takeken@centos /home/takeken/redmine]$ cat /usr/local/bin/service-redmine
#!/bin/sh

COMMAND=$1
PID=`ps aux | grep "[r]ails server -d" | awk '{ print $2 }'`

case $COMMAND in
  "start" )
    if [ ! -s $PID ] ;then echo "rails start [NG] already started"
    else rails server -d > /dev/null
    echo "rails start [OK]"
    fi ;;
  "status" )
    if [ ! -s $PID ] ;then echo "kidochu pid=$PID"
    else echo "teishichu"
    fi ;;
  "stop" )
    if [ ! -s $PID ] ;then
      sudo kill "$PID"
      echo "rails stop[OK]"
    else echo "rails stop[NG] teishichu"
    fi ;;

esac

環境:

[takeken@centos /home/takeken/redmine]$ cat /etc/redhat-release
Scientific Linux release 6.6 (Carbon)
[takeken@centos /home/takeken/redmine]$ uname -ri
2.6.32-504.3.3.el6.x86_64 x86_64

CentOSと思っていたらSLだった!!
ヽ(#゚Д゚)ノ┌┛(ノ´Д`)ノ

 

Similar Posts:


Leave a Reply

Your email address will not be published. Required fields are marked *