PHP daemon killed mysteriously
I have a php script, which runs as daemon and only writes current time to log file. This scripts is killed misteriously after 10-15 mins with no message to any log file. OS: Centos 6.9 + Cloudlinux + CageFS + cPanel. If I run the same daemon on Centos 6.9 only it doesn't stop. Is there something related to Cloudlinux which can kill the background process?
[SPOILER="Daemon script">
[SPOILER="PHP script">
#!/bin/bash
. /etc/rc.d/init.d/functions
PROGRAM="example"
NAME="Example Listener";
PHP="/usr/local/bin/php"
DAEMON_OPTS="/tmp/ex.php"
DAEMON_PARAMS="";
LOG=/var/log/${PROGRAM}.log
PID=/var/run/${PROGRAM}.pid
LOCK=/var/lock/subsys/${PROGRAM}
RETVAL=0
start() {
if [ -f $PID ] && checkpid `cat $PID`; then
echo "$NAME is already running."
exit 0
fi
echo -n $"Starting $NAME: "
daemon --pidfile=${PID} "$PHP $DAEMON_OPTS $DAEMON_PARAMS >> $LOG &"
pgrep -f "$DAEMON_OPTS" > $PID
usleep 500000
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch $LOCK
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
stop() {
if [ ! -f $PID ]; then
echo "$NAME is already stopped."
exit 0
fi
echo -n $"Stopping $NAME: "
echo -n "Stopping $NAME: " >> $LOG
if kill `cat $PID`; then
RETVAL=0
rm -f $LOCK
rm -f $PID
echo_success
else
RETVAL=1
echo_failure
fi
echo
[ $RETVAL = 0 ]
}
status_fn() {
if [ -f $PID ] && checkpid `cat $PID`; then
echo "$NAME is running."
exit 0
else
echo "$NAME is stopped."
exit 1
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status_fn
;;
restart|force-reload)
stop
start
;;
*)
echo $"Usage: $PROGRAM {start|stop|restart|force-reload|status}"
RETVAL=3
esac
exit $RETVAL
[SPOILER="PHP script">
-
Which user runs the script? AFAIK ..cloudlinux should not interfere in root owned process and php-cli you are using should not be limited by execution or memory limits in php.ini. I think it's better to contact CL support 0 -
Script is running by root. 0 -
It should run uninterrupted 0 -
Hello, Are you using any applications such as CSF/LFD that can kill processes based on resource usage? Thank you. 0 -
No. I am not using such apps. There is a cron which kill php scripts which belongs to 'init' as parent. Thanks to Bogdan@cloudlinux for the info. 0 -
Ah yes /etc/cron.d/kill_orphaned_php-cron is a cloudLinux script . 0 -
I'm happy to see you were able to address the issue. Thank you for updating us with the outcome. 0
Please sign in to leave a comment.
Comments
7 comments