I have a ubuntu server where I put my application core. It's a jar that needs to be always listening for requests. I made a script to run it with the correct parameters.
The scenario is similar to this: script location: /home/andrea/core/script.sh
script.sh takes a parameter, "start" or "stop" depending what I need to do.
Since I need it to be alive I created a cron job that checks if it's alive and if not it starts it again with the following commands:
crontab -e */5 * * * * /home/andrea/core/testscriptalive.sh
where testscriptalive.sh is: #!/bin/bash
# Check if core is running if [ ! -f /tmp/core.pid ]; then cd /home/andrea/core/ ./script.sh start ./email.sh fi
So, every 5 minutes cron runs the script "testscriptalive.sh", which basically checks if there's the correct PID and if not it starts again the core and it sends me an email. So far so well. What I need to do is: if I want to stop the core for X reasons how can I stop cron job from executing without editing it manually? For example if in the console I enter "./script stop" after 5 minutes the cron job automatically restarts it even if I don't want to. I need two sh scripts to couple to my "start" and "stop" parameters that:
checks if the job is correctly stored in cron, if not adds it
removes the job from cron
How can I achieve this?