Blaok / nextcloud-inotifyscan

Automatically scan external changes for Nextcloud local storage.
MIT License
48 stars 15 forks source link

can't use with Univention Corporate Server and nextcloud #9

Closed lirees closed 2 years ago

lirees commented 5 years ago

i'm apologize to write you again but after restart of the ucs test machines the script don't run again, i don't understand that happened i have only i have make simply system restart... so i have do it all from scratch sure to solve but don't works .. i report all the steps

1) install ucs update and nextcloud form umc 2) install inotifywait 3) install nextcloud-inotifyscan 4) create www-data.ini in /etc/nextcloud-inotifyscan/

[DEFAULT]
interval = 1
[Instance1]
occ = occ
user = administrator
docker = www-data:a1e6050215ae
external_storage = yes

i have tried to use root as user and with file name root.ini, the container id is retrieve from the command docker ps

root@server:/etc/nextcloud-inotifyscan# docker ps
CONTAINER ID        IMAGE
COMMAND                  CREATED             STATUS              PORTS
                     NAMES
a1e6050215ae        docker.software-univention.de/nextcloud:15.0.7-0
 "/bin/sh -c /usr/s..."   16 hours ago        Up 15 hours
 0.0.0.0:40000->80/tcp           tender_joliot

5) check that all path are correct

which docker > /usr/bin/docker
which php > /usr/bin/php
which python  > /usr/bin/python
which inotifywait >  /usr/bin/inotifywait

6) test the access to the docker container

docker exec -it 1e6050215ae echo "Hello from container!"
docker exec -it a1e6050215ae sudo -u www-data /var/www/html/occ files:scan
--all
Starting scan for user 1 out of 6 (Administrator)
Starting scan for user 2 out of 6 (dns-server)
Starting scan for user 3 out of 6 (Guest)
Starting scan for user 4 out of 6 (krbtgt)
Starting scan for user 5 out of 6 (nc_admin)
Starting scan for user 6 out of 6 (ucs-sso)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 15      | 24    | 00:00:00     |
+---------+-------+--------------+

... and all works

7) and finally run sudo systemctl enable --now nextcloud-inotifyscan@www-data but if i check the systemctl status the service it's stopped

root@server:/etc/nextcloud-inotifyscan# sudo systemctl status
nextcloud-inotifyscan@www-data
â nextcloud-inotifyscan@www-data.service - Nextcloud inotify scan daemon
for www-data
   Loaded: loaded (/etc/systemd/system/nextcloud-inotifyscan@.service;
enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2019-05-15 06:11:34 CEST;
3min 53s ago
 Main PID: 20301 (code=exited, status=1/FAILURE)

mag 15 06:11:34 server nextcloud-inotifyscan[20301]:   File
"/usr/local/bin/nextcloud-inotifyscan", line 279, in <module>
mag 15 06:11:34 server nextcloud-inotifyscan[20301]:     main()
mag 15 06:11:34 server nextcloud-inotifyscan[20301]:   File
"/usr/local/bin/nextcloud-inotifyscan", line 274, in main
mag 15 06:11:34 server nextcloud-inotifyscan[20301]:     for task in
watch_instances(parse_args()):
mag 15 06:11:34 server nextcloud-inotifyscan[20301]:   File
"/usr/local/bin/nextcloud-inotifyscan", line 148, in watch_instances
mag 15 06:11:34 server nextcloud-inotifyscan[20301]:
 universal_newlines=True).rstrip()
mag 15 06:11:34 server nextcloud-inotifyscan[20301]:   File
"/usr/lib/python2.7/subprocess.py", line 219, in check_output
mag 15 06:11:34 server systemd[1]: nextcloud-inotifyscan@www-data.service:
Main process exited, code=exited, status=1/FAILURE
mag 15 06:11:34 server systemd[1]: nextcloud-inotifyscan@www-data.service:
Unit entered failed state.
mag 15 06:11:34 server systemd[1]: nextcloud-inotifyscan@www-data.service:
Failed with result 'exit-code'.

i'm apologize but it's two day i fight without any result

Thanks

Blaok commented 5 years ago

I think you might need to set occ = /var/www/html/occ in the config because your docker doesn't seem to be working at the nextcloud folder.

If it doesn't work, please check if sudo -uwww-data docker exec -uwww-data a1e6050215ae php occ --version works. This is basically what the script is doing given your config. In the above command, the first www-data is the user running the script, which corresponds to www-data.ini. This user must have the privilege to run docker. The second www-data is the user running php inside the docker, which corresponds to the docker = www-data:a1e6050215ae line in the configuration. This user should be the one running nextcloud in the docker. php is hardcoded in the script so please make it available inside the docker (which is usually not a problem). occ can be configured, as mentioned above.

lirees commented 5 years ago

Thanks for your reply,

i have changed the occ value in ini file and i have add the www-data user into docker group for permit the access to the docker, the command dont' give avy error and retrieve correctly the version of nextcloud

sudo -uwww-data docker exec -uwww-data a1e6050215ae php /var/www/html/occ --version 
Nextcloud 15.0.7

and also the systemctl show that the process is active (running) .. perfect

 sudo systemctl status nextcloud-inotifyscan@www-data
â nextcloud-inotifyscan@www-data.service - Nextcloud inotify scan daemon for www-data
   Loaded: loaded (/etc/systemd/system/nextcloud-inotifyscan@.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-05-16 10:00:47 CEST; 6min ago
 Main PID: 18634 (nextcloud-inoti)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/system-nextcloud\x2dinotifyscan.slice/nextcloud-inotifyscan@www-data.service
           ââ18634 /usr/bin/python /usr/local/bin/nextcloud-inotifyscan --config /etc/nextcloud-inotifyscan/www-data.ini
           ââ18696 inotifywait --event=create,modify,move,delete --exclude=/\. --recursive --quiet --format=%e/%f%w/ --monitor /var/lib/univention-appcenter/apps/nextcloud/data/nextcloud-data/Administrator/files

mag 16 10:00:47 server systemd[1]: Started Nextcloud inotify scan daemon for www-data.
mag 16 10:00:48 server nextcloud-inotifyscan[18634]: INFO - watching /var/lib/univention-appcenter/apps/nextcloud/data/nextcloud-data/Administrator/files <=> /Administrator/files

but i found another little problem .. i dont' know if it concerns you, i try to explain

i have a shared folder on lan mapped as external storage in nextcloud and a sub-folder name myfolder

I hope i explained myself

Thanks

Blaok commented 5 years ago

As far as I know inotify doesn't work on remote filesystems. For external storage, the actual backend storage has to be local for this to work. Are you sure it was inotifyscan that triggered the scan in the first place? To debug this you can take a look of the inotifywait process launched by inotifyscan with something like ps or htop and start a inotifywait process yourself. Then, in another terminal, you can try to do the file operations and see if inotifywait outputs anything.