Skip to content

Instantly share code, notes, and snippets.

@checktravis
Last active October 9, 2020 11:10
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 checktravis/08fe31c2d155ca01cc5c078fdc3a816b to your computer and use it in GitHub Desktop.
Save checktravis/08fe31c2d155ca01cc5c078fdc3a816b to your computer and use it in GitHub Desktop.
# This is the mount script I have been using for my crypt drive.
# So far, these settings have been stable enough to use as a library source in Plex.
#
# start/enable this unit passing the remote name ("instance") you want to mount.
# example: sudo systemctl start rc-mount@gcrypt.service #instance is "gcrypt"
# instance needs to be defined in your rclone.conf
#
# Assuming:
# rclone is located at /usr/bin/rclone
#
# modify Enciroment variables in [Service] below
#
[Unit]
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
# this service will create "instance" in $mnt-path, then mount to it
Type=notify
Restart=on-failure
####################################################################################################
### --------- CUSTOMIZE THESE TO YOUR SITUATION ---------------------------------------------- ###
Environment="config=/home/driveuser/.rclone.conf"
# "remote" = whatever is provided after @ when running this template - Ex. "gcrypt"
Environment="remote=%I"
# local path to mount remote
Environment="mntpath=/home/driveuser/rclone/mnt"
# log path (crate or add to existing file ${logfile}/rclone-${remote}-mount.log
Environment="logpath=/home/driveuser/rclonestuff/logs"
# random agent string. best practice is NO SPACES and NO mention of rclone or what your are doing
Environment="useragent=GOOGLEisAWESOME"
####################################################################################################
####################################################################################################
### set user/group below, and use same user/group in ExecStartPre=/bin/chown commands -------- ###
User=driveuser
Group=drivegroup
ExecStartPre=/bin/mkdir -p ${mntpath}/%I
ExecStartPre=/bin/touch ${logpath}/rclone-%I-mount.log
# match user/group defined above in next two ExecStartPre
ExecStartPre=/bin/chown driveuser:drivegroup ${mntpath}/%I
ExecStartPre=/bin/chown driveuser:drivegroup ${logpath}/rclone-%I-mount.log
####################################################################################################
###
### remainder shouldn't need any changes...
ExecStart=/usr/bin/rclone --config=${config} mount ${remote}: ${mntpath}/%I --allow-other --dir-cache-time 1000h --log-file ${logpath}/rclone-%I-mount.log --poll-interval 15s --umask 002 --user-agent ${useragent} --vfs-read-chunk-size 32M --file-perms 0775
ExecReload=/bin/kill -USR1 $MAINPID
ExecStop=/bin/fusermount -uz ${mntpath}/%I
KillMode=mixed
KillSignal=SIGTERM
TimeoutStopSec=5s
[Install]
WantedBy=multi-user.target
#
### start with (example instance: "gcrypt"):
# sudo systemctl start rc-mount@gcrypt.service
### verify
# df -h
### start on boot:
# sudo systemctl enable rc-mount@gcrypt.service
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment