Merge pull request #492 from Devices/patch-1

systemd timer as option for background service
This commit is contained in:
Morris Jobke
2017-06-04 16:16:13 -05:00
committed by GitHub

View File

@@ -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.