Skip to content

Instantly share code, notes, and snippets.

@jacks205
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacks205/7fcb989e57859fa8f025 to your computer and use it in GitHub Desktop.
Save jacks205/7fcb989e57859fa8f025 to your computer and use it in GitHub Desktop.
Schedules server restart script
#!/bin/bash
#NOTE: USE `bash launch` not `sh launch`
timestamp(){
(date)
}
server_name="schedules-backend"
log_file="crash_log.txt"
server_log="server_log.txt"
time=$(timestamp)
crash_message="Restarting server. Logging scripted restart. (Add successful restart log);\n"
log_message="$time: $crash_message"
if lsof -i:1337 > /dev/null && [ "$1" != "-r" ]
then
echo "$time: Server is OK"
if [ "$1" == "-k" ]
then
kill `lsof -t -i:1337`
echo "$time: Killing server" >> ~/$server_log
echo "$time: Killing server"
fi
else
if [ "$1" == "-r" ]
then
kill `lsof -t -i:1337`
fi
echo "$time: Restarting server on 1337, logging restart to $log_file"
echo $log_message >> $log_file && echo $log_message >> ~/$server_log
cd ~/$server_name
sails lift >> ~/$server_log &
fi
@jacks205
Copy link
Author

NOTE: USE bash launch not sh launch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment