Skip to content

Instantly share code, notes, and snippets.

@stengland
Last active February 29, 2016 12:31
Show Gist options
  • Save stengland/76826150c116cf69f5ed to your computer and use it in GitHub Desktop.
Save stengland/76826150c116cf69f5ed to your computer and use it in GitHub Desktop.
Simple wrapper around rackup that restarts Rack when files change (uses inotify-tools' inotifywait)
#!/bin/sh
trap Terminate SIGINT SIGTERM SIGQUIT SIGKILL
Start () {
echo "Starting rack..."
rackup $@ &
echo $! > /tmp/rerackup.pid
}
Stop () {
echo "Stopping rack..."
kill `cat /tmp/rerackup.pid`
rm /tmp/rerackup.pid
}
Terminate () {
Stop
echo "Terminating rerackup..."
exit 0
}
Restart () {
Stop
Start $@
WatchForChanges $@
}
WatchForChanges () {
echo "Watching for changes"
inotifywait -r -q -e modify .
Restart $@
}
WatchForChanges $@ & Start $@
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment