Complete.Org: Mailing Lists: Archives: linux-help: April 2003:
[linux-help] Re: Keeping a process alive
Home

[linux-help] Re: Keeping a process alive

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: linux-help@xxxxxxxxx
Subject: [linux-help] Re: Keeping a process alive
From: flimzy@xxxxxxxxxx
Date: Mon, 28 Apr 2003 08:48:25 -0500 (CDT)
Reply-to: linux-help@xxxxxxxxx

Try a bash script something like this (this is entirely untested.. you'll
have to do your own debugging):
-- START --
#!/bin/bash
LOCK=/var/run/darkice

if -e ${LOCK}; then
  RUNNING=$(ps -a | grep $(cat ${LOCK}));
  if ( "${RUNNING}x" -ne "x"); then
# This means the process is already running
    exit;
  fi
# If the script gets this far, then the process has died
  rm ${LOCK};
fi

echo $<see note below> > ${LOCK}
<command to run darkice>
rm ${LOCK}
-- END --

$<see note below>:  I don't remember the variable name that returns the
PID.  You may need to look this up if you don't remember.

What the script does:
1) It checks for the existance of a lock file (/var/run/darkice, in this
case).
2) If the lock file exists, it checks the contents of the file (which
should be just a PID) against the list of running processes, to see if the
process is running.  NOTE: This should be clarified.  The current logic
may return false possitives.  For instance, if the lock file says "119"
and process "2119" is running, it will return a false possitive.
3) If the process is running, it exits immediately, without starting darkice.

4) If either the lock file doesn't exist, or the process it refers to is
not running, then it starts the process, creates the lock file, and waits
for the process to complete.  NOTE: For this to work, the command you use
to start darkice cannot fork to the background.
Just put this script in your crontab to run every 5 minutes or so
(whatever is reasonable).
I'm sure this script has bugs... but I'm sure you can figure them out :)

Good luck!

-- Jonathan


> Hello, all!
>
> Just for fun, I've set up my Linux RH 7.2 (I know... I should upgrade)
> box as a streaming audio encoder and server.  I'm encoding Butler
> County police scanner audio and streaming it to whoever is interested.
> I have a web page set up to provide access to the stream:
>
> http://users.sctelcom.net/~jdlucas/scanner/
>
> (it works most of the time, unless my ISP changes my IP on me, then I
> have to edit the web page...)
>
> Anyone is more than welcome to try it; Butler County isn't all that
> exciting, though.  I'm working on setting up a stereo stream; one
> channel Butler County, the other Sedgwick (I have a scanner that will
> monitor trunked systems.)
>
> I'm using "darkice" as the soundcard-to-mp3 stream encoder, and
> "icecast" as the server, both on the same machine, a PII 350MHz.
>
> The problem I'm having is that darkice is kind of unstable, meaning it
> may run anywhere from 30 minutes to 30 hours before crashing, but it
> will eventually crash.
>
> I currently have the darkice configuration set up so that it runs 5
> hours 59 minutes and 45 seconds before shutting down, and I have the
> crontab set up to restart the process every 6 hours.  At best, you get
> a 15 second gap in the audio every six hours; at worst, the server is
> dead for about 6 hours.
>
> I'm looking for something to stick in the crontab to check if the
> darkice process is running every 30 minutes or so, and, if it is, leave
> it alone, and if it has died, restart it.
>
> Perhaps crontab isn't the best answer?  I'm open to suggestions...
>
> By the way, the darkice encoder insists on running with superuser
> privileges... something about threading.
>
> Any help is appreciated!
>
> Thanks!
> --John
>
>
> -- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
> visit http://www.complete.org/cgi-bin/listargate-aclug.cgi



-- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]