Skip to content

Instantly share code, notes, and snippets.

@zxaos
Created October 2, 2012 20:45
Show Gist options
  • Save zxaos/3823190 to your computer and use it in GitHub Desktop.
Save zxaos/3823190 to your computer and use it in GitHub Desktop.
Compass Watcher
#! /bin/sh -e
### BEGIN INIT INFO
# Provides: compasswatcher
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the compass watch process for each directory
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
RUBY="/usr/bin/ruby1.8"
COMPASS="/usr/local/bin/compass"
COMPASSUSER="www-data"
PIDDIR="/var/run/compasswatcher/"
CONFIGFILE="/etc/compasswatcher"
start(){
I=0
for DIR in $(cat ${CONFIGFILE}); do
echo "Starting Compass on ${DIR}"
start-stop-daemon --start --background --make-pidfile --pidfile "${PIDDIR}compasswatcher${I}.pid" --chuid ${COMPASSUSER} --exec ${RUBY} -- ${COMPASS} watch "${DIR}"
I=$((I+1))
done
}
stop(){
for PIDFILE in ${PIDDIR}*.pid; do
kill $(cat "${PIDFILE}") || true
rm "${PIDFILE}"
done
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload|force-reload|restart)
stop
start
;;
*)
N=/etc/init.d/compasswatcher
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment