droneの起動スクリプト

amazon linux用のdrone起動スクリプトです。
インストール・初期設定については下の記事を参照してください。
https://hacknote.jp/archives/6836/

#! /bin/sh
#chkconfig:   2345 99 99

DAEMON_OPTS="--config=/etc/drone/drone.toml" 

pid() {
  if [ -f /usr/local/bin/droned ]; then
    pidof /usr/local/bin/droned
  fi
}

stop() {
  if pidof /usr/local/bin/droned >/dev/null; then
    kill -9 "$(pid)" 
  else
    echo "Drone not runned" 
    exit 1
  fi
}

start() {
  if pidof /usr/local/bin/droned >/dev/null; then
    echo "Drone already runned" 
    exit 1
  else
    nohup /usr/local/bin/droned $DAEMON_OPTS > /var/log/drone.log  2>&1 &
  fi
}

restart() {
  if pidof /usr/local/bin/droned >/dev/null; then
    kill -9 "$(pid)" 
    nohup /usr/local/bin/droned $DAEMON_OPTS > /var/log/drone.log  2>&1 &
    exit 0
  else
    nohup /usr/local/bin/droned $DAEMON_OPTS > /var/log/drone.log  2>&1 &
    exit 0
  fi
}

status() {
  if pidof /usr/local/bin/droned >/dev/null; then
    echo "Drone with pid $(pid) is running" 
  else
    echo "Drone is not running" 
  fi
  exit 0
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  status)
        status
        ;;
  *)
        echo "Usage: service drone {start|stop|restart|status}" 
        exit 1
        ;;
esac