SiteHost

Cron Jobs

Scheduled jobs can be convenient to automate the maintenance or administration of a website application. You can create cron jobs per Container on your Cloud Container server.

Managing Scheduled Jobs

You need a SSH/SFTP user linked to at least one Container to manage the scheduled jobs. If you use a SSH/SFTP user linked to a single Container you can follow these steps to add or edit your cron jobs:

  1. SSH into the Container.
  2. Change into the containers/crontabs/ directory.
  3. Edit the crontab file accordingly.
  4. Save the file and wait one minute for the file to be processed.

You can use the command below to edit the file through an SSH session.

nano /container/crontabs/crontab

This crontab file uses the standard cron format and you can find more information about this on the Cron Wikipedia page. The Contrab Guru helper is handy if you would like to check your crontab set up.

For convenience, all Cloud Container servers have the base Operating System Time Zone set to UTC (0), consider this when configuring your scheduled jobs.

Troubleshooting Scheduled Jobs

The jobs will be executed as the user www-data (uid: 33) on the Cloud Container servers. The www-data user should have access to all files and directories within the /container directory but the /container/backup/containers directory. If your scheduled jobs are not working properly, the tips below can help you track down the issue:

  • Run the task manually through the command line to ensure it is working as expected.
  • Edit the first line of the crontab file specifying the MAILTO variable, so you can receive the outputs of the command set when the task is processed. If no output is thrown, you won't receive emails.
  • Check the /container/logs/rsyslog/syslog log file. The lines as per the below indicate your crontab file is being processed.
        CRON[XX]: (root) CMD (/bin/cat /cron/crontab | /usr/bin/crontab -u www-data -)
  • Check you have an empty new line at the end of the crontab file
  • Ensure your crontab file is in the UNIX text file format. This is especially important for Windows users. We would recommend editing the crontab file via SSH using nano or vim text editors.

Working with the Cloud Container's file structure

In order to make the Cloud Containers as generic as possible, we had to make some choices and the mapping of the directory differs from what you can see in your SSH session. If you need to execute files under the application directory, or write some information into a log file, consider using /container/ instead of the paths you can see when connected via SSH.

Here is the matrix of the mapping from your ssh connection to the container:

Path to use Equivalent path
/container/application /data/docker_app
/container/logs /var/log/docker_app
/container/config /etc/docker_app