Rclone autostart script

I have successfully tested mount my google drive with rclone, but I’d like it to auto-mount every time i restart.

Latest OSMC running on a Vero 4k +

I tried to follow these instructions:

cd /home/osmc
mkdir scripts
cd scripts
nano mountscript.sh
chmod +x mountscript.sh

mountscript.sh looks like this

$!/bin/bash

rclone mount crypt:media /home/osmc/gsuite

Then I did:

sudo nano /lib/systemd/system/test.service

and typed in:

[Unit]
Description=rclone_mount
After=network.target

[Service]
ExecStart=/home/osmc/scripts/mountscript.sh

[Install]
WantedBy=multi-user.target

and at last:

sudo systemctl daemon-reload
sudo systemctl enable test.service
sudo systemctl start test.service

But it does not mount when I restart. (This is my first time trying such a script as this)

Any ideas ?

EDIT: Retried the mount via SSH, but when I browse the folders it seems to lock or freeze the box. Still able to access it with SSH.

Hi,

Does: sudo systemctl start test.service mount it?

Thanks Tom.

Hi, thanks for the reply. I did not get an error message the first time I tried it, but now I get:

Failed to start test.service: Unit test.service has a bad unit file setting.

See system logs and ‘systemctl status test.service’ for details.

I haven’t found out how to see the system logs yet.

Hi,

Whats the output of:

systemctl status test.service

Thanks Tom.

Hi, the output is:

osmc@osmc:~$ systemctl status test.service

  • test.service - rclone_mount
    Loaded: loaded (/lib/systemd/system/test.service; enabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Fri 2021-04-30 14:17:03 CEST; 13min ago
    Process: 376 ExecStart=/home/osmc/scripts/mountscript.sh (code=exited, status=203/EXEC)
    Main PID: 376 (code=exited, status=203/EXEC)

Apr 30 14:17:03 osmc systemd[1]: Started rclone_mount.
Apr 30 14:17:03 osmc systemd[1]: test.service: Main process exited, code=exited, status=203/EXEC
Apr 30 14:17:03 osmc systemd[1]: test.service: Failed with result ‘exit-code’.

I made a post in the rclone forums as well, and after some posts we found out I have an old version of rclone.

I installed using:

sudo apt-get install rclone

and got version 1.45 (Newest is 1.55.1)

tried to install it the correct way, using:

curl https://rclone.org/install.sh | sudo bash

osmc@osmc:~$ curl https://rclone.org/install.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4491 100 4491 0 0 11604 0 --:–:-- --:–:-- --:–:-- 11574
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15 100 15 0 0 56 0 --:–:-- --:–:-- --:–:-- 56
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12.6M 100 12.6M 0 0 14.1M 0 --:–:-- --:–:-- --:–:-- 14.1M
unzip: invalid option – ‘a’
BusyBox v1.30.1 (Debian 1:1.30.1-4) multi-call binary.

Usage: unzip [-lnojpq] FILE[.zip] [FILE]… [-x FILE…] [-d DIR]

Extract FILEs from ZIP archive

-l List contents (with -q for short form)
-n Never overwrite files (default: ask)
-o Overwrite
-j Do not restore paths
-p Print to stdout
-q Quiet
-x FILE Exclude FILEs
-d DIR Extract into DIR
osmc@osmc:~$ rclone version
rclone v1.45

  • os/arch: linux/arm
  • go version: go1.11.6

Should be #!/bin/bash

Not critical but better to use the full path for rclone.

To get it to start after the network is up, use:

After=network-online.target
Wants=network-online.target

and enable connman-wait-for-network.service

1 Like

I got some help at the rclone-forum, somebody posted their script, and I just tried to edit it so it would suit me.

I did sudo nano /lib/systemd/system/rclone.service

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

[Service]
Type=notify
Environment=RCLONE_CONFIG=/home/osmc/.config/rclone/rclone.conf
KillMode=none
RestartSec=5
*ExecStart=/usr/bin/rclone mount crypt:media /home/osmc/gsuite *
# This is for allowing users other than the user running rclone access to the mount
*–allow-other *
# Google Drive is a polling remote so this value can be set very high and any changes are detected via polling.
*–dir-cache-time 1000h *
# To log to syslog as well
*–syslog *
# I reduce the poll internval down to 15 seconds as this makes changes appear fast the API quotas per day are huge
*–poll-interval 15s *
# This is setting the file permission on the mount to user and group have the same access and other can read
*–umask 002 *
# Please set this to your own value below
*–user-agent randomappname102 *
# This sets up the remote control daemon so you can issue rc commands locally
*–rc *
# This is the default port it runs on
*–rc-addr :5572 *
# no-auth is used as no one else uses my server and it is not a shared seedbox
*–rc-no-auth *
# The local disk used for caching
*–cache-dir=/cache *
# This is used for caching files to local disk for streaming
*–vfs-cache-mode full *
# This limits the cache size to the value below
*–vfs-cache-max-size 750G *
# This adds a little buffer for read ahead
*–vfs-read-ahead 256M *
# This limits the age in the cache if the size is reached and it removes the oldest files first
*–vfs-cache-max-age 1000h *
# This sets a per file bandwidth control and I limit this to a little bigger than my largest bitrate I’d want to play
–bwlimit-file 16M
ExecStop=/bin/fusermount -uz /home/osmc/gsuite
ExecStartPost=/usr/bin/rclone rc vfs/refresh recursive=true --rc-addr 127.0.0.1:5572 _async=true
Restart=on-failure
User=osmc
Group=osmc

[Install]
WantedBy=multi-user.target

Did

osmc@osmc:~$ sudo systemctl daemon-reload

osmc@osmc:~$ sudo systemctl enable rclone.service

osmc@osmc:~$ sudo systemctl start rclone.service

I got an error:

Job for rclone.service failed because the control process exited with error code.

See “systemctl status rclone.service” and “journalctl -xe” for details.

osmc@osmc:~$ systemctl status rclone.service

  • rclone.service - RClone Service

Loaded: loaded (/lib/systemd/system/rclone.service; enabled; vendor preset: enabled)

Active: activating (auto-restart) (Result: exit-code) since Sat 2021-05-01 11:12:01 CEST; 899ms ago

Process: 5040 ExecStart=/usr/bin/rclone mount crypt:media /home/osmc/gsuite --allow-other --dir-cache-time 1000h --syslog --poll-interval 15s --umask 002 --user-agent randomappname102 --rc --rc-addr :5572 -

Main PID: 5040 (code=exited, status=1/FAILURE)

May 01 11:12:01 osmc systemd[1]: Failed to start RClone Service.

After some mucking about it seems I got this working.

/lib/systemd/system/rclone.service file looks like this:

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

[Service]
Environment=RCLONE_CONFIG=/home/osmc/.config/rclone/rclone.conf
ExecStart=/home/osmc/scripts/mountscript.sh

[Install]
WantedBy=multi-user.target

/home/osmc/scripts/mountscript.sh file looks like this:

#!/bin/bash

/usr/bin/rclone mount crypt:media /home/osmc/gsuite --allow-non-empty --allow-other --size-only --dir-cache-time=2m --fast-list --vfs-read-chunk-size=96M --vfs-cache-max-age 675h --vfs-read-chunk-size-limit=1G --buffer-size=48M


These are the settings/variables I use on a coreelec-box and I got them from another rclone-user.

Are there any improvements to me made? I have a rather large library.