danb35 / freenas-iocage-nextcloud

Script to create an iocage jail on FreeNAS for the latest Nextcloud 28 release, including Caddy, MariaDB or PostgreSQL, and Let's Encrypt
GNU General Public License v3.0
250 stars 71 forks source link

Cron Task Issue? #183

Closed arthertm closed 2 years ago

arthertm commented 2 years ago

Hi Dan,

I recently did a fresh install of 23, to update from 22 (choose a fresh install). All is good except for the Nextcloud background tasks dont run, I get a "Last job execution ran 12 minutes ago. Something seems wrong" message.

crontab -u www -e shows

/5 * /usr/local/bin/php -f /usr/local/www/nextcloud/cron.php

which looks correct.. but something amiss..

Is their anything you can suggest? It would appear as though the task is not running.

Any guideance appreciated.

danb35 commented 2 years ago

What happens if you try running /usr/local/bin/php -f /usr/local/www/nextcloud/cron.php manually from within the jail? Does that change anything?

arthertm commented 2 years ago

Thanks or coming back Dan, response to that is..

Console has to be executed with the user that owns the file config/config.php Current user id: 0 Owner id of config.php: 80

I checked user ID's and www is 80... did a ls -l of config.php

www:*:80:80:World Wide Web Owner:/nonexistent:/usr/sbin/nologin

_-rw-r--r-- 1 www www 495 Jan 27 19:34 .htaccess -rw-r--r-- 1 www www 0 Jan 27 19:34 CANINSTALL -rw-r----- 1 www www 1372 Feb 8 19:28 config.php -rw-r--r-- 1 www www 64160 Jan 27 19:34 config.sample.php

Slightly out of my comfort zone, again, thanks for help...

arthertm commented 2 years ago

Trying to understand this issue, I ran the below aiming to run command as user www:

sudo -u www /usr/local/bin/php -f /usr/local/www/nextcloud/cron.php

I am then greeted with the following error: -

OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

Appreciate any advice, please?

wein-geist commented 2 years ago

I can confirm the error of @arthertm, I see the same error message when running the cron.php. It also shows up whenever I run the occ command for any action.

Which also already happened during the installation process, exactly at the occ set memcache APCu line (490). After that, the error shows up for the remaining occ commands. Here is an extract of the installation process:

The current PHP memory limit is below the recommended value of 512MB.
System config value log_type set to string file
The current PHP memory limit is below the recommended value of 512MB.
System config value logfile set to string /var/log/nextcloud/nextcloud.log
The current PHP memory limit is below the recommended value of 512MB.
System config value loglevel set to string 2
The current PHP memory limit is below the recommended value of 512MB.
System config value logrotate_size set to string 104847600
The current PHP memory limit is below the recommended value of 512MB.
System config value memcache.local set to string \OC\Memcache\APCu
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set redis host --value="/var/run/redis/redis.sock" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set redis port --value=0 --type=integer failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set memcache.distributed --value="\OC\Memcache\Redis" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set memcache.locking --value="\OC\Memcache\Redis" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set overwritehost --value="myhostname.net" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set overwrite.cli.url --value="http://myhostname.net" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set overwriteprotocol --value="http" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set htaccess.RewriteBase --value="/" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ maintenance:update:htaccess failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set trusted_domains 1 --value="myhostname.net" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ config:system:set trusted_domains 2 --value="192.168.0.251" failed!
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
Command: su -m www -c php /usr/local/www/nextcloud/occ background:cron failed!
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

Command: su -m www -c php -f /usr/local/www/nextcloud/cron.php failed!
crontab: /mnt/includes/www-crontab: Permission denied
Command: crontab /mnt/includes/www-crontab failed!
Successfully removed mount from nextcloud_23's fstab
Installation complete!

Researching this error quickly leads to php.ini, where the following line is needed (apc.enable_cli=1), but this is already correct.

GJSchaller commented 2 years ago

I came here to note something similar, in that when I run tasks from the command line / shell inside the Jail, it does not seem to pick up settings from php.ini - in my case, I both noted that apc.enable_cli=1 was set (and ignored by the CRON task), but also that it didn't seem to honor the memory limit of 512MB from the command line when running a manual update of Nextcloud.

Is it possible the command line version of PHP is not pulling from the same php.ini, or something similar?

Aephir commented 2 years ago

I've had a lot of the same, and have to pass --define apc.enable_cli=1 every time I want to do anything, e.g.

sudo -u www php --define apc.enable_cli=1 occ maintenance:mode --off

This works for some things, but is probably not a good long term solution. I have updated this in all the files I could think could possibly be relevant (in php.ini, /usr/local/etc/php, /usr/local/etc/php-fpm.d), but I still have to explicitly write it in every command.

And I also see a lot of errors related to PHP, e.g. the ... (Is the matching PHP module installed and enabled?) mentioned above, and this when trying occ mainetenance:repair:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) 

and

The current PHP memory limit is below the recommended value of 512MB.

I also noticed in my install log, towards the end:

OC\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

crontab: /mnt/includes/www-crontab: Permission denied
Command: crontab /mnt/includes/www-crontab failed!
Successfully removed mount from nextcloud's fstab
Installation complete!

so it's likely been an issue (for me at least) since the very beginning, I just haven' noticed until somewhat later.

GJSchaller commented 2 years ago

I've been doing some troubleshooting on the PHP side - the ini file seems to be honored from the command line when running basic diagnostics (php --ini outputs the desired variables / settings: memory_limit is 512M ). Maybe the issue is linked a setting within the Nextcloud file structure / environment?

GJSchaller commented 2 years ago

The permissions on php.ini are incorrect, resulting in the user www not being able to read it, and applying the defaults. Here's the discussion:

https://forums.freebsd.org/threads/php-8-0-command-line-ignoring-php-ini-in-freebsd-13-1-jail.85320/

I did a chmod 644 to my php.ini, and things are now working properly - both in terms of memory_limit, and apc.enable_cli=1

danb35 commented 2 years ago

@GJSchaller, thanks for tracking down the issue--I never saw it myself, so I'm not sure why you (and others) were having this problem, but that gave me something to work with. I've addressed in the script by changing ownership on php.ini rather than changing its permissions.