Pm2 trigger email if service down

198 Views Asked by At

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('[email protected]', 'PM2 Missing', implode("\n", $errored), 'From: [email protected]');
}

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!!

1

There are 1 best solutions below

0
Ammar On

Just got it resolved by adding the absolute path for shell_exec