How to start perl daemon from php

I need to control the (start \ stop \ restart) perl daemon from a web application (php). Daemon starts (and starts) correctly when I use my init script (/etc/init.d/foodaemon start (works fine)) but it doesn’t work (the daemon is unmounted, but the pid file is created, because if the daemon died after creating it) when I try to run the 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 the permissions. 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 } 
+4
source share
1 answer

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 am updating following

  #cd $DAEMON_PATH PID=`$DAEMON_PATH/$DAEMON > /dev/null 2>&1 & echo $!` 

And it works ... Sorry ...

+1
source

All Articles