I have Raspbian Jessie 8 running in a Raspberry Pi 3. There are 3 JavaScript services that are automatically started by PM2.
However, if the Raspberry is shutdown incorrectly, e.g., if the energy cable is removed, the services don't start.
They only start automatically if the Raspberry is shutdown properly, e.g., using sudo reboot
.
I need a shell script that checks if the Raspberry was incorrectly shutdown and, if it was, to be rebooted using sudo reboot
.
I saw here and here how to create a simple reboot script and here how to check if a service is running, but found nothing on how to check for an improper shutdown. Can anyone tell me how?