Reputation: 99
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
}
Upvotes: 4
Views: 603
Reputation: 99
SOLVED... There was an error in my init.d script, or rather
case "$1" in
start)
if [ -z "$(pgrep $DAEMON)" ]
then
# DAEMON is not running
printf "%-50s" "Starting $NAME..."
cd $DAEMON_PATH
PID=`$DAEMON > /dev/null 2>&1 & echo $!`
#echo "Saving PID" $PID " to " $PIDFILE
if [ -z $PID ]; then
printf "%s\n" "Fail"
I did not have permission to do
cd $DAEMON_PATH
so, I update as follow
#cd $DAEMON_PATH
PID=`$DAEMON_PATH/$DAEMON > /dev/null 2>&1 & echo $!`
and It works...Sorry...
Upvotes: 1