Prevent writing in directory when Rclone mount is offline in Linux

Is there a way to disable writes to a directory until the RCLONE is properly mounted under Linux?
My program does not know or care if RCLONE is mounted and will just write into the directory which in this case is the local disc.

Now Rclone service is started errors because there is stuff in the said directory. The option allow non empty is a problem because of conflicting files i assume?

Scenario:
Proxmox server is coming up where directory /mnt/mrplex is entered as store. Proxmox likes to have its own file structure and happily writes it. A few seconds later systemd is starting mrplex.service and errors out because the directory is not empty. To proceed I remove all contents written by Proxmox in the /mnt/mrplex directory and restart the service. Everything is working until the rclone mount is offline upon which point i have todo the same again.

//
DEBIAN buster
systemd mounts an encrypted Gdrive Folder to directory /mnt/mrplex

hello,

this is the goto systemd script in the forum, from a fellow rcloner.
https://github.com/animosity22/homescripts/blob/master/systemd/rclone.service

and this is a wiki
https://github.com/rclone/rclone/wiki/Systemd-rclone-mount

is that is not helpful, then post the systemd service file

hey thanks for your reply. my systemd looks very similar to the one you posted.
But i dont see how that is solving my problem :confused: dont get me wrong i am able to succesfully mount with rclone. But in the time that it is not mounted i want no other program to be able to write into the directory.

[Unit]
Description=RClone Service
Wants=network-online.target
After=network-online.target

[Service]
Type=notify
#Environment=RCLONE_CONFIG=/root/.config/rclone/rclone.conf
RestartSec=5
KillMode=none

ExecStart=/usr/bin/rclone mount mrplexcrypt: /mnt/mrplex
--allow-other
--dir-cache-time 1440m
--log-level INFO
--log-file /var/log/rclone.log
--poll-interval 15s
--umask 002
--user-agent itstheroot1
--cache-dir=/cache
--vfs-cache-max-size 40G
--vfs-cache-mode writes
--vfs-cache-max-age 336h
--vfs-read-chunk-size-limit=off
--vfs-read-chunk-size=128M
--drive-use-trash
--buffer-size 1024M
--fast-list
--tpslimit 10
--bwlimit 85M

ExecStop=/bin/fusermount -uz /mnt/mrplex
Restart=always
User=root
Group=root

[Install]
WantedBy=multi-user.target

well, now that you posted the systemd file and tried the simple stuff.

we have linux/systemd experts and hopefully one will stop by soon.

If proxmox is started via a systemd unit (e.g. proxmox.service) then you could create a local config for it in /etc/system/proxmox.service.d/local.conf (make sure the ".d" name matches the service file name).

In it put the lines

[Unit]
RequiresMountsFor=/mnt/mrplex

Now proxmox shouldn't(!!) start until the mount has completed.

(At least that's the directory for CentOS 7; I assume Debian puts it in the same place!)

In my case (non-rclone related) I need xinetd to start after a specific NFS mount has completed so I have

% cat /etc/systemd/system/xinetd.service.d/local.conf 
[Unit]
RequiresMountsFor=/FastData

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.