Last active
August 29, 2015 14:05
-
-
Save nohtyp/1b2c674bd32c599b69db to your computer and use it in GitHub Desktop.
This gist starts/stops hubot on a Linux system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #https://gist.github.com/febuiles/1394520 | |
| # This assumes you have: | |
| # 1) A user called `hubot` in charge of the bot. | |
| # 2) A file called /home/hubot/.hubotrc that contains the Hubot credentials. | |
| # | |
| # To set the adapter either edit bin/hubot to specify what you want or append | |
| # `-- -a campfire` to the $DAEMON variable below. | |
| # | |
| ### BEGIN INIT INFO | |
| # Provides: hubot | |
| # Required-Start: $all | |
| # Required-Stop: $all | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: starts the hubot service | |
| # Description: starts the Hubot bot for the HipChat rooms | |
| ### END INIT INFO | |
| PATH=/home/hubot/myhubot/node_modules:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
| NAME="myhubot" | |
| HUBOT_HOME="/home/hubot/myhubot" | |
| LOGFILE="/var/log/hubot/hubot.log" | |
| PIDFILE="/var/run/hubot.pid" | |
| DAEMON='/usr/local/bin/npm_exec hubot -a hipchat -n myhubot' | |
| PID=`ps -ef |grep hubot |grep coffee|grep -v grep | grep -v bash |awk -F ' ' '{print $2}'` | |
| set -e | |
| case "$1" in | |
| start) | |
| if [ -z "$PID" ]; then | |
| echo -n "Starting $NAME: " | |
| cd $HUBOT_HOME | |
| . /home/hubot/myhubot/.hubotrc | |
| $DAEMON 1> $LOGFILE & 2>&1 | |
| echo "Starting" | |
| else | |
| echo "process $NAME currently start" | |
| fi | |
| ;; | |
| stop) | |
| echo "Stopping $NAME: " | |
| if [ -z "$PID" ]; then | |
| echo "No processes to kill" >> $LOGFILE | |
| exit 0 | |
| else | |
| echo "$PID" > $PIDFILE | |
| for i in $PID;do | |
| echo "Killing process $PID" >> $LOGFILE | |
| kill $i | |
| done | |
| fi | |
| ;; | |
| status) | |
| if [ -z "$PID" ]; then | |
| echo "No processes started" | |
| else | |
| echo "Process ID: $PID" | |
| fi | |
| ;; | |
| restart) | |
| echo "Restarting $NAME: " | |
| echo "$PID" > $PIDFILE | |
| for i in $PID;do | |
| echo "Killing process $PID" >> $LOGFILE | |
| kill $i | |
| done | |
| . /home/hubot/myhubot/.hubotrc | |
| cd $HUBOT_HOME | |
| $DAEMON 1> $LOGFILE & 2>&1 | |
| echo "Starting $NAME:" | |
| ;; | |
| *) | |
| N=/etc/init.d/$NAME | |
| echo "Usage: $N {start|stop}" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment