Cron Jobs fail with no response. Errors in log. Can't find source of problems

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

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:

Nextcloud version (eg, 12.0.2): 13.0.2
Operating system and version (eg, Ubuntu 17.04): Linux 3.10.0-714.10.2.lve1.4.79.el7.x86_64
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.33
PHP version (eg, 7.1): 7.2

The issue you are facing:
After installing NextCloud, changing the background job method to Webcron or Cron and running the cron job results in no response. The settings panel warns that the jobs are not being run and there are errors in the log.

If I run the Webcron using a browser I recieve the following response: status: “success”
The Cron job is set to email me a response, but when I run the command below it doesn’t respond with anything probably meaning that the cron job neither succeeded or failed when called, but failed somewhere else.

I had an installation of OwnCloud before switching to NextCloud, I was able to successfully run the OwnCloud Cron job when it was installed.

Is this the first time you’ve seen this error? (Y/N): Yes

Steps to replicate it:

  1. Install NectCloud 13.0.2
  2. Create Cron Job in cPanel: */5 * * * * /usr/bin/php -f /home/{path}/cron.php
  3. Set background job method to Cron

The output of your Nextcloud log in Admin > Logging:

Error	PHP	Undefined index: SCRIPT_FILENAME at /home/chillsti/public_html/cloud/lib/base.php#144
Fatal	cron	Undefined index: SERVER_PROTOCOL	
Error	base	ErrorException: session_name(): Cannot change session name when headers already sent	
Error	PHP	ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /home/chillsti/public_html/cloud/lib/base.php#424
Error	PHP	ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /home/chillsti/public_html/cloud/lib/base.php#420

Repeat each time the Cron is run

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'nope',
  'passwordsalt' => 'supernope',
  'secret' => 'ultranope',
  'trusted_domains' => 
  array (
    0 => 'chillstice.com',
    1 => 'cloud.chillstice.com',
  ),
  'datadirectory' => '/home/chillsti/public_html/cloud/data',
  'overwrite.cli.url' => 'https://cloud.chillstice.com',
  'htaccess.RewriteBase' => '/',
  'dbtype' => 'mysql',
  'version' => '13.0.2.1',
  'dbname' => 'nope',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nope',
  'dbpassword' => 'noooope',
  'installed' => true,
  'filelocking.enabled' => true,
  'mail_smtpmode' => 'php',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpsecure' => 'ssl',
  'mail_from_address' => 'cloud',
  'mail_domain' => 'chillstice.com',
  'maintenance' => false,
  'htaccess.IgnoreFrontController' => true,
  'skeletondirectory' => 'default-files',
);

The output of your Apache/nginx/system log in /var/log/____:

The folder is empty (shared hosting)

Hi,

For which user did you create this cron job? Which user is your web server running with?

I’m pretty sure it’s using chillsti when running the Cron command through cPanel. I can ssh in using chillsti and manually run the command, but I don’t get any response in console. Manually running it also causes the errors.

I was hoping you answer my question for the user the web server is running with.
Anyway, could you try to the run the following commands and provide the output?

ps -ef | grep apache | grep -v | grep -v root | head -1 | awk '{ print $1}'

sudo -u `ps -ef | grep apache | grep -v | grep -v root | head -1 | awk '{ print $1}'` /usr/bin/php -f /home/chillsti/public_html/cloud/cron.php

After executing the last command, do you still see the error message?

Nonetheless, the cron job needs to be defined for the web server user. Example:
crontab -e -u www-data

EDIT: as j-ed wrote, I was missing an argument. Sorry! The commands were intended like he correctly wrote. Thanks @j-ed!

I tried running the commands using ssh, but I think it’s expecting different syntax. Should I be running the commands using a different console? Could shared hosting be preventing me from running the commands?

Running the commands yields the following output:

Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.

Also, I’m not familiar with running Cron jobs with crontab, how would I properly format the full Cron job instruction?

Thanks for working with me, please excuse my unfamiliarity with Cron jobs.

@Chillstice

ps -ef | grep apache | grep -v grep | grep -v root | head -1 | awk '{ print $1}'

sudo -u `ps -ef | grep apache | grep -v grep | grep -v root | head -1 | awk '{ print $1}'` /usr/bin/php -f /home/chillsti/public_html/cloud/cron.php

The used xommand syntax isn’t specific at all and should work on any Linux server, with one single correction. I think there is an argument missing after the second grep command. Please try the commands I posted above.

1 Like

I was able to run the commands, but there’s no output. I tried switching over to cron to test it and I’m still getting the same errors in the log.

Error	PHP	Undefined index: SCRIPT_FILENAME at /home/chillsti/public_html/cloud/lib/base.php#144
Fatal	cron	Undefined index: SERVER_PROTOCOL
Error	base	ErrorException: session_name(): Cannot change session name when headers already sent
Error	PHP	ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /home/chillsti/public_html/cloud/lib/base.php#424
Error	PHP	ini_set(): Headers already sent. You cannot change the session module's ini settings at this time at /home/chillsti/public_html/cloud/lib/base.php#420

Damn I hate shared hosting. I never know what the actual limitations are.
Might be possible of course that your shared hoster doesn’t allow cron jobs and doesn’t provide direct access to the web server (user).

Okay, one last command:
ps -ef | grep -i apache

Please provide the output if there is any. If not: I suggest you ask your hoster if and how you can create cron jobs for your web server user. I suggest to ask for workarounds as well. If your hoster provides the service he should also support it :wink: I mean he knows the system much better than we do.

No output.

Strange, because I was able to use Cron jobs successfully with vanilla OwnCloud on the same machine before I switched to the NextCloud installation.

I’ll contact InterServer about it and see what they have to say.

I asked InterServer and they said:
"It seems to be an issue with /home/chillsti/public_html/cloud/lib/base.php . Could you please get this file checked by a developer? "

Can you please try to run the following command

ps -ef | grep -i httpd

instead of the previously mentioned one.

1 Like

No output
This is all I see:
image

Please check out the webcron https://www.easycron.com. I found it very easy to set up cronjob and supports multiple configurations(e.g. execution logs, email notifications, run time predictions ).

2 Likes

OMG thank you. This appears to be working flawlessly, the errors are gone and it’s reporting that the cron job is being run.

I’m surprised that the webcron version is running without errors, but running the cron job through cPanel breaks everything.