Using Cronjobs/Scheduled Tasks to Check Your Client Sites

YourSites offers you the ability to check for updates on your client sites and also to check that the client sites are not down.

At present there is a single set of configuration options that control the frequency that this is done across all client sites.  In future releases we may extend this to allow client site specific settings - if there is demand for this.

Configuring Frequency of Checks

In the backend of YourSites - if you click the 'Options' button you can configure the scheduled tasks.

  1. Start by setting the email addresses and name for the sender and recipient of the notification messages
  2. You can set a security key for running the cronjob - if you set a value here it will be required as an argument to your cronjob script to it to be able to run (see below for explanation)
  3. Then choose if you want to check for Joomla Updates, Extension Updates, Client Sites not being down, generating Akeeba Backups, checking Akeeba Backups and clearing the site cache
  4. When you choose any of these options you are asked for 2 or 3 numbers - taking the Joomla Update checks as an example
    1. 'Check Joomla Update Interval' - this is the time between each check to a specific client site that you want to check that Joomla is up
    2. 'Cronjob batch size' - since you will not want to check all your sites at exactly the same time (this could overload your servers if you have a large number of client sites on the same server) we do the checks in batches or groups of sites.  This is the number of sites that are checked with each pass of the cronjob.
    3. 'Update Notification'  - if you run your Joomla update check once an hour you probably don't an hourly notification of updates being available.  This allows you set the interval between notification emails.  If something else changes in the meantime e.g. another new release of Joomla, an additional extension update or the site not being down then this limitation on notifications is ignored and a new notification is sent out.   Note this setting not needed for  backup generation, checks and clearing the cache.

You need to set up one or more cronjobs to add actions to the queue and to process them.

In the screenshot above we are asking the server to check for Joomla and Extension updates once every 720 minutes (12 hours) and to check each client site is up once every 5 minutes.  We will check 20 sites for Joomla updates, 10 sites for Extension updates (we set this lower since this typically takes longer to process) and 30 sites for sites being up (this is a fast/lightweight test so we can easily do 30 at a time.

Please note that the checks are done sequentially since PHP on Windows doesn't support forking.  We may offer simultaneous checks in PHP on Unix/Linux down the line if there is demand.

Each time the cronjob is executed we complete 2 tasks.

  1. We check the update intervals and if we are due another set of checks we add these to the queue of checks to be undertaken
  2. If you setup a single cronjob we process the queue of checks based on the batch sizes given above - doing the checks in the following order : websites up, Joomla updates, extension updates.  NOTE that you cannot perform Akeeba Backups as part of the main cron - it is too slow and will block the other actions
  3. If you setup multiple cronjobs we process actions you select based on the batch sizes set for each action type.  You always need to setup a separate cronjobs for processing AkeebaBackups.

If you have sites that are down or require updates you will be sent a notification email.

Executing the Cronjob/Scheduled Task

1. Using wget/curl to open a webpage

You set up cron to open 2 different webpages (replacing YOURSECRETKEY with the value you set in your config.

wget "https://YOURDOMAIN/index.php?option=com_yoursites&task=cron.addToCron&secretkey=YOURSECRETKEY"

and for a catch all processing cronjob

wget "https://YOURDOMAIN/index.php?option=com_yoursites&task=cron.processCron&secretkey=YOURSECRETKEY"

if you want specific action cronjobs you will want (available actions are checkcore, checkextensions, checksiteup, createbackups)

wget "https://YOURDOMAIN/index.php?option=com_yoursites&task=cron.processCron&secretkey=YOURSECRETKEY&action=createbackups"

The addToCron page should be opened at least as often as the shortest interval you have configured above.

The processCron page should be opened as often as is needed to process the queue entries before its topped up by the addToCron task.,  In our case above we add site checks every 5 minutes and process them in batches of 30 so if we have 97 sites to process we will need 4 batches to be run every 5 minutes (97 / 30 rounded up to the nearest whole number) so we should set our processCron task to run once a minute.

If you want to run a simple combined cron job for everything then simply use

wget "https://YOURDOMAIN/index.php?option=com_yoursites&secretkey=YOURSECRETKEY"

2. Using Joomla cli

YourSites adds a cli script to your Joomla /cli folder /cli/yoursites_cron.php - you should set this up to run with the same frequency as the processCron task described above.  Pass your secret key as an argument to this script e.g.

php cli/yoursites_cron.php YOURSECRETKEY

or

php cli/yoursites_cron.php key=YOURSECRETKEY

 You can specify actions using the action argument (available actions are checkcore, checkextensions, checksiteup, createbackups)

php cli/yoursites_cron.php key=YOURSECRETKEY action=createbackups

You can also separate out the adding to queue and processing queue as

php cli/yoursites_cron.php key=YOURSECRETKEY action=createbackups task=add

or

php cli/yoursites_cron.php key=YOURSECRETKEY action=createbackups task=process

Deciding on frequency

We've added a helpful tool to the config pages to guide you on how often to run the cron jobs. See

click this for more information.

Important Note

In both cases the you can configure YourSites so that the script checks that the machine that is running the cron/loading the cron webpage has the same IP address as the YourSites server itself or has a specific IP address.  In other words you can configure the YourSites to only allow the script to run from specific machines. If you want to use a 3rd party cron service to run your cronjob for you you must relax this setting and rely on the 'secret key' to block "malicious" users from triggering your cronjob for you.

We love every single one of our users, without you YourSites simply couldn't happen! So we would love a review at the Joomla! JED so we can let others know about us too, please take a minute to write a review:

https://extensions.joomla.org/extension/yoursites-manager/

If you feel you have something negative to say, we would implore you to speak to us first, as we really really don't want anyone to be unhappy!

STAY CONNECTED