Check if process is running, if not, execute another script
Hello!
I have a game server running using java, and it tends to crash sometimes, and only way to start it now is manually, so i thought i could create a script to check periodically if java is running, and if it isn't, run my startup script for the game server also, if it's possible it should log when it actually started the server startup script into a text file or something, so i can check why it crashed Thank you in advance! |
Don't think it will be difficult .. you can use the ps command in your script to check the process and restart if the process is not running .. Perhaps set it up using cron. loging should not be a problem as well...
|
Quote:
Code:
while ! <insert your command here>; do sleep 2; done
This might or might not work depending on how the program crashes (plus java tends to act its way, instead of just doing things the right and standard way). A more complete schema to do this would be something like: Code:
#!/bin/bash |
Hey, thanks for the reply, but i tried a different approach, which didn't quite work
I made a script: Code:
#!/bin/sh but when i run it manually, it runs just fine */3 * * * * /root/check_running.sh |
Try changing it to look like below, or whatever shell your script is in.
Quote:
|
Have you looked at putting this in the inittab with the respawn action?
Code:
Valid actions for the action field are: |
All times are GMT -5. The time now is 01:37 AM. |