TiBeN/CrontabManager

CrontabManager not reading/writing crontabs correctly

Closed this issue · 3 comments

I suspect it's because it was made from another instantiation of Crontab from my other batch file?

But do you know why the var_dump can't read the existing cron?

$results = $crontabRepository->findJobByRegex("/cadence-scheduler-{$scheduler_id}/"); var_dump($scheduler_id, $results, $crontabRepository->getJobs()); die();
Output is :
int(1)
array(0) {
}
array(0) {
}

it shows no $results for cadence-scheduler-1 however if you check sudo crontab -u www-data -l
45 15 * * * php /redacted/batch/cadence-step-checker.php '1' > /dev/null 2>&1 & #cadence-scheduler-1

which clearly shows, it exist in the crontab file of www-data.

PROBLEM 2

This is also another problem

$crontabRepository = new CrontabRepository(new CrontabAdapter());
  $crontabJob = new CrontabJob();
  $crontabJob
      ->setMinutes('*')
      ->setHours('*')
      ->setDayOfMonth('*/'.getBinDelayDay($scheduler_id))
      ->setMonths('*')
      ->setDayOfWeek('*')
      ->setTaskCommandLine('php '. SITEROOT .'/batch/cadence-bins.php \'' . $scheduler_id . '\' > /dev/null 2>&1 &')
      ->setComments('cadence-bin-'.$scheduler_id);
  $crontabRepository->addJob($crontabJob);
  $crontabRepository->persist();

But if you run that same command again, the library will know there were cadence-bin-id created, however if you check on sudo crontab -u www-data -l it was not written in there, why? and where was it written?

TiBeN commented

Hi rochiey,

I suspect your PHP process user is not aligned with the Linux user of your crontab. I remind you that on Linux each user has its own crontab file.

You can check the user of your PHP process by adding this to your PHP code and see what is returned:

echo posix_getpwuid(posix_geteuid())['name'];

According to your issue, your crontab is attached to the user "www-data":

sudo crontab -u www-data -l

If the PHP line does returns another user than "www-data" you are not handling the correct crontab file.

By default the library works with the crontab file of the user your PHP script is run. But you can make the library to work with the crontab of another user than runtime user like explained here in the README.

Please don't forget to close the issue if you solved it.

Make sense, because when I do the testing, I manually run the batch file through terminal, so it would make sense that the library will create the cron in the user's cron instead of using www-data (which is normal because www-data is the user that the library will use when in background process). My bad for not checking my users cron during the debug process.

TiBeN commented

Great news. I'm glad you solved your issue.