# Cron does not terminate and need a lot of ram

**URL:** <https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222>\
**Category:** ℹ️ Support\
**Tags:** nc19, cron\
**Created:** [July 14, 2020, 4:40am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222 "2020-07-14T04:40:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 4:40am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/1 "2020-07-14T04:40:43Z")

</div>

Nextcloud version: **19.0.0**  
Operating system and version: **18.04.4.LTS**  
Apache or nginx version: **nginx/1.18.0 (fpm-fcgi)**  
Database: **mysql 10.1.44**  
PHP version: **7.4.8**

> **apps**
>
> ```auto
> Enabled:
> - accessibility: 1.5.0
> - activity: 2.12.0
> - apporder: 0.10.0
> - bruteforcesettings: 1.6.0
> - circles: 0.19.3
> - cloud_federation_api: 1.2.0
> - comments: 1.9.0
> - contactsinteraction: 1.0.0
> - dav: 1.15.0
> - federatedfilesharing: 1.9.0
> - federation: 1.9.0
> - files: 1.14.0
> - files_automatedtagging: 1.9.0
> - files_downloadactivity: 1.8.0
> - files_pdfviewer: 1.8.0
> - files_rightclick: 0.16.0
> - files_sharing: 1.11.0
> - files_trashbin: 1.9.0
> - files_versions: 1.12.0
> - files_videoplayer: 1.8.0
> - flowupload: 1.0.0
> - groupfolders: 6.0.6
> - imageconverter: 1.2.1
> - logreader: 2.4.0
> - lookup_server_connector: 1.7.0
> - nextcloud_announcements: 1.8.0
> - notifications: 2.7.0
> - oauth2: 1.7.0
> - password_policy: 1.9.1
> - photos: 1.1.0
> - privacy: 1.3.0
> - provisioning_api: 1.9.0
> - quota_warning: 1.8.0
> - ransomware_protection: 1.7.0
> - richdocuments: 3.7.3
> - serverinfo: 1.9.0
> - settings: 1.1.0
> - sharebymail: 1.9.0
> - spreed: 9.0.1
> - support: 1.2.1
> - survey_client: 1.7.0
> - systemtags: 1.9.0
> - theming: 1.10.0
> - twofactor_backupcodes: 1.8.0
> - twofactor_totp: 4.1.3
> - twofactor_u2f: 5.1.0
> - updatenotification: 1.9.0
> - user_ldap: 1.9.0
> - viewer: 1.3.0
> - workflowengine: 2.1.0
> Disabled:
> - admin_audit
> - encryption
> - files_external
> - firstrunwizard
> - issuetemplate
> - recommendations
> - socialsharing_email
> - text
> 
> ```

The issue you are facing:  
Hello, everyone,

currently i have the problem that the nextcloud cron is filling 76% of my memory and i can’t figure out why. Could someone help me with this?  
 ![image](https://help.nextcloud.com/uploads/default/original/3X/e/1/e18d727f27741bfb271d168bafa89b416ce82f37.png)

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

Steps to replicate it:

1. Restart Server
2. Wait

The output of your Nextcloud log in **Admin \> Logging** :

```auto
No entries because of the cron

```

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

```auto
<?php
$CONFIG = array (
  'passwordsalt' => ' ***REMOVED SENSITIVE VALUE***',
  'trusted_domains' => 
  array (
    0 => 'mmmbox.mmmgroup.com',
  ),
  'datadirectory' => ' ***REMOVED SENSITIVE VALUE***',
  'skeletondirectory' => ' ***REMOVED SENSITIVE VALUE***',
  'tempdirectory' => '/tmp/nextcloud',
  'dbtype' => 'mysql',
  'version' => '19.0.0.12',
  'dbname' => ' ***REMOVED SENSITIVE VALUE***',
  'dbhost' => ' ***REMOVED SENSITIVE VALUE***',
  'dbtableprefix' => 'oc_',
  'dbuser' => ' ***REMOVED SENSITIVE VALUE***',
  'dbpassword' => ' ***REMOVED SENSITIVE VALUE***',
  'mysql.utf8mb4' => true,
  'installed' => true,
  'loglevel' => 0,
  'logtimezone' => 'Europe/Berlin',
  'logdateformat' => 'd.m.y H:i:s',
  'maintenance' => false,
  'secret' => ' ***REMOVED SENSITIVE VALUE***',
  'ldapIgnoreNamingRules' => false,
  'forcessl' => true,
  'mail_smtpmode' => 'smtp',
  'mail_from_address' => ' ***REMOVED SENSITIVE VALUE***',
  'mail_domain' => ' ***REMOVED SENSITIVE VALUE***',
  'mail_smtphost' => ' ***REMOVED SENSITIVE VALUE***',
  'mail_smtpport' => '25',
  'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
  'ldapUserCleanupInterval' => 51,
  'lost_password_link' => ' ***REMOVED SENSITIVE VALUE***',
  'instanceid' => ' ***REMOVED SENSITIVE VALUE***',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtpname' => '',
  'mail_smtppassword' => '',
  'overwrite.cli.url' => 'https://mmmbox.mmmgroup.com',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),
  'default_language' => 'de',
  'default_locale' => 'de',
  'trashbin_retention_obligation' => 'auto, 60',
  'versions_retention_obligation' => 'auto, 60',
  'theme' => 'mmmbox',
  'simpleSignUpLink' => 'false',
  'activity_expire_days' => '90',
  'default_language' => 'de',
  'default_locale' => 'de',
  'trashbin_retention_obligation' => 'auto, 60',
  'versions_retention_obligation' => 'auto, 60',
  'theme' => 'mmmbox',
  'simpleSignUpLink' => 'false',
  'activity_expire_days' => '90',
);

```

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

```auto
no errors

```

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [July 14, 2020, 5:22am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/2 "2020-07-14T05:22:54Z")

</div>

Please deactive all cron-processes for Nextcloud and then start it manually. Perhaps you find an error:

`sudo -u username /usr/bin/php.7.4 ....`

Test also with the standard php version.

`sudo -u username php ...`

Test also your php7.4 settings.

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 5:35am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/3 "2020-07-14T05:35:28Z")

</div>

thanks for your quick response,

if I start the cron by hand, it runs through without any problems.  
No error message or similar can be detected.

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [July 14, 2020, 6:08am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/4 "2020-07-14T06:08:48Z")

</div>

Perhaps the wrong user or wrong environment variables with CRON. No further idea. Sorry.  
How often do you start the cron job?

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 6:17am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/5 "2020-07-14T06:17:47Z")

</div>

the cron is started every 5 minutes there are no other parameters, everything I have specified for the cron is shown in the screenshot above

the backup does not run at the time the cron hangs and no other task i know of

as user is set the same user I used to run the cron manually

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [July 14, 2020, 6:18am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/6 "2020-07-14T06:18:33Z")

</div>

I think the cron starts to fast.  
Set the cron to every hour for testing.  
Look in your php-settings (7.4 / normal). Please test also the normal php-version in /usr/bin.

`which php`  
`php --version`

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 6:52am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/7 "2020-07-14T06:52:58Z")

</div>

I don’t know what you mean by normal.  
I have installed another php 7.0 because of a relatively old application. With the path information I want to prevent that nextcloud is running with it.

i just followed the instructions, there are also 5 minutes  
[https://docs.nextcloud.com/server/latest/admin\_manual/configuration\_server/background\_jobs\_configuration.html?highlight=cron#cron](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/background_jobs_configuration.html?highlight=cron#cron)

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [July 14, 2020, 7:08am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/8 "2020-07-14T07:08:06Z")

</div>

Yes. But if you use cron every 5 minutes it does not work because it runs multiple because of the long time of execution.

But perhaps it is a problem with your old operation system. With Ubuntu 20.04 LTS or Debian Buster 10 you get a newer php-version than php 7.0 . Which operation system is installed?

php 7.0 and Ubuntu:  
[https://packages.ubuntu.com/de/xenial/php](https://packages.ubuntu.com/de/xenial/php)  
This is Ubuntu 16.04 LTS and very old.

php 7.0 and Debian:  
[https://packages.debian.org/de/stretch/php](https://packages.debian.org/de/stretch/php)  
This is Debian Stretch and also a little bit old.

Both systems are supported but perhaps not a good solution for nextcloud.  
You must use for running nextcloud a php-version from another source than the normal distribution.

> [@Tealk144](#):
>
> Operating system and version: **18.04.4.LTS**

[https://packages.ubuntu.com/de/bionic/php](https://packages.ubuntu.com/de/bionic/php)  
uses php 7.2

Perhaps you can dist-upgrade to Ubuntu 20.04 LTS

---

<div class="post-metadata">

**Author:** ![tflidd](https://help.nextcloud.com/letter_avatar/tflidd/32/5_5575768a8748004e209b776fc1b2916d.png) [@tflidd](https://help.nextcloud.com/u/tflidd)\
**Post date:** [July 14, 2020, 7:52am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/9 "2020-07-14T07:52:56Z")

</div>

In your database you have a table `oc_jobs` or `jobs`. This is a list of all jobs executed during a cronjob. There is even a column with execution duration.

With this list you can perhaps crosscheck with the apps installed if everything is working as supposed. From you apps, there is stuff like `imageconverter` which could create a lot of load on the system.

> [@Tealk144](#):
>
> if I start the cron by hand, it runs through without any problems.  
> No error message or similar can be detected.

That is great, and how long took the run?  
The 5 minute cycle was changed recently, before it was about 15 minutes. Drawback of longer cycles are that notification mails will be sent with a larger delay. Normally the cronjob creates a lockfile, so there shouldn’t be any overlap (the new process makes sure the old one finished).  
if everything takes long, you might take a look into your database caching settings.

If you have redis, I’d use it as file-locking cache as well that takes away load from the normal database.

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 8:12am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/10 "2020-07-14T08:12:10Z")

</div>

since I have installed php 7.4, should this not be a problem for the time I think?

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 8:21am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/11 "2020-07-14T08:21:55Z")

</div>

this execution duration is given in seconds? then it would be 86 seconds in total

so according to the github page of the imageconverter this is only done by hand

> **[major-mayer/imageconverter](https://github.com/major-mayer/imageconverter)**
>
> A simple Nextcloud app to convert HEIC/ HEIF images to JPEG - major-mayer/imageconverter

  
we have some iphone users, so I installed this.

I have now done it 3 times by hand and it takes maximum 2 minutes.

thanks for the tip with the redis filelock, have it set up now  
[https://docs.nextcloud.com/server/latest/admin\_manual/configuration\_server/caching\_configuration.html?highlight=file%20lock%20redis#id2](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html?highlight=file%20lock%20redis#id2)

since the changeover the cronjob also takes less than one minute

---

<div class="post-metadata">

**Author:** ![tflidd](https://help.nextcloud.com/letter_avatar/tflidd/32/5_5575768a8748004e209b776fc1b2916d.png) [@tflidd](https://help.nextcloud.com/u/tflidd)\
**Post date:** [July 14, 2020, 9:33am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/12 "2020-07-14T09:33:04Z")

</div>

Which task is taking most of the time?

With the reduction, did the memory consumption decrease as well?

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 9:42am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/13 "2020-07-14T09:42:58Z")

</div>

i can’t say yet, because the cron seems to hang only 2 times a day

---

<div class="post-metadata">

**Author:** ![tflidd](https://help.nextcloud.com/letter_avatar/tflidd/32/5_5575768a8748004e209b776fc1b2916d.png) [@tflidd](https://help.nextcloud.com/u/tflidd)\
**Post date:** [July 14, 2020, 9:46am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/14 "2020-07-14T09:46:50Z")

</div>

then it’s just a matter of time. Don’t forget to dump the jobs-table so you can track this issue. I’m not sure about the logs (perhaps needs to increase log level), perhaps there it’s mentioned which job is started, so in case of a crash you just need to check which one was started last.

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 9:57am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/15 "2020-07-14T09:57:53Z")

</div>

These are the 3 biggest jobs, then come 10 or so with an execution time of 1

```
OCA\Activity\BackgroundJob\ExpireActivities 16
OCA\Files_Versions\BackgroundJob\ExpireVersions 15
OCA\Files\BackgroundJob\ScanFiles 15
```

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 14, 2020, 9:58am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/16 "2020-07-14T09:58:30Z")

</div>

> [@tflidd](#):
>
> then it’s just a matter of time. Don’t forget to dump the jobs-table so you can track this issue. I’m not sure about the logs (perhaps needs to increase log level), perhaps there it’s mentioned which job is started, so in case of a crash you just need to check which one was started last.

so I can just empty the oc\_jobs?

---

<div class="post-metadata">

**Author:** ![Chris\_Aldred](https://help.nextcloud.com/user_avatar/help.nextcloud.com/chris_aldred/32/27062_2.png) [@Chris\_Aldred](https://help.nextcloud.com/u/Chris_Aldred)\
**Post date:** [July 14, 2020, 11:29am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/17 "2020-07-14T11:29:00Z")

</div>

I am having this exact problem, I have ensured the php config has been done correctly. This has only started after I have moved to nextcloud 19, could this be an issue with php7.4 ?

Nextcloud version: **19.0.0**  
Operating system and version: **20.04 LTS**  
Apache or nginx version: **nginx/1.18.0 (fpm-fcgi)**  
Database: **mysql 10.1.44**  
PHP version: **7.4.8**

---

<div class="post-metadata">

**Author:** ![tflidd](https://help.nextcloud.com/letter_avatar/tflidd/32/5_5575768a8748004e209b776fc1b2916d.png) [@tflidd](https://help.nextcloud.com/u/tflidd)\
**Post date:** [July 14, 2020, 6:01pm UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/18 "2020-07-14T18:01:52Z")

</div>

> [@Tealk144](#):
>
> so I can just empty the oc\_jobs?

No just backup the table after each run to see how long it took. Don’t empty the table, it’s needed.

---

<div class="post-metadata">

**Author:** ![Tealk144](https://help.nextcloud.com/user_avatar/help.nextcloud.com/tealk144/32/10676_2.png) [@Tealk144](https://help.nextcloud.com/u/Tealk144)\
**Post date:** [July 15, 2020, 4:14am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/19 "2020-07-15T04:14:47Z")

</div>

so i couldn’t see any difference except for the new timestamps, i started an excerpt here.

The problem is that the cron gets stuck at night and I would rather sleep than wait for the cron 😕

 ![image](https://help.nextcloud.com/uploads/default/original/3X/e/f/ef7046ced32766147ed6876dd50a87af003ccc3d.png)

but it always seems to get stuck at the same time; once at 23:30 and at 5:30(CEST)

but I have to agree @Chris_Aldred , I’ve only had this problem since Nextcloud 19  
Whereby only on the Ubuntu system, I manage another one on Debian and there it does not occur, the configuration is almost identical

---

<div class="post-metadata">

**Author:** ![tflidd](https://help.nextcloud.com/letter_avatar/tflidd/32/5_5575768a8748004e209b776fc1b2916d.png) [@tflidd](https://help.nextcloud.com/u/tflidd)\
**Post date:** [July 23, 2020, 9:11am UTC](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222/20 "2020-07-23T09:11:11Z")

</div>

> [@Tealk144](#):
>
> than wait for the cron

You can run a cron afterwards to query the values from the database. Also the logs might give hints 😉

> [@Tealk144](#):
>
> once at 23:30 and at 5:30(CEST)

I am not sure if all the jobs do something at each run. Like this, I’d think that these are some daily routines, not sure like for the trashbin and stuff like that. But I don’t know enough to tell you which has changed for NC 19. Perhaps change the run time a bit, perhaps on your ubuntu system it collides with a different cronjob.

[Next page](https://help.nextcloud.com/t/cron-does-not-terminate-and-need-a-lot-of-ram/87222.md?page=2)
