Skip to content

fix: run occ by absolute path when cron.php is called from the CLI - #41895

Open
openefaadmin wants to merge 1 commit into
owncloud:masterfrom
openefaadmin:fix/cron-occ-absolute-path
Open

openefaadmin wants to merge 1 commit into
owncloud:masterfrom
openefaadmin:fix/cron-occ-absolute-path

Conversation

@openefaadmin

Copy link
Copy Markdown

cron.php's CLI fallback executed ./occ system:cron, which resolves against
the caller's working directory. Cron runs commands from the user's home, so a
crontab line like php -f /var/www/owncloud/cron.php printed the hint and
then failed with sh: 1: ./occ: not found - background jobs silently never
ran. Use DIR . '/occ' and the running PHP_BINARY instead, both escaped.

How this was tested

From /tmp: php /path/to/owncloud/cron.php printed sh: 1: ./occ: not found and core/lastcron stayed unset; with the fix the background jobs ran and lastcron was set.

A changelog entry is included in changelog/unreleased/; it links pull/TBD and can be renamed to the PR number.

@openefaadmin
openefaadmin requested a review from a team as a code owner October 7, 2026 02:43
@CLAassistant

CLAassistant commented Oct 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

cron.php's CLI fallback executed `./occ system:cron`, which resolves against
the caller's working directory. Cron runs commands from the user's home, so a
crontab line like `php -f /var/www/owncloud/cron.php` printed the hint and
then failed with `sh: 1: ./occ: not found` - background jobs silently never
ran. Use __DIR__ . '/occ' and the running PHP_BINARY instead, both escaped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Scott Barbour <[email protected]>
@openefaadmin
openefaadmin force-pushed the fix/cron-occ-absolute-path branch from 64a4719 to ebc3d1a Compare October 7, 2026 17:05

@oc-tmueller oc-tmueller left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the absolute path is the right fix. While we're touching these lines, two related problems keep the silent-failure case from being fully fixed:

  1. The exit code is lost. \system() returns false only when the shell can't start at all. When occ system:cron runs and exits non-zero (127 for occ not found, 1 for not installed, maintenance mode, or a config.php owner mismatch), system() returns the last line of output. So $return === false doesn't fire and cron.php still exits 0, which means cron and monitoring never see the failure.
  2. The hint still prints ./occ system:cron, the relative form this PR shows fails outside the server root.

Suggested:

$occ = \escapeshellarg(PHP_BINARY) . ' ' . \escapeshellarg(__DIR__ . '/occ');
echo 'Please use ' . __DIR__ . '/occ system:cron' . PHP_EOL;
\system("$occ system:cron", $exitCode);
// in case of an error while cron execution we exit with error code as well
if ($exitCode !== 0) {
	exit($exitCode);
}

Longer term we'd like to retire the CLI side of cron.php altogether. That is tracked in #41914, so this PR can stay a small, backportable fix.

@oc-tmueller oc-tmueller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as commented - thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants