I am running a php script to output the server, cronJobs, and processes. If I do pm2 stop server and run the script it shoots an email with details of which service is stopped, everything is working perfectly as if $errored
comes in place.
$errored = array_diff($required, $running);
echo "Errored:\n";
print_r($errored);
if ( $errored ) {
mail('youremail@domain.com', 'PM2 Missing', implode("\n", $errored), 'From: errors@yourserver.com');
}
But when I run the script with cron it throws an error that all the PM2 services are stopped.
Could it be possible Pm2 is running under user "ubuntu" and cron is running as a root user?
Need help!!