Skip to content

Instantly share code, notes, and snippets.

@piccaso
Forked from zxaos/compasswatcher.sh
Last active January 3, 2016 15:39
Show Gist options
  • Save piccaso/8484638 to your computer and use it in GitHub Desktop.
Save piccaso/8484638 to your computer and use it in GitHub Desktop.
#! /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
### setup:
### wget -O /etc/init.d/compasswatcher https://gist.github.com/piccaso/8484638/raw/compasswatcher.sh
### chmod +x /etc/init.d/compasswatcher
### update-rc.d compasswatcher defaults
### create /etc/compasswatcher - one compass dir per line
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
RUBY="/usr/bin/ruby1.9.1"
COMPASS="/usr/local/bin/compass"
PIDDIR="/var/run/compasswatcher/"
CONFIGFILE="/etc/compasswatcher"
start(){
mkdir -p $PIDDIR
I=0
for DIR in $(cat ${CONFIGFILE}); do
COMPASSUSER=`stat -c "%U" ${DIR}`
#echo "Starting Compass for $COMPASSUSER on ${DIR}"
start-stop-daemon \
--nicelevel 15 \
--start --background --make-pidfile --pidfile "${PIDDIR}compasswatcher${I}.pid" \
--chuid ${COMPASSUSER} --exec ${RUBY} -- ${COMPASS} watch "${DIR}" --poll \
I=$((I+1))
echo sudo -u $COMPASSUSER $COMPASS compile $DIR --trace
done
}
stop(){
for PIDFILE in ${PIDDIR}*.pid; do
kill $(cat "${PIDFILE}") || true
rm "${PIDFILE}"
done
}
status () {
cat ${PIDDIR}*.pid | xargs ps --pid
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
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|status}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment