From 147cd911090ddb78348ba88dedb0acb09a4a5566 Mon Sep 17 00:00:00 2001 From: Devices Date: Sat, 3 Jun 2017 13:30:47 +0200 Subject: [PATCH] systemd timer as option for background service Added examples and a smart explanation on how to automate cron.php with systemd. --- .../background_jobs_configuration.rst | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/admin_manual/configuration_server/background_jobs_configuration.rst b/admin_manual/configuration_server/background_jobs_configuration.rst index ca4cb1faa..5128e8bd7 100644 --- a/admin_manual/configuration_server/background_jobs_configuration.rst +++ b/admin_manual/configuration_server/background_jobs_configuration.rst @@ -83,3 +83,46 @@ You can verify if the cron job has been added and scheduled by executing:: .. note:: Please refer to the crontab man page for the exact command syntax. .. _easyCron: http://www.easycron.com/ + +systemd +~~~~~~~ + +If systemd is installed on the system, a systemd timer could be an alternative to a cronjob. + +This approach requires two files: **nextcloudcron.service** and **nextcloudcron.timer**. Create these two files in ``/etc/systemd/system/``. + +**nextcloudcron.service** should look like this:: + + [Unit] + Description=Nextcloud cron.php job + + [Service] + User=www-data + ExecStart=/usr/bin/php -f /var/www/nextcloud/cron.php + + [Install] + WantedBy=basic.target + +Replace the user ``www-data`` with the user of your http server and ``/var/www/nextcloud/cron.php`` with the location of **cron.php** in your nextcloud directory. + +**nextcloudcron.timer** should look like this:: + + [Unit] + Description=Run Nextcloud cron.php every 15 minutes + + [Timer] + OnBootSec=5min + OnUnitActiveSec=15min + Unit=nextcloudcron.service + + [Install] + WantedBy=timers.target + +The important parts in the timer-unit are ``OnBootSec`` and ``OnUnitActiveSec``.``OnBootSec`` will start the timer 5 minutes after boot, otherwise you would have to start it manually after every boot. ``OnUnitActiveSec`` will set a 15 minute timer after the service-unit was last activated. + +Now all that is left is to start and enable the timer by running these commands:: + + systemctl start nextcloudcron.timer + systemctl enable nextcloudcron.timer + +.. note:: Select the option ``Cron`` in the admin menu for background jobs. if left on ``AJAX`` it would execute the AJAX job on every page load.