Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Launching a launcher?

by pileofrogs (Priest)
on Aug 27, 2010 at 23:09 UTC ( #857785=perlquestion: print w/replies, xml ) Need Help??
pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks!

I'm on CentOS linux and I'm writing a script to start important services if they get turned off for some reason. The services in question are all launched by bash scripts on system start, so I'm going to call those same scripts to start dead services.

My problem is, one of those scripts starts its process and puts it in the background by running a foreground process with a '&' at the end. This seems to be keeping the filehandles open and perl doesn't recognise that the launcher (not the service) has ended. Obviously, I should fix that launcher to be better behaved, but I want my perl script to be able to handle badly written launchers.

I'll try and show an example in case that didn't make sense... I'm starting an imaginary server called "crappyserver".

Here's an example launcher /etc/rc.d/init.d/crappyserver

#! /bin/bash case "$1" in start) /usr/sbin/crappyserver & ;; stop) kill `cat /var/run/` ;; esac

And here's my launcher launcher

#! /usr/bin/perl -w use Imagniary::Module; if ( !Imaginary::Module::crappyserver_is_running() ) { open(my $handle, '-|', '/etc/rc.d/init.d/crappyserver start') || die "failure!"; while( my $line = <$handle> ) { print $line; } close($handle); print "Done!\n"; }

My launcher-launcher hangs at the open() call. It does launch crappyserver, but it never prints "Done!"

This has something to do with buffering doesn't it...?


Any help is greatly appriciated!


Replies are listed 'Best First'.
Re: Launching a launcher?
by TGI (Parson) on Aug 28, 2010 at 06:33 UTC

    I worked on a similar project for a while, but I found monit and scrapped my code. monit is pretty easy to set up, can do all sorts of smart things like restart a process up to n times, and then call for help. You can set up arbitrary tests for to verify process responses. It does alerts as well as process monitoring and management.

    By selecting the appropriate compilation options, you can even keep monit very lean. For example, I was able to use it on a project targeted for ARM based system with 64 MB RAM and still have plenty of room for a couple of Perl daemon processes.

    In short, monit >= sliced bread.

    TGI says moo

Re: Launching a launcher?
by ikegami (Pope) on Aug 28, 2010 at 04:06 UTC

    This has something to do with buffering doesn't it...?

    You read from the pipe until it is closed, which could very well be when the server exits. No, buffering is not an issue.

Re: Launching a launcher?
by JavaFan (Canon) on Aug 28, 2010 at 11:09 UTC
    I'm on CentOS linux and I'm writing a script to start important services if they get turned off for some reason.

    This is a solved problem. Just put the appropriate entry in /etc/inittab. It's designed to do this stuff.

Re: Launching a launcher?
by afoken (Abbot) on Aug 28, 2010 at 12:54 UTC

    Once again, daemontools could help. See also the djb way.


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://857785]
Approved by muba
Front-paged by ww
[karlgoethebier]: shmem: Ja ischweis
[karlgoethebier]: shmem: Vielleicht hat er in den Bollerwagen gebrochen?
[karlgoethebier]: shmem:Ach so. Bollerwagen ist eigentlich was für Kinder. Bei uns fahren sie mit Traktoren und Feuerwehrwagen rum...
[shmem]: karlgoethebier: here abouts people are sitting in big tents, gulp beer and ingest badly scorched chicken and sausages while (not) listening to afwul musik
[shmem]: *awful

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2017-05-25 12:39 GMT
Find Nodes?
    Voting Booth?