Skip to content

Instantly share code, notes, and snippets.

@soplakanets
Created April 15, 2011 07:54
Show Gist options
  • Save soplakanets/921336 to your computer and use it in GitHub Desktop.
Save soplakanets/921336 to your computer and use it in GitHub Desktop.
Sample script to restart node.js server when current directory is modified(recursively).
#!/usr/bin/env bash
PID=0
APP_FILE="./app.js"
function start_server {
node $APP_FILE &
PID=$!
}
function stop_server {
kill -TERM $PID
}
function restart_server {
stop_server && start_server
}
start_server
ls -laR . > /tmp/testdirb.$$
while true; do
ls -laR . > /tmp/testdira.$$
diff /tmp/testdira.$$ /tmp/testdirb.$$ || (echo "Restarting..." && restart_server)
cp /tmp/testdira.$$ /tmp/testdirb.$$
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment