Cron.php on snap

Is a cronjob needed for cron.php if I have installed Nextcloud via snap? It seems to be running a cron.php job every so often even without an entry in crontab, although not every 5 minutes, the interval varies.
If I add a cronjob to the root’s crontab, logs show it runs every 5 minutes, but the Nextcloud web UI still shows that it does not - it reports a random variable interval, sometimes I look at it and it says ran 2 minutes ago, sometimes it goes 30 minutes without running (at least as far as the web UI reports).

The main issue I have is that calendar emails & push notifications are not consistent. They are generally delivered after the time they are set for. This becomes a problem for short-notice calendar additions - e.g. if I add an item for, say, 2 hours from now, and I want a notification 10-20 minutes before the event, the email might arrive after the event start time, which I believe is due to this randomly variable cron interval.

Any ideas as to how to fix this are welcome.

Did you active cron on nextcloud (check the panel admin) ?

1 Like

The cron job needs to run as the same user as the webserver.

1 Like

Hiya, thanks for chipping in.

Yes cron is selected in the admin page.

The snap runs as root, so I figured the cron should run as root too… is that not right?
Edit: it even tells me in the admin panel:
The cron.php needs to be executed by the system user “root”.

Root would be correct if nextcloud runs as root :slight_smile: Not exactly sure how it works in docker though.

1 Like

So the cron job is needed for a snap install then? And would anyone have any insight on why the admin panel shows that it runs are random intervals way past the 5 minutes?

I have added the following cron job in my root crontab:

*/5 * * * * /snap/nextcloud/current/bin/php -f /snap/nextcloud/current/htdocs/cron.php

It started running the job every 5 minutes, but after a while it stopped running it. Cron log shows “session opened for user root” and “session closed for user root” every 5 minutes, but nothing running in between.

Is this the correct command to type in crontab?

I am not familiar with snap, so I might be off here.

Your webserver, is that nginx or Apache? Check what users they are running. On Ubuntu it is often www-data.

This command can list the user the web server is running as

ps aux | egrep '(apache|httpd)'

Here you see my apache webserver runs as user apache

root     51495  0.0  0.3 395336 28172 ?        Ss   Jun09   0:04 /usr/sbin/apache2 -D DEFAULT_VHOST -D HTTP2 -D PHP -D SSL -D SSL_DEFAULT_VHOST -D PROXY -D FCGID -D QOS -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   59063  0.0  1.2 243700 99872 ?        Ssl  Jun09   2:22 /usr/sbin/redis-server
apache   79290  0.0  0.1  93000 11096 ?        S    15:41   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D HTTP2 -D PHP -D SSL -D SSL_DEFAULT_VHOST -D PROXY -D FCGID -D QOS -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   79291  0.8  0.8 2810600 65732 ?       Sl   15:41   1:23 /usr/sbin/apache2 -D DEFAULT_VHOST -D HTTP2 -D PHP -D SSL -D SSL_DEFAULT_VHOST -D PROXY -D FCGID -D QOS -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
apache   79356  1.0  1.2 3025976 101384 ?      Sl   15:41   1:36 /usr/sbin/apache2 -D DEFAULT_VHOST -D HTTP2 -D PHP -D SSL -D SSL_DEFAULT_VHOST -D PROXY -D FCGID -D QOS -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start

I am no expert either, but as far as I understand, the snap runs as one unit under root, and it includes everything Nextcloud needs to run inside the snap, including apache, php etc. So they all run as root inside the snap. The snap is running its own apache instance. This shows in ps as running under the root user.

Seems all odd. Do you get any errors in the nextcloud log file?

Does occ work?

/snap/nextcloud/current/bin/php -f /snap/nextcloud/current/htdocs/occ

Yeah snaps are horrible for troubleshooting and customisation, as I am finding out. However, I did try to install Nextcloud manually but came up with a lot of problems that the snap just doesn’t have as it’s pre-configured to just work out of the box.

The nextcloud.log in my data folder is actually empty. In a snap install occ is run like ‘nextcloud.occ’, and it runs fine for whatever occ commands I’ve had to use.