Created
February 15, 2012 21:28
-
-
Save piatra/1839107 to your computer and use it in GitHub Desktop.
Restart node server where changes are made to server file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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