Cron job hanging and possible work-arounds

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can. :heart:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • Nextcloud Hub 26 Spring (34.0.0)
  • Operating system and version (e.g., Ubuntu 24.04):
    • Debian 13.5 (trixie)
  • Web server and version (e.g, Apache 2.4.25):
    • apache2 2.4.67-1~deb13u3
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • None
  • PHP version (e.g, 8.3):
    • PHP 8.4.21 (cli) (built: May 8 2026 05:56:48) (NTS)
  • Is this the first time you’ve seen this error? (Yes / No):
    • No
  • When did this problem seem to first start?
    • Not sure. Say at least since April, 2026
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Zip file download, and updates since.
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • No

Summary of the issue you are facing:

From time to time, the cron job (cron.php) hangs, sometimes for a day or more before I discover it. I do not have a diagnosis or solution, but I do have two possible workarounds.

Steps to replicate it (hint: details matter!):

I have no idea, sorry. Possibly rebooting, which I have been doing a lot for unrelated reasons, but I have not tested this hypothesis.

Configuration

Nextcloud

The output of occ config:list system or similar is best, but, if not possible, the contents of your config.php file from /path/to/nextcloud is fine (make sure to remove any identifiable information!):

root@hawk:/var/local/nc.data# su www-data -c 'php -f /var/www/nextcloud/occ config:list system; echo $?'
{
    "system": {
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "nextcloud",
            "nextcloud.localdomain",
            "localhost",
            "hawk",
            "hawk.localdomain",
            "nextcloud.curleynet.mywire.org:17800"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "sqlite3",
        "version": "34.0.0.12",
        "overwrite.cli.url": "http:\/\/localhost",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "maintenance": false,
        "default_phone_region": "US",
        "theme": "",
        "loglevel": 2,
        "logtimezone": "America\/Denver",
        "logfile": "\/var\/log\/nextcloud\/nextcloud.log",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpmode": "smtp",
        "mail_sendmailmode": "smtp",
        "mail_smtpauth": true,
        "mail_smtpauthtype": "LOGIN",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "app_install_overwrite": [
            "calendar"
        ],
        "trashbin_retention_obligation": "auto, 90",
        "maintenance_window_start": 19,
        "filelocking.enabled": true,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "dbindex": 0,
            "timeout": 1.5
        },
        "versions_retention_obligation": "auto, 90",
        "data-fingerprint": "8fbb403d5754a1b6bf96b34cabc08a6b",
        "mail_smtpstreamoptions": {
            "ssl": {
                "allow_self_signed": false,
                "verify_peer": true,
                "verify_peer_name": true
            }
        }
    }
}
0
root@hawk:/var/local/nc.data# 

Apps

The output of occ app:list (if possible).

root@hawk:/var/local/nc.data# su www-data -c 'php -f /var/www/nextcloud/occ app:list; echo $?'
Enabled:
  - activity: 7.0.0
  - app_api: 34.0.0
  - appstore: 1.0.0
  - bruteforcesettings: 7.0.0
  - calendar: 6.5.0
  - circles: 34.0.0
  - cloud_federation_api: 1.18.0
  - comments: 1.24.0
  - contacts: 8.7.1
  - contactsinteraction: 1.15.0
  - dashboard: 7.14.0
  - dav: 1.39.0
  - federatedfilesharing: 1.24.0
  - federation: 1.24.0
  - files: 2.6.0
  - files_downloadlimit: 5.2.0-dev.0
  - files_external: 1.26.0
  - files_lock: 34.0.0
  - files_pdfviewer: 7.0.0-dev.0
  - files_reminders: 1.7.0
  - files_sharing: 1.26.0
  - files_trashbin: 1.24.0
  - files_versions: 1.27.0
  - firstrunwizard: 7.0.0-dev.0
  - logreader: 7.0.0
  - lookup_server_connector: 1.22.0
  - nextcloud_announcements: 6.0.0
  - notes: 6.0.0
  - notifications: 7.0.0-dev.1
  - oauth2: 1.22.0
  - office: 1.0.0
  - password_policy: 6.0.0-dev.0
  - privacy: 6.0.0-dev.1
  - profile: 1.3.0
  - provisioning_api: 1.24.0
  - recommendations: 7.0.0-dev.0
  - related_resources: 5.0.0-dev.0
  - serverinfo: 6.0.0
  - settings: 1.17.0
  - sharebymail: 1.24.0
  - support: 6.0.0
  - suspicious_login: 12.0.0-dev.0
  - systemtags: 1.24.0
  - tables: 2.2.0
  - text: 8.0.0
  - theming: 2.9.0
  - twofactor_backupcodes: 1.23.0
  - twofactor_totp: 16.0.0
  - updatenotification: 1.24.0
  - user_status: 1.14.0
  - viewer: 7.0.0-dev.0
  - webhook_listeners: 1.6.0
  - workflowengine: 2.16.0
Disabled:
  - admin_audit: 1.24.0
  - encryption: 2.22.0
  - photos: 7.0.0 (installed 2.0.1)
  - survey_client: 6.0.0-dev.0 (installed 2.0.0)
  - testing: 1.23.0
  - twofactor_nextcloud_notification: 8.0.0
  - user_ldap: 1.25.0
  - weather_status: 1.14.0 (installed 1.2.0)
0
root@hawk:/var/local/nc.data# 

The cron job hangs, sometimes for as much as a day. It may be associated with rebooting, which I have been doing a lot lately for unrelated reasons. I do not have a solution, but I have two possible workarounds.

  1. I originally got my nextcloudcron.service from an earlier version of the manual, version 28 I believe. The current version has a line the earlier version does not have, specifically the ExecCondition line. https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/background_jobs_configuration.html#systemd Inserting that line may help the problem.
  2. Use timeout to limit the life of a given instance. My ExecStart line now looks like so:
ExecStart=timeout -p 12m /usr/bin/php -f /var/www/nextcloud/cron.php

The 12 minute timeout is very generous on my system as it is a small system. It allows for up to two skipped runs.

I have not done extensive testing, but one or both of these seems to work so far.

out of curiosity: Why don’t you use cronjob?

occ status --help says:

-e, --exit-code        exit with 0 if running in normal mode, 1 when in maintenance mode, 2 when `./occ upgrade` is needed. Does not write any output to STDOUT.

So, this line basically this checks the exit code of the occ status command, and only runs the cronjob if the exit code is 0 which prevents the cron job from running when, for example, Nextcloud is in maintenance mode or an upgrade is pending.

That said, I don’t think it will help much if a background job is actually hanging or otherwise causing problems.

Hmm, I’m not entirely sure about the implications of that, but I’d say it’s more of a nasty workaround than an actual solution.

After all, you’re simply terminating the process after 12 minutes. That obviously helps in the sense that cron.php can be started again afterwards, but it doesn’t really address the underlying issue.

It would probably be better to find out why cron.php is hanging in the first place, or more specifically, which background job started by cron.php is causing the problem.

Maybe occ background-job:history could help pinpoint the issue. You can also list all registered background jobs and run them individually, which might help identify the job that is causing the problem:

 background-job
  background-job:delete                  Remove a background job from database
  background-job:execute                 Execute a single background job manually
  background-job:history                 Show currently running jobs
  background-job:list                    List background jobs
  background-job:running                 Show currently running jobs
  background-job:worker                  Run a background job worker