Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

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

Hi,

I have written a daemon with the help of this post Re: Writing a Perl Daemon. The daemon more or less follows the structure shown there. The daemon is installed in CentOS 7 within systemd environment. It is declared there as forking type of daemon with a PID file and everything that goes with it.

Now I have a problem with it. The daemon sends data to two servers (for redundancy purposes) every two seconds. When both remote servers are up, everything is fine. However, when one of the servers is down, there are problems. The procedure waits for disconnected server to respond and at that time the data are not sent to the connected server too.

I need the daemon to have two child processes. Each one would send the data to one of the servers. In that case difficulties with one server would not cause problems with another one. I am not sure if Proc::Daemon and Proc::PID::File support more than one child process.

I tried something like this:

foreach my $server (@servers) { $i++; # # fork and background process # our $ME = $0; $ME =~ s|.*/||; our $PIDFILE = $PIDDIR . "/$ME.pid" . $i; my $pid = 0; $daemon{$server} = Proc::Daemon->new ( pid_file => $PIDFILE, work_dir => cwd () ); $pid = $daemon{$server}->Init (); if ($pid == 0) { # do the child stuff } }

When I run this daemon it creates children processes and more PID files. However, when I try to kill them, it is not so straightforward, because some a new child appears and I have to kill it too. I think I could resolve this issue, but there are more.

Since I use systemd where I have to specify PIDFile, I am also not sure if it is supported to have more PID files. I guess the right way would be to put all children PIDs into one PID file. Until now I was only testing this multiple children version with running the daemon manually. The strange behaviour with popping up children after killing the original ones stopped me from going further. I did not try to do it with systemd yet.

Where can I find some examples how to make a PERL daemon with more child processes? Since I use Proc::Daemon, Proc::PID::File, I would prefer to make it work with these libraries. I hope it can be done with them. Otherwise, I have to change quite a lot.


In reply to Multiple forks with Proc::Daemon by markoh

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 rifling through the Monastery: (3)
As of 2024-04-20 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found