3 ms·
Are you using a Node.JS backend? This is a little script that I set up with cron on a second instance, which logs in and restarts the Node server if it's down.
by peterburkimsher 7y ago
Are you using a Node.JS backend? This is a little script that I set up with cron on a second instance, which logs in and restarts the Node server if it's down. • replaces * because it's used for italics on Hacker News comments.
#!/bin/bash
thisHtml=`curl -s "[your site's web address]"`
if [[ $thisHtml != •"<title>[your site's title]</title>"• ]]; then
#echo "Server is down"
ssh -i "[your pem file]" -t ec2-user@[ip address] 'sudo /bin/bash -c "killall -9 node"'
ssh -i "[your pem file]" -t ec2-user@[ip address] 'sudo /bin/bash -c "export PATH="/root/.nvm/versions/node/v8.11.2/bin:/usr/lib/node:/usr/local/bin/node:/usr/bin/node:$PATH" && forever start /var/www/html/[...]/index.js"'
rebootDate=`TZ=":[your time zone]" date '+%Y-%m-%d %H:%M:%S'`
echo "$rebootDate" >> "/home/ec2-user/serverMonitoring/devRestarts.txt"
fi