Added environment variable to control startup of RC and setting an optional Post Mount Script which is executed in ExecStartPost of the service.

Joshua Grisham 2021-03-25 17:26:02 +01:00
parent 37dc57fc00
commit 744f73f090

@ -12,8 +12,10 @@ Type=notify
Environment=REMOTE_NAME="%i" Environment=REMOTE_NAME="%i"
Environment=REMOTE_PATH="/" Environment=REMOTE_PATH="/"
Environment=MOUNT_DIR="%h/%i" Environment=MOUNT_DIR="%h/%i"
Environment=POST_MOUNT_SCRIPT=""
Environment=RCLONE_CONF="%h/.config/rclone/rclone.conf" Environment=RCLONE_CONF="%h/.config/rclone/rclone.conf"
Environment=RCLONE_TEMP_DIR="/tmp/rclone/%u/%i" Environment=RCLONE_TEMP_DIR="/tmp/rclone/%u/%i"
Environment=RCLONE_RC_ON="false"
#Default arguments for rclone mount. Can be overridden in the environment file #Default arguments for rclone mount. Can be overridden in the environment file
Environment=RCLONE_MOUNT_ATTR_TIMEOUT="1s" Environment=RCLONE_MOUNT_ATTR_TIMEOUT="1s"
@ -58,6 +60,7 @@ ExecStart=/usr/bin/rclone mount \
#See additional items for access control below for information about the following 2 flags #See additional items for access control below for information about the following 2 flags
# --allow-other \ # --allow-other \
# --default-permissions \ # --default-permissions \
--rc="${RCLONE_RC_ON}" \
--cache-tmp-upload-path="${RCLONE_TEMP_DIR}/upload" \ --cache-tmp-upload-path="${RCLONE_TEMP_DIR}/upload" \
--cache-chunk-path="${RCLONE_TEMP_DIR}/chunks" \ --cache-chunk-path="${RCLONE_TEMP_DIR}/chunks" \
--cache-workers=8 \ --cache-workers=8 \
@ -91,6 +94,9 @@ ExecStart=/usr/bin/rclone mount \
# --volname="${RCLONE_MOUNT_VOLNAME}" # --volname="${RCLONE_MOUNT_VOLNAME}"
"${REMOTE_NAME}:${REMOTE_PATH}" "${MOUNT_DIR}" "${REMOTE_NAME}:${REMOTE_PATH}" "${MOUNT_DIR}"
#Execute Post Mount Script if specified
ExecStartPost=/bin/sh -c "${POST_MOUNT_SCRIPT}"
#Unmount rclone fs #Unmount rclone fs
ExecStop=/bin/fusermount -u "${MOUNT_DIR}" ExecStop=/bin/fusermount -u "${MOUNT_DIR}"
@ -228,6 +234,28 @@ If you wish for your mounts to be auto-mounted when the system starts, and auto-
`loginctl enable-linger <USERNAME>` `loginctl enable-linger <USERNAME>`
## Enable the Remote Control API
You can enable the use of [rclone rc](https://rclone.org/rc/) by setting the environment variable `RCLONE_RC_ON` to `true` in your `.env` file (like mentioned in the examples above).
```
MOUNT_DIR=/mnt/user-dropbox
RCLONE_RC_ON=true
```
## Executing a post-mount Script
You can specify a command or script to be executed after the mount is complete by setting the environment variable `POST_MOUNT_SCRIPT` to a string which represents a command or script file that you wish to be executed. This will be preceded by `/bin/sh -c` and executed in the service's `ExecStartPost` event.
For example, if you wanted to execute `echo Hello world.` after the mount was completed, you would set `POST_MOUNT_SCRIPT="echo Hello world."` in the `.env` file. This would then be executed as `/bin/sh -c "echo Hello world."` during `ExecStartPost`.
A more practical example is to use this post mount script to refresh the VFS directory cache automatically after the mount is created on each startup of the service. This can be achieved like this, for example:
```
MOUNT_DIR=/mnt/user-dropbox
RCLONE_RC_ON=true
RCLONE_MOUNT_VFS_CACHE_MODE=full
POST_MOUNT_SCRIPT="rclone rc vfs/refresh recursive=true"
```
# Continuing improvement # Continuing improvement
I have included "TODO" comments where I see a need for improvement. If anyone has any ideas on how to improve this, that would be great! I have included "TODO" comments where I see a need for improvement. If anyone has any ideas on how to improve this, that would be great!