Cron job not working - migration from plesk

Discussion in 'Installation/Configuration' started by ptidav, Dec 19, 2023.

  1. ptidav

    ptidav New Member

    Hello,
    i'm migrating a website from a plesk server to a new ispconfig server.
    I get some trouble with a cron job that is not executed.
    I added the following syntax in the cron job interface :
    php web/crons/create-files-log-day.php >> web/crons/create-files-log-day.log 2>&1
    I checked "active" and "log output" options.
    Actually it does not work, cron is not executed by the system at the planed time.

    If I run the command directly from a terminal, the script is executed and the log updated.

    If someone could give me some help, thanks in advance.
    David
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    In Cronjobs on Linux you must set the full path to a command as corn does not know where the command php is otherwise, in your case:

    /usr/bin/php web/crons/create-files-log-day.php
     
  3. ptidav

    ptidav New Member

    I also just saw that updating the cron from the administration interface was not taken into account.... I have to save the modification twice for it to be effective (seen by doing a cat / etc/crond.d/ispc_chrooted_web1).
    I use google chrome.

    After modifying the syntax, the cron execution is started but it does not execute.
    I found this line of information in the log /private/cron.log: "sh: 1: crontab: not found"
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    You must wait until changes are written to disk, this takes up to 60 seconds, there is an indicator (red dot) in the navigation bar that shows you when there are any pending config changes.

    That's likely from your earlier attempt as php can not be found without a proper path, or there is no PHP in the jail for this website cronjob. You can now either check the jail if PHP is there to see why your script fails. Or you just enter the URL to the script in the crown command field, this creates a URL cronjob:

    https://yourdomain.tld/crons/create-files-log-day.php

    which is generally the easiest option, as long as that script supports it to be called by URL. Or you can try switching the cronjob to non jailed, but then you must use the full path to the php script like:

    /usr/bin/php /var/www/yourdomain.tld/web/crons/create-files-log-day.php
     
  5. ptidav

    ptidav New Member

    My script can not be called from URL....

    I checked php binary is in the jail. It is available (php and php8.1).
    [​IMG]

    On plesk server it was called by this syntax :
    /opt/plesk/php/7.4/bin/php /var/www/vhosts/yourdomain.tld/httpdocs/crons/create-files-log-day.php >> /var/www/vhosts/yourdomain.tld/httpdocs/crons/create-files-log-day.log 2>&1

    I made a try with full path :
    /usr/bin/php /var/www/yourdomain.tld/web/crons/create-files-log-day.php
    and I get the following error in the private/cron.log file :
    Could not open input file: /var/www/yourdomain.tld/web/crons/create-files-log-day.php
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    The full path is only used when you switch to a non-jailed cronjob, it can not work within a jail as /var/www/yourdomain.tld/ is the folder / of the jail. So if you want to use the full path, you must create a cronjob without jailkit.

    and what happens when you run:

    /usr/bin/php web/crons/create-files-log-day.php

    inside the jail?
     
  7. ptidav

    ptidav New Member

  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Hmm, ok. So the cronjob that ISPConfig created works fine and gets excited correctly. The issue is that this php script seems to want to run other Linux commands, in this case, the crontab command, which is not in the jail. This script should not try to alter the crontab, you should check its code to see why it is doing this. Might even be that the script contains malware that tries to install itself into the crontab.
     
  9. ptidav

    ptidav New Member

    the script creates directories in web/crons/logs2 with year, month and day :
    PHP:
    <?php
    define
    ('folder_log''web/crons/logs2');

    $output = [];
    $result_code null;
    exec('crontab -l 2>&1'$output$result_code);

    $folder folder_log.'/'.date('Y/m/d');

    if(!
    file_exists($folder))
        @
    mkdir($folder0755true);

    if(
    === $result_code){
        foreach(
    $output as $line){
            if(
    preg_match('#^[^\#].*/(cron_[\w\d]+)\.php#'$line$m)){
                if(
    $fa fopen($file $folder.'/'.$m[1].'.log''a+')){
                    
    fclose($fa);
                    
    $result true;
                }
                else
                    
    $result false;

                echo 
    $file.': '.($result 'success' 'fail')."\n";
            }
        }
    }
    else
        echo 
    implode("\n"$output);

    echo 
    "\n";
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    And it calls crontab command:

    PHP:
    exec('crontab -l 2>&1'$output$result_code);
    listing cronjobs of the local user and returning them does not really makes sense to me for what the script is doing, especially as this script is not and will not get called by a user crontab. So yes, you can add crontab command to the jail, but this would allow scripts to create cronjobs in the background that you can not see or manage from ispconfig. So either install crontab command in the jail (you can do that with jk_cp command or by adding it to jail settings in ISPConfig under system > server config) or switch to a unjailed cronjob, or change your script so that it does not try to mess with crontab.
     
  11. ptidav

    ptidav New Member

    Ok, thanks for all your precisions.
    So, I tried to modify my cron command to execute it as non jailed :
    /usr/bin/php /var/www/yourdomain.tld/web/crons/create-files-log-day.php

    I get the following error again in the private/cron.log file :
    Could not open input file: web/crons/create-files-log-day.php

    I can see this entry when I do a ls -l in /etc/crond.d/
    -rw-r--r-- 1 root root 222 Dec 20 12:59 ispc_chrooted_web1
    The cron seems to be still in jailed environnement no ?

    So, do I need to change the client settings in ISPCONFIG to allow non-jailed crons to run?
    I read in this thread https://forum.howtoforge.com/threads/how-to-disable-completely-jailkit-for-cron-jobs.57420/ where you replied that you have to go to clients, select the client and allow non jailed cronjobs on the limits tab.
    Do you talk about this setting ?
    [​IMG]
     
  12. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes, if the file has chrooted in its name, then its a chrooted cronjob.

    yes

    yes. you might have to recreate the cronjob afterwards.
     
    Th0m likes this.

Share This Page