Last active
June 4, 2019 10:13
-
-
Save deeuu/8a450bb8d3225d1eaa2ac34e52ac9bfe to your computer and use it in GitHub Desktop.
Script to create a systemd service for mounting an rclone remote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remote = $ARG1 | |
mount_point = f'/mnt/{remote}' | |
print(f'Creating mount point for user `{$USER}`, (may require root permissions)') | |
sudo mkdir -p @(mount_point) | |
sudo chown $USER @(mount_point) | |
log = f'/tmp/rclone-mount-{remote}.log' | |
config = f'''[Unit] | |
Description=Rclone mount ({remote}) | |
AssertPathIsDirectory={mount_point} | |
Wants=network-online.target | |
After=network-online.target | |
[Service] | |
Type=simple | |
ExecStart=/usr/bin/rclone mount \\ | |
{$ARG1}:/ {mount_point} \\ | |
--vfs-cache-mode full \\ | |
--cache-dir %h/.cache \\ | |
--vfs-cache-max-age 8h \\ | |
--log-level INFO \\ | |
--log-file {log} | |
ExecStop=/bin/fusermount -uz {mount_point} | |
Restart=always | |
RestartSec=10 | |
[Install] | |
WantedBy=network-online.target''' | |
fn = f'rclone-mount-{remote}.service' | |
echo @(config) > @(fn) | |
print(f'Created service file {fn}') | |
print(f'Rclone log will be stored at {log}') | |
print('Cache stored at ~/.cache') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.