Skip to content

Instantly share code, notes, and snippets.

@ideaoforder
Created August 21, 2009 17:40
Show Gist options
  • Select an option

  • Save ideaoforder/172228 to your computer and use it in GitHub Desktop.

Select an option

Save ideaoforder/172228 to your computer and use it in GitHub Desktop.
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: starling
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop starling server
### END INIT INFO
#
# starling This init.d script is used to start starling.
# It basically just calls starling.
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
set -e
if [ -x /usr/bin/starling ] ; then
HAVE_STARLING=1
else
echo "No starling gem installed. Please run 'gem install starling'."
exit 0
fi
. /lib/lsb/init-functions
PID="YOUR_WEB_APP/tmp/pids/"
QPATH="log/"
PORTS="22122" # comma separated, no spaces!
STARLING="$ENV /usr/bin/starling -d"
test -f /etc/default/rcS && . /etc/default/rcS
PIDS=$(echo $PORTS | awk '{split($1, array, ","); for(e in array) {print array[e]}}')
starling_stop() {
for PORT in $PIDS; do
THISPID=$PID"starling_"$PORT".pid"
if [ -e $THISPID ]; then
if kill `cat $THISPID`; then
success=0
else
success=1
fi
#else
# log_failure_msg "Unable to find starling's PID. Please make sure that starling is running, and pid file is in /var/run/starling.pid"
# return 1
fi
done
return $success
}
starling_start() {
for PORT in $PIDS; do
THISPID=$PID"starling_"$PORT".pid"
START_COMMAND="$STARLING -P $THISPID -q $QPATH -p $PORT"
$START_COMMAND
done
}
# Stupid hack to keep lintian happy. (Warrk! Stupidhack!).
case $1 in
start)
log_daemon_msg "Starting message server" "starling"
if starling_start; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
log_daemon_msg "Stopping message server" "starling"
if starling_stop; then
log_end_msg 0
else
log_end_msg 1
fi
;;
restart)
log_daemon_msg "Restarting message server" "starling"
if ! starling_stop; then
log_end_msg 1 || true
fi
sleep 2
if starling_start; then
log_end_msg 0
else
log_end_msg 1
fi
;;
*)
log_success_msg "Usage: /etc/init.d/starling {start|stop|restart}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment