Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@deeuu
Last active June 4, 2019 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeuu/8a450bb8d3225d1eaa2ac34e52ac9bfe to your computer and use it in GitHub Desktop.
Save deeuu/8a450bb8d3225d1eaa2ac34e52ac9bfe to your computer and use it in GitHub Desktop.
Script to create a systemd service for mounting an rclone remote
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')
@deeuu
Copy link
Author

deeuu commented May 31, 2019

  • This is not optimised for media streaming
  • Now using full cache mode for storing files on disk up to 8 hours (suitable for work-based remotes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment