Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED PHP daemon killed mysteriously

Discussion in 'CloudLinux' started by rahnev, May 31, 2017.

  1. rahnev

    rahnev Active Member

    Joined:
    Jul 6, 2016
    Messages:
    33
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    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?

    Code:
    #!/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
    

    Code:
    <?php
    
    $log = "/tmp/ex.log";
    
    while(true){
        $date = date("Y-m-d H:i:s");
        $data = "$date\n";
    
        file_put_contents($log, $data, FILE_APPEND | LOCK_EX);
        sleep(10);
    }
    
    ?>
     
  2. Anoop P Alias

    Anoop P Alias Well-Known Member

    Joined:
    Mar 31, 2015
    Messages:
    76
    Likes Received:
    10
    Trophy Points:
    8
    Location:
    Kochi,Kerala,India
    cPanel Access Level:
    Root Administrator
    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
     
  3. rahnev

    rahnev Active Member

    Joined:
    Jul 6, 2016
    Messages:
    33
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    Script is running by root.
     
  4. Anoop P Alias

    Anoop P Alias Well-Known Member

    Joined:
    Mar 31, 2015
    Messages:
    76
    Likes Received:
    10
    Trophy Points:
    8
    Location:
    Kochi,Kerala,India
    cPanel Access Level:
    Root Administrator
    It should run uninterrupted
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,427
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Are you using any applications such as CSF/LFD that can kill processes based on resource usage?

    Thank you.
     
  6. rahnev

    rahnev Active Member

    Joined:
    Jul 6, 2016
    Messages:
    33
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    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.
     
  7. Anoop P Alias

    Anoop P Alias Well-Known Member

    Joined:
    Mar 31, 2015
    Messages:
    76
    Likes Received:
    10
    Trophy Points:
    8
    Location:
    Kochi,Kerala,India
    cPanel Access Level:
    Root Administrator
    Ah yes /etc/cron.d/kill_orphaned_php-cron is a cloudLinux script .
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,427
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    I'm happy to see you were able to address the issue. Thank you for updating us with the outcome.
     
Loading...

Share This Page