Linux-Noob Forums
Respawning Processes - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html)
+--- Forum: Tips and Tricks (https://www.linux-noob.com/forums/forum-59.html)
+--- Thread: Respawning Processes (/thread-2478.html)



Respawning Processes - znx - 2005-08-20


He's a quick tip to force a process to always keep respawning. Basically if the process dies, another will start in its place.

 

Save this as, respawn.sh:



Code:
#!/bin/sh
while [ 1 ]; do
   /bin/ls -l /home/znx
done




 

Now execute it like this:



Code:
$ ./respawn.sh




 

Now the screen will fill with lots and lots of ls information. Ctrl+C will kill it for you. This is an example of a neverending loop. Now where would you want this? Well the reason that I'm writing this is that I recently helped Blue|Moon setup this to ensure that a Counter Strike Source server would keep running:



Code:
#!/bin/sh
while [ 1 ]; do
   cd /path/to/install
   ./srcds_run -game cstrike ..... the rest of your options ......
done




 

Started with:



Code:
$ cd /path/to/install
$ screen -m -d -S sourceserver ./respawn.sh




 

Now when the server quits or is killed, another takes its place, saving you the user from having to login remotely and start it all the time :)




Respawning Processes - bluemoon - 2005-08-20


This script works a treat, theres nothing like this available. znx has spent hours with me tonight creating this and sorting out my system. Great guy, if everyone followed his views in the world :)It would be a hell of a better place

 

Thanks again




Respawning Processes - xDamox - 2006-05-15


Quote:This script works a treat, theres nothing like this available. znx has spent hours with me tonight creating this and sorting out my system. Great guy, if everyone followed his views in the world :)It would be a hell of a better place 

Thanks again
 

hehe yea znx is a cool person always willing to help out :)he knows his stuff too.