Skip to content

Instantly share code, notes, and snippets.

@brianredbeard
Created Nov 14, 2013
Embed
What would you like to do?
Startup script for a Red Hat SCL based node.js application which should run on startup - Hubot. http://github.com/github/hubot (Note, this isn't a _good_ example, simply _an_ example).
#!/bin/bash
# hubot
# chkconfig: 345 20 80
# description: hubot
# processname: hubot
# This script assumes you have a user called "hubot" on your system and that hubot is installed in /opt/hubot
#
# Fore more info on this craziness -
# http://thejacklawson.com/how-to-hubot/
#
# Save Environement Variables in /opt/hubot/hubot/bin/hubot.env
# e.g
# export HUBOT_GTALK_USERNAME='hubot@example.com'
# export HUBOT_GTALK_PASSWORD='abc123''
# export HUBOT_GTALK_WHITELIST_DOMAINS='example.com'
NAME="hubot"
USER="hubot"
DESC="hubot"
PIDFILE=/var/run/$NAME/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
DAEMON="scl enable nodejs010 "
DAEMONOPTS="/opt/hubot/hubot/bin/hubot --name ${NAME} --adapter xmpp"
MANPATH=/opt/rh/nodejs010/root/usr/share/man
X_SCLS=nodejs010
LD_LIBRARY_PATH=/opt/rh/nodejs010/root/usr/lib64
PATH=/opt/rh/nodejs010/root/usr/bin:/opt/rh/mariadb55/root/usr/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/rh/mariadb55/root/usr/sbin:$PATH
PYTHONPATH=/opt/rh/nodejs010/root/usr/lib/python2.6/site-packages
export MANPATH PATH PYTHONPATH LD_LIBRARY_PATH
source /opt/hubot/hubot/bin/hubot.env
case "$1" in
start)
printf "%-50s" "Starting $DESC..."
PID=`runuser -m -c "${DAEMON} '${DAEMONOPTS}'" - $USER >> /var/log/hubot/hubot 2>&1 & echo $!`
#echo "Saving PID" $PID " to " $PIDFILE
if [ -z $PID ]; then
printf "%s\n" "Fail"
else
echo $PID > $PIDFILE
chown $USER $PIDFILE
chown $USER /var/log/hubot/hubot
printf "%s\n" "Ok"
fi
;;
status)
printf "%-50s" "Checking $DESC..."
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" "Service not running"
fi
;;
stop)
printf "%-50s" "Stopping $DESC"
PID=`pgrep hubot`
if [ "${PID}x" != "x" ]; then
pkill -u $USER
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment