Linux / 电脑技术 · 2022年6月11日 0

Nextcloud cron.php 每5分钟运行设置

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=apache
ExecStart=/usr/bin/php -f /var/www/html/nextcloud/cron.php
KillMode=process

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.

The KillMode=process setting is necessary for external programs that are started by the cron job to keep running after the cron job has finished.

Note that the .service unit file does not need an [Install] section. Please check your setup because we recommended it in earlier versions of this admin manual.

nextcloudcron.timer should look like this:

[Unit]
Description=Run Nextcloud cron.php every 5 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
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 5 minute timer after the service-unit was last activated.

Now all that is left is to start and enable the timer by running this command:

systemctl enable --now nextcloudcron.timer

php.ini  加入  apc.enable_cli=1