I need to control (start\stop\restart) a perl daemon from a web application (php).
Daemon starts (and run) correctly when I use my init script (/etc/init.d/foodaemon start (works fine) ) from command line, but doesn’t works (daemon is down but pid file is created, as if the daemon died after its creation) when I try to launch from application.
In my /etc/sudoers, I added
apache ALL = NOPASSWD: /etc/init.d/foodaemon
In my php script,
$cmd = "/usr/bin/sudo /etc/init.d/foodaemon start";
exec($cmd,$out,$ret);
I have all permissions. The perl script is
#!/usr/bin/perl
use strict;
use warnings;
use Proc::Daemon;
Proc::Daemon::Init;
my $continue = 1;
$SIG{TERM} = sub { $continue = 0 };
close STDIN;
open STDERR,">>/tmp/mylog";
print "My pid: $$\n";
close STDOUT;
while ($continue) {
# ... what I need
}
SOLVED… There was an error in my init.d script, or rather
I did not have permission to do
so, I update as follow
and It works…Sorry…