Skip to content

Instantly share code, notes, and snippets.

@deepakmahakale
Created December 2, 2019 09:17
Show Gist options
  • Save deepakmahakale/b09dbadf805c00955646560d543879c7 to your computer and use it in GitHub Desktop.
Save deepakmahakale/b09dbadf805c00955646560d543879c7 to your computer and use it in GitHub Desktop.
A script to restart a node js app and serve over localtunnel (including crontab)
# m h dom mon dow command
* * * * * /home/deepak/workspace/status_check.sh >> /home/deepak/workspace/logs/status.log 2>&1
#!/bin/bash
echo "$(date) Killing the processes"
kill $(cat pids/run.pid)
kill $(cat pids/lt.pid)
sleep 3s
echo "$(date) Starting the app"
/usr/bin/node bot.js > stdout.txt 2> stderr.txt & echo $! > pids/run.pid
/usr/local/bin/lt --port 3000 --subdomain english-translated > lt_stdout.txt 2> lt_stderr.txt & echo $! > pids/lt.pid
#!/bin/bash
echo "$(date) Status check - english translated:"
if [[ $(ps aux | awk '/[b]in\/lt .*english-translated/ {print $2}') ]];
then
echo "$(date) Service is running"
else
echo "$(date) Service is stopped. Restarting"
cd ~/workspace/poc-translate-to-english && sh restart.sh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment