Tag: Nextcloud

  • Nextcloud Cron Setup

    Nextcloud Cron Setup

    You may have encountered the following warning after a Nextcloud install or you may even never seen it but Nextcloud need to execute some background tasks regularly to insure it’s good working condition. Some cleanups need to be executed on a daily basis.

    If you don’t know what I’m talking about, check your Nextcloud application settings : Open your Nextcloud instance with a privileged account > click on your icon > Settings > Basic settings.

    You can learn more in the official Nextcloud documentation.

    Nextcloud Background Jobs Tab

    There is 3 different ways of executing these scheduled tasks :

    • AJAX
    • Webcron
    • Cron

    The AJAX is the default one but it’s the less reliable because this technique only execute one task per page reloaded by an user, it requires many visits to be efficient.

    The Webcron can be an good choice depending on your setup, but it rely on an external source to execute your Cron. You can use a service like easyCron to load your http[s]://<domain-of-your-server>/nextcloud/cron.php URL, that will trigger the execution of the jobs.

    The Cron method is, to me, the most reliable, you just have to enter how often you want your background tasks to run. As long your server is running, the task will execute, it’s that simple.


    Setup

    Two ways are gonna be covered, the classic way or the Docker way, depending of your install type.

    Classic installation :

    You just have to set a Cron task, it’s that easy ! To check your active Cron jobs just execute the following command in a terminal.

    crontab -l

    This will list (-l) your active Cron tasks.

    To edit (-e) you Cron file you will need to edit it as the user www-data (The nextcloud user).

    crontab -e -u www-data

    Here you can insert a new line at the end of the document with the following.

    */5  *  *  *  * php -f /var/www/nextcloud/cron.php

    This will trigger the Cronjob execution every 5 Minutes (Time used in the Nextcloud Doc)

    On some systems it might be required to call php-cli instead of php.

    If you want to force the execution of Cronjobs, you can enter the command manually :

    sudo -u www-data php -f /var/www/html/nextcloud/cron.php

    Docker Installation :

    In Docker the idea is pretty munch the same, but the process must be executed in the host system instead of the container itself. By editing the host Crontab file you can specify the container and the user you want to use.

    First we need to identify the Nextcloud container name.

    docker ps

    With this command, you can list every running containers. Find the name of your nextcloud one and get to the next step. In our case the container will be named “Nextcloud“.

    Next, we are gonna try the command manually and check if it’s triggered in the container. In the host terminal type :

    docker exec -u www-data nextcloud php cron.php

    If the background jobs tab now show a green dot after a page refresh, the command is working, we just need to make it run every 5 Minutes.

    Successful Background Jobs Execution 

    On your Docker host system, edit the Cron file by typing :

    crontab -e

    Add the following line at the end to execute it every five minutes :

    */5 * * * * docker exec -u www-data nextcloud php cron.php

    Bonus : Non persistant Cron OS

    Some OS, have non persistant Cron settings after reboot (e.g Unraid), to counter that we can edit the starting script of the OS to insert the Nextcloud Cronjob line after startup.

    In Unraid, the startup script is located under /boot/config/go, by editing this file, we can execute actions after the initial startup.

    nano /boot/config/go

    In the “go” file add the following script at the end :

    # Add the Nexctloud Cron at startupcrontab -l > /tmp/tempecho \ >> /tmp/tempecho "*/5 * * * * docker exec -u www-data nextcloud php cron.php" >> /tmp/tempcrontab /tmp/temp

    This script will backup the preconfigured Cronjobs in a file, add the Nextcloud entry & define this file as the new Cronjob.

  • Fixing Broken Nextcloud – MariaDB 10.X Upgrade

    Fixing Broken Nextcloud – MariaDB 10.X Upgrade

    As a classic HomeLab enjoyer I self-host most of the stuff I use daily. But few days ago while maintaining my Nextcloud instance, I updated Nextcloud & MariaDB to catch up on the latest patches. Unfortunately, my docker install was unable to start properly again and I was greeted by the following error :

    Nextcloud_Error
    The Nextcloud error I encountered

    So I went to check the Nextcloud logs on my docker container with the following command :

    docker logs nextcloud

    I immediately realized that was a database error and not a Nextcloud one, the following messages where present :

    Doctrine\DBAL\Exception\DriverException: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 4047 InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE. Update failed

    From my small knowledge in programming I know one thing, Doctrine is like a link between operations that are queued in the app (Nextcloud in this case) waiting for being written to the database.

    InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED

    If you want a quick fix you can just rollback to a previous version of mariadb (10.5.11) but if you want to know more about this issue, just stick with me for a bit.

    From MariaDB 10.6.0, tables that are of the COMPRESSED row format are read-only by default, the goal here is to deprecate the feature in the future. By setting the innodb_read_only_compressed 3 variable to OFF it make the tables writable.

    read_only_compressed
    read_only_compressed

    However, this is a workaround rather that a solution. Tables must be migrated. Hopefully they should be migrated automatically by Nextcloud in an incoming update soon. It is wise not to touch the table’s definition in order to not break the (hopefully) incoming Nextcloud migration.


    How to fix it ?

    Standard Install

    • Access you MariaDB server
    • Edit the /etc/my.cnf.d/server.cnf file
    • Find the [mysqld] section
    • Add the following statement “innodb_read_only_compressed=OFF”
    • Restart your SQL service

    Docker Install

    If you are running your app in docker container you can add the command in your docker-compose script to be executed at every startup :

    command: # CLI arguments  - "--innodb_read_only_compressed=OFF"