Skip to content

Instantly share code, notes, and snippets.

@piatra
Created February 15, 2012 21:28
Show Gist options
  • Save piatra/1839107 to your computer and use it in GitHub Desktop.
Save piatra/1839107 to your computer and use it in GitHub Desktop.
Restart node server where changes are made to server file
#! /bin/bash
if [[ -f ./$1 ]]; then
while true; do
time=$(stat -c %Y server.js | cut -d ' ' -f1);
oldtime=$(cat log);
if [[ "$oldtime" -lt "$time" ]]
then
if [[ $pid -gt 0 ]]; then
node server &
else
echo "kill former node instance"
kill -9 $pid
node $1 &
echo "restarted"
fi
fi
echo $time > log;
pid=$(ps | grep node | cut -d ' ' -f1)
sleep 2;
done
else
echo "Usage: ./server.sh [server_file.js]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment