Created
November 14, 2013 01:10
-
-
Save brianredbeard/7459507 to your computer and use it in GitHub Desktop.
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).
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 | |
| # 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='[email protected]' | |
| # 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