Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to run shoutcast on my shared hosting server (it runs Debian). Every once and a while the shoutcast server dies. I am not always there to turn it back on. Is there a way to create a script that if dies will start back up?
The outline for the script is:
shoutcast server
sleep 5
DSP Plugin
If this script dies how can I set it up so it restarts again in 30 seconds?
I would do an infinite while loop in a bash script that does a grep on ps -A and if the the main process name disappears (I am assuming it does when it dies), it restarts it again asynchronously (with an appended &). After this check it sleeps for 5 to 30 seconds. You could run the server from this script initially.
If this script dies how can I set it up so it restarts again in 30 seconds?
You can use a respawn event in /etc/inittab, but that won't wait for 30 seconds. When the script dies, it would be restarted immediately.
As an example, here is how I keep the program "mythbackend" always running as userid "mythtv" when I'm at runlevel 2, 3, 4, or 5. If it ever dies (which it never does), then it would be restarted ("respawned") immediately. Here's the line I manually added to /etc/inittab:
I am on shared hosting. I doubt that I have access to the main inittab. Is their a way to do it and confine it to one bash script?
Denes described how to do that in his/her post above. You could also use a cron job to check-and-restart, but you probably don't have access to cron on a shared host either. There's no such thing as a "personal inittab", so the inittab route would be out for you if you don't have priviledged access to the system. If you want to get fancy you could have a parent fork and exec a child (which is the actual server). The parent loops and waits on the child, and when the child terminates, a new one is forked. The high-level functional equivalent of a looping bash script as Denes described, but implemented differently.
Bash is easier then dealing with fork and exec and a c compiler for this type of application. Assuming your process name is Test located in the directory this script was run from, the code below will do it. You may want to echo date when it restarts just so you know when it happens.
#!/bin/sh
while true;
do
PROCESS=`ps -A | grep Test`
if [ "$PROCESS" = "" ]
then
# Not found - start process
./Test &
else
# Found it - don't do anything
fi
sleep 30
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.