I'm trying to write an auto start script that starts on boot and restarts if it crashes. The start on boot is doable by simply adding the script to the
/etc/rc.local
File, however my problem is the auto restart. I thought about exporting the $$ Variable into an external text file before starting the actual script, and using this with another script to check whether that pid still is running or not. My question is now how to check if a specific PID is still running and also if there is a more reliable way to do this.
Best Answer
What your script needs to perform in such a manner is
systemd
sevice.An example would be the one below:
This can be done in several ways:
Place your script in another location and access it from your
systemd
service files.Place the code directly in the
systemd
service file.I believe the first option is ideal in your situation. Now once done enable at boot with the normal
systemctl
commands, such as:Sources:
https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files
https://www.freedesktop.org/software/systemd/man/systemd.unit.html