Setting up jailed cron

Discussion in 'ISPConfig 3 Priority Support' started by pawan, Feb 5, 2020.

Tags:
  1. pawan

    pawan Member HowtoForge Supporter

    I have added a cron for one website.
    cron scriptis is web root folder.
    The generated cron file in /etc/cron.d is like
    Code:
    *       *       *       *       *       web255  /web/backup.sh >>/private/cron.log 2>>/private/cron_error.log #mysite.com
    In IPSCONFIG cron setting I had enetered full path as
    /var/www/clients/client135/web255/web/backup.sh
    Now in the log system.log, I can see the log entry like:
    Code:
    Feb  5 18:10:01 server2 CRON[8453]: (web255) CMD (/web/backup.sh >>/private/cron.log 2>>/private/cron_error.log #mysite.com)
    but no backup is generated. when I execute/run the file in terminal it works fine.
    Also I can't see any error log in private folder.
    what I am missing here.

    ISPConfig Version: 3.1dev
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    That's the wrong path as you refer to a root folder outside of the jail, ISPConfig detected your mistake and corrected it.

    Most likely your backup.sh file is not correct for being sued in a jail. You must use the full path for all commands that you use inside that script and you may only use commands or programs in that script that are installed inside the jail and take care to use correct paths, the root folder of the jail is /var/www/clients/client135/web255/, so when you e.g. refer to the web folder inside the script, then the correct path is /web and not /var/www/clients/client135/web255/web
     
  3. pawan

    pawan Member HowtoForge Supporter

    Hi Till,
    The contents of backup script is like below:
    Code:
    #!/bin/sh
    mongodump --db=mysite --out=/var/www/clients/client135/web255/backup/
    how I can setup this or include the command "mongodump" inside Jail.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    You can add programs to a jail with the jk_cp command.

    https://olivier.sessink.nl/jailkit/jk_cp.8.html

    first you must find out where mongodump is installed on your server, you can do that with the which command:

    which mongodump

    Let's assume it is in /usr/bin/, you have to check and alter the path! In that case, the command would be:

    jk_cp -j /var/www/clients/client135/web255 /usr/bin/mongodump

    Beside mongodump missing in the jail, the script has two more failues, missing path to mongodump and wrong path as --out parameter.
     
  5. pawan

    pawan Member HowtoForge Supporter

    Thanks Till,
    I used that command to copy the mongodump, also created a shell user with jail.
    and logged in with that jailed user. run the command sh backup.sh. working fine.
    but ispconfig cron still not working.
    cron file contents
    Code:
    MAILTO=''
    SHELL='/usr/sbin/jk_chrootsh'
    
    *       *       *       *       *       web255  /web/backup.sh >>/private/cron.log 2>>/private/cron_error.log #mysite.com
    and script file contents
    Code:
    #!/bin/sh
    mongodump --db=mysite --out=/backup/
    the setting in ipsconfig cron
    [web_root]/backup.sh
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    The script is still wrong, you missed adding the path to mongodump. The script has to be something like:

    Code:
    #!/bin/sh
    /usr/bin/mongodump --db=mysite --out=/backup/
    you have to set the correct path, my example is just a guess. and I don't know how mongodump connects to the database, if it tries to use a socket, then it must fail from within the jail, the connection will be possible only trough 127.0.0.1 IP address.
     
  7. pawan

    pawan Member HowtoForge Supporter

    I tried this as well, but no luck
    Code:
    #!/bin/sh
    /usr/bin/mongodump --db=mysite --out=/backup/
    Just wanted to confirm, as a layman, I assume that when I can execute the backup.sh as a jailed user with the same content(script), I assume that cron should work?
    if not, how I can add cron from ISPCONFIG interface, may be non-jailed.
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    When it works as a jailed SSH user, then it should work as cron as well, beside that cron has even stricter requirements like the need for full paths etc. And you confirmed that /usr/bin/ is indeed the right path? As I mentioned above, I don't know in which path this tool is installed, so you have to check it on your server.

    Justs et cron level to full cron in client limits. Then delete the current cronjob and create it again.
     
  9. pawan

    pawan Member HowtoForge Supporter

    Hi Till,
    Got it working like I have updated the backup.sh file as:
    Code:
    #!/bin/sh
    /usr/bin/mongodump --db=mysite --out=/var/www/mysite.com/backup/
    and for cron instead of adding backup.sh, I created another file backup.php with
    PHP:
    <?php
    shell_exec
    ("./backup.sh");
    ?>
    and added the backup.php file in ispcofig cron.
    and the same is working fine.
    I still couldn't make out, why adding `backkup.sh` directly to cron won't work.
     

Share This Page