|We don't bite newbies here... much|
Multiple forks with Proc::Daemonby markoh (Novice)
|on Aug 07, 2017 at 07:19 UTC||Need Help??|
markoh has asked for the
wisdom of the Perl Monks concerning the following question:
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:
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.