klemens-u / nextcloud-inotify

When a file is created/changed/deleted in the filesystem (e.g. over Samba) run Nextcloud file scanning for the parent directory efficently. Otherwise the updates would not be recognized by Nextcloud
0 stars 0 forks source link

Detect file system changes for Nextcloud data

The following is a nice and efficent solution to inform Nextcloud about changes to files in the Nextcloud data directory. A common usecase is the integration of SAMBA, so files can be accessed via network shares and Nextcloud.

The solution was tested with Ubuntu 22.04 Server, but should be easy to adapt for other Linux distributions.

Developed for our "cloudBox" solution (https://translate.google.com/translate?sl=de&tl=en&u=https://cloudbox.ull.at/)

Problem

When a file is created/changed/deleted in the filesystem (e.g. over Samba) updates are not recognized by Nextcloud. Running occ files:scan regularly is very I/O intensive and takes a long time, multiple minutes even for medium installation.

Solution

Use Linux inotify to scan only the specific directory where the file change occured.

We'll use watcher.py as tool for that: https://github.com/klemens-u/Watcher-Python3

Setup & Ops

Start / Stop / Debug

Rotate Watcher Logfiles

Bonus: Install SAMBA

...

Share a subdirectory of user1's Nextcloud files with authentification

[files] path = /srv/nextcloud/user1/files/projects writeable = yes browseable = yes valid users = projects force user = www-data force group = www-data

Public Share

[pictures] path = /srv/nextcloud/admin/files/pictures public = yes writeable = yes force user = www-data force group = www-data



- `testparm`
  - Tests SAMBA config
- `service smbd restart`

### Create a "project" user
- `adduser projects`
- `smbpasswd -a projects`
- `passwd --lock projects `
  - disable unix login for security

### Misc
- `pdbedit -L -v`
  - List SAMBA users