BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Shell script to restart server when it crashes


#1

Does anybody has a bash script or a solution for auto server start?
My server crashes sometimes those aren’t frequent crashes maybe like 2 crashes per month. But sometimes i am out of house and i have to restart it manually. I was thinking about making a bash script to check if it runs but i dont really know how to write it.


#2

I normally recommend utilities known as forever and forever-service.

Check out Any script I try running at startup does not work and the links in that post.


#3

You misunderstood me. I use forever for my scripts, but the blynk server itself which work on Java sometimes crashes. I dont think i can use forever to check if java process works.


#4

As per the GitHub for the forever-service (not forever) https://github.com/zapty/forever-service java programs can be run as a service. The example it gives on the front page for the repository is:

$ sudo forever-service install javaservice1 -s start.jar -f " -c 'java -Xms1024m -Xmx1024m -jar'"

#5

If already implemented a similar check with crontab, would you still recommend switching to forever-service?

I made a couple shell scripts and created cron schedules; one to download the latest server if it detects an update - runs it once everyday and another one to restart the server if not running (by checking ps) - runs it once every minute