0

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

Oleg Barabanov
  • 2,468
  • 2
  • 8
  • 17
Ammar
  • 1
  • 1
  • I tried running the cron both as a non-root and the root user with the same behavior. – Ammar Aug 10 '22 at 04:30
  • Can you provide process list watching PM2 process? When you add you cron job, what is the logged username? – Alaindeseine Aug 10 '22 at 16:01
  • It is watching for server,cronJob,processes only not the modules. The cron I've added is */10 * * * * /usr/bin/php /home/ubuntu/pm2script.php in logs I can see the corn is logged as ubuntu – Ammar Aug 11 '22 at 03:53
  • Sorry for my bad english, what i want is the result of this command: `ps axuf | grep "pm2"` – Alaindeseine Aug 11 '22 at 07:23
  • @Alaindeseine, no problem mate here's what you asked for. https://pastebin.com/2zMtyL5V – Ammar Aug 12 '22 at 14:50
  • @Alaindeseine any leads bro? I've tried multiple times and different methods with the same response. It should be running the same with manual and corn. – Ammar Aug 14 '22 at 20:17

1 Answers1

0

Just got it resolved by adding the absolute path for shell_exec

Ammar
  • 1
  • 1