#!/bin/bash # hubot # chkconfig: 345 20 80 # description: hubot # processname: hubot DAEMON="bin/hubot" ROOT_DIR="/opt/hubot" DAEMON_ADAPTER="irc" LOG_FILE="/var/log/hubot.log" USER=hubot NAME=hubot PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME case "$1" in start) echo -n $"Starting $NAME: " runuser -l $USER -c "source $ROOT_DIR/hubot.env && source $ROOT_DIR/plugins.env && cd $ROOT_DIR; $DAEMON -a $DAEMON_ADAPTER" >> $LOG_FILE 2>&1 & sleep 3 PID=$(ps aux | grep node | head -1 | awk '{print $2}') if [ -z $PID ]; then printf "%s\n" "[ NOT OK]" else echo $PID > $PIDFILE printf "%s\n" "[ OK ]" fi ;; status) echo -n $"Status $NAME: " if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then printf "%s\n" "[ process dead but pidfile exists ]" else echo "[ running ]" fi else printf "%s\n" "[ not running ]" fi ;; stop) echo -n $"Stopping $NAME: " PID=`cat $PIDFILE` if [ -f $PIDFILE ]; then kill $PID printf "%s\n" "[ OK ]" rm -f $PIDFILE else printf "%s\n" "[ pidfile not found ]" fi ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {status|start|stop|restart}" exit 1 esac