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/crappyserver.pid` ;; 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...?

Argh!

Any help is greatly appriciated!

--Pileofrogs


In reply to Launching a launcher? by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.