On Mon, Feb 04, 2013 at 01:07:55PM +0000, Albretch Mueller 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) > ~ > 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 based on 1) and the id of the running > process > 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)
A 'crontab' example, controlling the online time of my modem (my providers switch cheap and very expansive fees at certain hours) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SHELL=/bin/bash PATH=/usr/lsh:/usr/lbin:/usr/bin:/bin:/sbin # m h dom mon dow command # ----------------------------- # IF online through script 'ip-Tele2', then shutdown modem every 2 hours # (at minute 57, run script 'ring-bell'; at minute 59, run 'poff') (weekdays) 57 0-22/2 * * 1-5 pidof pppd && ps -o command -C ip-Tele2 && ring-bell 3 59 0-22/2 * * 1-5 pidof pppd && ps -o command -C ip-Tele2 && poff &> /dev/null # IF stub file: 'ip-stop' exists, then shutdown modem ('poff') (daily, every hour) # (at minute 57, run script 'ring-bell'; at minute 59, run 'poff') (7 days) 57 0-23 * * 0-6 [ -f /tmpp/stub/crontab/ip-stop ] && pidof pppd && ring-bell 3 59 0-23 * * 0-6 [ -f /tmpp/stub/crontab/ip-stop ] && pidof pppd && poff && rm /tmpp/stub/crontab/ip-stop - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Hope this gives some helpful clue. Moin W.F. -- -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20130204191906.ga4...@fok01.laje.edewe.de