Skip to content

Instantly share code, notes, and snippets.

@kalendae
Created May 14, 2013 19:38
Show Gist options
  • Save kalendae/5578830 to your computer and use it in GitHub Desktop.
Save kalendae/5578830 to your computer and use it in GitHub Desktop.
startup script for running slanger as daemon
#!/bin/bash
# slanger daemon
# chkconfig: 345 20 80
# description: slanger daemon
# processname: slanger
. /etc/rc.d/init.d/functions
# Location of a non-daemon application to be daemonized
BIN="/home/xxx/.rvm/gems/ruby-1.9.2-p290/bin/slanger --app_key XXXX --secret YYYY --api_host 0.0.0.0:4568 --websocket_host 0.0.0.0:8081"
# The username to run the process with
RELUSER="xxx"
# Our PID file
PIDFILE="/var/run/slanger.pid"
# Log file location
LOGFILE="/var/log/slanger.log"
start()
{
rm -f $LOGFILE
# Execute ourself in a background mode
su -l $RELUSER -p -c "${0} start_internal &"
echo -n "Starting Application: "
success "Starting Application: "
echo
}
start_internal()
{
# Remember PID
echo "$$" > $PIDFILE
# setup env
source /home/xxx/.rvm/environments/ruby-1.9.2-p290
# Exec the non-daemon application
exec $BIN > $LOGFILE
}
stop()
{
if [ -f ${PIDFILE} ]; then
kill `cat $PIDFILE`
rm -f $PIDFILE
echo -n "Stopping Application: "
success "Stopping Application: "
echo
fi
}
case "$1" in
start)
start
;;
start_internal)
start_internal
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage $0 {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment