Unraid Docker: Permission problems related to cron job

Hello,
My cronjob does some weird things I cannot seem to find the cause of.
I’m using the latest official docker image and just recently setup nextcloud. So it is a new installation, not update. I’m using it on unraid server.

My docker allocations:

/var/www/html  -  /mnt/user/appdata/nextcloud/html
/var/www/html/custom_apps  -  /mnt/user/appdata/nextcloud/apps
/var/www/html/config  -  /mnt/user/appdata/nextcloud/config
/var/www/html/data  -  /mnt/user/Private/nextcloud/

The cronjob told me to make the data folder permission 0770 so I did so.

I created this cron script:
docker exec --user www-data Nextcloud php /var/www/html/cron.php

When I try to run it this is my error message:

{"reqId":"Dq3FQqFYbSY1NIyRufQZ","level":3,"time":"2024-05-07T06:38:20+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(/var/www/html/data/data_dir_writability_test_6639cc5c3a743.tmp): Failed to open stream: Permission denied at /var/www/html/lib/private/legacy/OC_Util.php#572","userAgent":"--","version":"29.0.0.19","data":{"app":"PHP"}}
Your data directory is invalid.
Ensure there is a file called ".ocdata" in the root of the data directory.

Your data directory is not writable.
Permissions can usually be fixed by giving the web server write access to the root directory. See https://docs.nextcloud.com/server/29/go.php?to=admin-dir_permissions.

{"reqId":"Dq3FQqFYbSY1NIyRufQZ","level":3,"time":"2024-05-07T06:38:20+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(/var/www/html/data/nextcloud.log): Failed to open stream: Permission denied at /var/www/html/lib/private/Log/File.php#82","userAgent":"--","version":"29.0.0.19","data":{"app":"PHP"}}

Nextcloud is running fine, I can access my user folder. Also there is an ocdata file
ksnip_20240507-083924

What is my issue here?

If i get your sceenshot right your …/nextcloud folder is owned by nobody:users which is not right by default. usually 33:33 (www-data:www-data) is the right owner. Permissions should be 750 for folders and 640 for files

I’m not really sure what I’m doing wrong. On my system I created a new user and group called www-data as it was non existent. It was only existing inside the container. Then I chown -c www-data:www-data ./nextcloud
Now the owner of the folder is www-data.
Now if I give any permission other than 777 nextcloud won’t run saying data folder with the .ocdata file is missing. If I run the cron job with this permission setup I have this output

{"reqId":"RG5P0Tsz7qjop0apU71R","level":3,"time":"2024-05-07T12:04:57+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(/var/www/html/data/data_dir_writability_test_663a18e9e6380.tmp): Failed to open stream: Permission denied at /var/www/html/lib/private/legacy/OC_Util.php#572","userAgent":"--","version":"29.0.0.19","data":{"app":"PHP"}}
Your data directory is invalid.
Ensure there is a file called ".ocdata" in the root of the data directory.

Your data directory is not writable.
Permissions can usually be fixed by giving the web server write access to the root directory. See https://docs.nextcloud.com/server/29/go.php?to=admin-dir_permissions.

{"reqId":"RG5P0Tsz7qjop0apU71R","level":3,"time":"2024-05-07T12:04:57+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"fopen(/var/www/html/data/nextcloud.log): Failed to open stream: Permission denied at /var/www/html/lib/private/Log/File.php#82","userAgent":"--","version":"29.0.0.19","data":{"app":"PHP"}}

If I set the permission to 750 as you say nextcloud frontend goes down saying data folder is missing.

My current data folder permission:
ksnip_20240507-142234

user names are not important in *ix system - UID and GID are important. you need 33:33 by default you don’t need a user www-data you need a user with UID 33 - or you need adjust your container user as described the guide above. I can’t tell if unraid is doing some additional voodoo which you have to understand yourself… maybe they adjust container user to be “nobody” - this out of scope of this forum.

there is a lengthy post about cron and unraid Unraid, Nextcloud, and what the hell is a Cron? maybe it helps you to understand your problem but I’m too lazy to follow all the references…

1 Like

It is working now. I have used getent group 33 to check which user has the id 33 and it was sshd.
I have then used chown -R sshd:sshd ./nextcloud on my data folder and now the cronjob is working. But only working with chmod 777 and not with chmod 750 which I still dont understand but whatever. At least I can use nextcloud now.
Thank you

if the last octet controls the access seems unraid is doing some custom stuff as assumed before - I recommend you to familiarize yourself with their apps and maybe ask for support in Unraid forums.