Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found