Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cron jobs to restart a shell process ...

16 views
Skip to first unread message

qwert...@syberianoutpost.ru

unread,
Feb 4, 2013, 7:59:57 AM2/4/13
to
~
Sometimes I need to start a long running process which for various reasons may
be stopped (server drops connection, OS kills it, ...) and I would like to have
a somewhat automatic mechanism to check if it was stopped and, in that case,
restart it (of course, with a new process id)
~
This is what I have in mind:
~
1) run an initial script to set up the context of the long running process,
which, of course, will be specific, but the communication between 1) and 2) is
just trough a regular protocolled file (I try to make my code as compatible as
possible and pipes and other forms of interprocess comm tend to be very OS
specific).
~
2) a second general script which just checks if process is running and restarts
it in the case it isn't, based on:
~
2.1) a lock file named after some identifying metadata regarding 1), and
~
2.2) containing the current/last process id.
~
3) insert a line in your crontab file, to run 2)
~
You can check if a process is running by pars-, greping ps aux's output and
simply go monkey to finish some working script, but I am sure those needs aren't
just mine and there should be either a flag for cron jobs, a utility, or some
best practices out there I don't know of. In fact, do you know of best practices
for max data processing (I am talking here about jobs that may take days)
~
Is there such a thing?
~
Any suggestions?
~
lbrtchx
comp.unix.shell:cron jobs to restart a shell process ...

Icarus Sparry

unread,
Feb 4, 2013, 11:49:59 AM2/4/13
to
There are lots of things like that.

The whole "init" setup is designed to keep programs like "getty" running
on serial lines, so a simple approach is to add a line to /etc/inittab if
your system uses that. These days there are a lot of alternatives, of
which systemd seems to be gaining the most attention. (This assumes you
are the administrator of the machine).

I happen to like Dan Bernsteins tools, http://cr.yp.to/daemontools.html
which is suitable even if you are not the administrator. You might see if
your cron supports a "@reboot" specification, which can make it easy to
start svscan or another monitoring program if you are not the
administrator.

Jon LaBadie

unread,
Feb 4, 2013, 1:22:02 PM2/4/13
to
On 02/04/2013 07:59 AM, qwert...@syberianoutpost.ru wrote:
> ~
> Sometimes I need to start a long running process which for various reasons may
> be stopped (server drops connection, OS kills it, ...) and I would like to have
> a somewhat automatic mechanism to check if it was stopped and, in that case,
> restart it (of course, with a new process id)
> ~

Define "stopped". Do you really mean exited/terminated?
Or could your definition include hung processes?

I ask as looking at the process list would not differentiate
a hung process from a normally running process.
0 new messages