I am currently trying to set up a cronjob that will start a node.js server whenever that server is down.
For that purpose, I have written a simple script to test and start the node server.
#!/bin/bash ts=$(date +%T) if pgrep -f "node" then echo $ts": node running" else echo $ts": node not running" '/usr/bin/node' '/home/pi/project/serveronly/index.js' > '/home/pi/project/node.log' fi
The corresponding crontab is:
m h dom mon dow command * * * * * /home/pi/project/sanity_check.sh >> /home/pi/project/cron.log 2&>1
my logging shows the following: If I simply start the script it will start the server and log the node.js output properly.
For the script started by cron it looks this way:
If an instance of
node.js is currently running it will detect that and log accordingly.
If none is detected it will log into
cron.log properly, but it will log nothing into
node.log and it will not start a server.