php - Check if process is running, if not start it -
i'm using ratchet, node js application , zeromq in codeigniter based php application.
in admin dashboard, want able see if socket running , if node js app running. if it's down, need able put online.
i know can use php's exec
putting online, script finish, command line.
how can achieve this? like:
ratchet: status online (stop, start, restart) node service: status online (stop, start, restart) zeromq: status online (stop, start, restart)
i tried lot of solutions including fsockopen()
check if port open...
but working solution check if node js application process on argument application file. if not use exec
run permanently (with &
argument) , putting output in logfile (in same folder of node app).
$node = '/usr/bin/node'; $base = '/path/to/your/app'; $appfile = 'my_app.js'; $logfile = 'my_app.log'; $proc = explode("\n", trim(shell_exec(" ps -ef | grep -v grep | grep $appfile"))); if ($proc[0] == '') { exec("$node $base/$appfile >> $base/$logfile &"); }
it's working fine , running node server once.
edit : minimalist php code version :
if(trim(shell_exec('ps -ef | grep -v grep | grep app.js')))=='') { exec('node /path/to/app.js >> /path/to/app.log &'); }
Comments
Post a Comment