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!

SOLVED PHP daemon killed mysteriously

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

  1. rahnev

    rahnev Active Member

    Joined:
    Jul 6, 2016
    Messages:
    40
    Likes Received:
    3
    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:
    97
    Likes Received:
    14
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. rahnev

    rahnev Active Member

    Joined:
    Jul 6, 2016
    Messages:
    40
    Likes Received:
    3
    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:
    97
    Likes Received:
    14
    Trophy Points:
    8
    Location:
    Kochi,Kerala,India
    cPanel Access Level:
    Root Administrator
    It should run uninterrupted
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,408
    Likes Received:
    1,953
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

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

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. rahnev

    rahnev Active Member

    Joined:
    Jul 6, 2016
    Messages:
    40
    Likes Received:
    3
    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:
    97
    Likes Received:
    14
    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 .
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,408
    Likes Received:
    1,953
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    I'm happy to see you were able to address the issue. Thank you for updating us with the outcome.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice