Suddenly lost connection and can't connect again

My nextcloudpi on docker (raspberry pi4) worked well until a few hours ago (i thought). I used the desktop client to sync a folder, backed it up on the server and hat no issues so far. I could upload files from my phone with no problem as well and acces them in the synced folder.
When opening the browser interface on another computer and trying to download a folder, it came an error message which i can not reproduce, because now nothing is working…
However, I looked up the error message and found some things about permissions, so I typed the command:
sudo chown -R www-data:www-data /media/storage/nextcloud

to make sure everything is correctly set up. This is the folder where the data from the container is mapped to.
I restarted the container and nothing worked after that. My desktop client does not connect

500 Internal Server Error

nor can i open up the web browser of nextcloud or nextcloudpi settings.
I rebooted the raspberry and restarted the container a few times, giving me the following docker container log:

Starting PHP-fpm
Starting Apache
Starting mariaDB
2020-04-21 7:50:03 0 [Note] mysqld (mysqld 10.3.22-MariaDB-0+deb10u1) starting as process 187

sudo ls -l /media/storage/nextcloud

results in

drwx—r-x 2 www-data www-data 4096 Apr 21 05:00 backup
drwx—r-x 3 www-data www-data 4096 Apr 8 14:37 bin
drwx—r-x 5 www-data www-data 4096 Apr 21 09:50 database
drwx—r-x 9 www-data www-data 4096 Apr 8 13:36 etc
drwx—r-x 3 www-data www-data 4096 Apr 6 08:28 ncp
drwx—r-x 16 www-data www-data 4096 Apr 8 14:29 nextcloud

Am i missing something?

  1. Why is the whole thing blown up now?
  2. How can i fix it without going through the whole install process again and restore everything?
    3 How can I avoid this to happen again?
  3. What caused the first problem (not being able to download files from the web browser interface?

Thanks in advance for any hints on how to solve these problems!

You messed it up there, imho.
My data storage looks like this

sudo ls -lh /path/to/ncdata
total 0
drwxr-xr-x 1 root root 534 Dec 21 04:40 bin
drwxr-xr-x 1 systemd-network systemd-timesync 318 Mar 6 16:40 database
drwxr-xr-x 1 root root 160 Mar 6 16:28 etc
drwxr-xr-x 1 root www-data 1,2K Mar 6 16:32 ncp
drwxr-x— 1 www-data www-data 420 Mar 6 16:28 nextcloud

drwxr-xr-x gives the owner all folder permissions, if i didn’t get this wrong.
I chmod the permissions to the following
sudo chmod 755 /media/storage/nextcloud/*

drwxr-xr-x 2 www-data www-data 4096 Apr 21 05:00 backup
drwxr-xr-x 3 www-data www-data 4096 Apr 8 14:37 bin
drwxr-xr-x 5 www-data www-data 4096 Apr 21 11:13 database
drwxr-xr-x 9 www-data www-data 4096 Apr 8 13:36 etc
drwxr-xr-x 3 www-data www-data 4096 Apr 6 08:28 ncp
drwxr-xr-x 16 www-data www-data 4096 Apr 8 14:29 nextcloud

still notworking.
i don’t think, that root needs to own some folders to make ncp work, or am I wrong on this?
Even though also changed the owner, with the same result.

Any other ideas?

Did you run NC under docker container? Then user should be that being used by docker, not www-data.

If you execute:

ps -aux | grep docker
docker1    3702  0.2  1.9 2194492 276664 ?      Ssl  Apr17  13:28 blabla

I suppose you will see a lot of services runned by user docker and root. Then check docker1 user (from above) Group:

groups docker1
docker1 : docker someothergroup

You see that user docker1 belongs to the group docker and someothergroup. Now you have to set permissions to NC folder as for docker, e.g. for this example:

sudo chown -R docker1:docker /media/storage/nextcloud

docker is run by root in my case.
I had some permission problems before
(Backup error with NCP docker)

and solved it with
sudo chown -R "www-data:www-data" /media/storage/nextcloud

so I am wondering whats going on…

I do not know your docker setup. Do you have any configuration for docker environment? You could set user there, then it should be synced with permissions.

sudo cat /etc/environment

I have no special setup for docker. I run it as root on my raspberry and i am not quite sure what you mean with setting the environment. Can you explain it a bit further?

All folders are now owned by user www-data and group www-data.
In my dockersetup the owner and group of the database folder are: systemd-resolve:systemd-network .

Its hard to tell what it should be from this point of view, what I normally would do in this case is just start a new docker container with different names, volumes and ports and then compare the permissions.

I recreated the container and restored my data from a backup file.
I created the “backup” folder and

sudo chown -R www-data:www-data /media/storage/nextcloud/backup

sudo ls -l /media/storage/nextcloud

i get

drwxr-xr-x  2 www-data        www-data         4096 Apr 22 08:48 backup
drwxr-xr-x  3 root            root             4096 Apr  6 08:22 bin
drwxr-xr-x  5 systemd-network systemd-timesync 4096 Apr 22 08:46 database
drwxr-xr-x  9 root            root             4096 Apr 22 08:54 etc
drwxr-xr-x  3 root            www-data         4096 Apr  6 08:28 ncp
drwxr-x--- 14 www-data        www-data         4096 Apr  6 07:42 nextcloud

everything seems to work just fine. I can upload , download, restore and backup.
I guess its solved now.

Lesson learned:
Don’t chown all folders blindly. Check their original permissions before!

Thanks for your support!

1 Like