# Systemd service for rclone mounts/docker autostart

**URL:** <https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171>\
**Category:** Help and Support\
**Created:** [June 19, 2023, 3:38pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171 "2023-06-19T15:38:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bstrmbrg](https://forum.rclone.org/letter_avatar_proxy/v4/letter/b/ba8739/32.png) [@bstrmbrg](https://forum.rclone.org/u/bstrmbrg)\
**Post date:** [June 19, 2023, 3:38pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/1 "2023-06-19T15:38:21Z")

</div>

#### What is the problem you are having with rclone?

Hello. I have three custom systemd services, two rclone mount services and one for starting my docker stack. At the moment I have disabled autostart on these services because I have an annoying problem on my server where unbound fails to autostart when I reboot and I have to manually start it. Without unbound the server has no internet access so the mounts won't start either. I think it's due to timing of the autostart or something because it starts without a problem with systemctl start.

What I would like to do is have one "master" service that starts the other services provided that they meet the criteria for starting. Any help on approaching this would be much appreciated.

Another annoying error I have when rebooting the server is that sonarr/radarr can't see the rclone mount the first time they are started. First I start the rclone mount service, then I start my docker compose service. Now I need to restart radarr/sonarr one time in order for them to see the root folders (rclone mount).

Basically I would like some help with creating a systemd service that does the following:

1. Wait for a while to let other system services start up
2. Start unbound
3. If unbound started successfully and the server has internet access, start mount service 1  
and mount service 2
4. Wait until the mounts are available in the file system (no idea how to do this check in the service)
5. Start docker compose service.

I am running Ubuntu 22.04

#### Run the command 'rclone version' and share the full output of the command.

rclone v1.61.1

- os/version: ubuntu 22.04 (64 bit)
- os/kernel: 5.19.0-45-generic (x86\_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.19.4
- go/linking: static
- go/tags: none

#### Which cloud storage system are you using? (eg Google Drive)

Google Drive

#### The command you were trying to run (eg `rclone copy /tmp remote:tmp`)

Here are my 3 systemd services:

rclone-drive.service (used to start my main mount:

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

[Service]
ExecStart=/usr/bin/rclone mount \
  --config=/opt/rclone/rclone.conf \
  --log-level=INFO \
  --bwlimit 25M:off \
  --log-file=/opt/rclone/logs/rclone-mount.log \
  --umask=002 \
  --gid=1000 \
  --uid=1000 \
  --allow-other \
  --timeout=1h \
  --poll-interval=15s \
  --dir-cache-time=1000h \
  --cache-dir=/media/ssd/rclone_cache \
  --vfs-cache-mode=full \
  --vfs-cache-max-size=1500G \
  --vfs-cache-max-age=12h \
  --vfs-read-ahead=2G \
  gcrypt_direct: /data1/Allt
ExecStop=/bin/fusermount -uz /data1/Allt
Restart=on-abort
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3

[Install]
WantedBy=multi-user.target

```

rclone-drive-nextcloud.service (used to start a separate mount for seafile (haven't bothered to change the service name:

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

[Service]
#Type=notify
#Environment=RCLONE_CONFIG=/opt/rclone/rclone.conf
#KillMode=none
#RestartSec=5
#ExecStart=/usr/bin/rclone mount gcrypt_direct: /data1/Allt --log-file /opt/rclone/logs/gcrypt_direct.log --allow-other
#ExecStop=/bin/fusermount -uz /data1/Allt
#Restart=on-failure
#User=olympen
#Group=olympen
ExecStart=/usr/bin/rclone mount \
  --config=/opt/rclone/rclone.conf \
  --log-level=INFO \
  --log-file=/opt/rclone/logs/rclone-mount-seafile.log \
  --umask=002 \
  --gid=8000 \
  --uid=8000 \
  --allow-other \
  --timeout=1h \
  --poll-interval=15s \
  --dir-cache-time=1000h \
  --cache-dir=/media/ssd/rclone_cache_seafile \
  --vfs-cache-mode=full \
  --vfs-cache-max-size=100G \
  --vfs-cache-max-age=12h \
  gcrypt_nextcloud: /data2/seafile_data
ExecStop=/bin/fusermount -uz /data2/seafile_data
Restart=on-abort
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3

[Install]
WantedBy=multi-user.target

```

docker-compose.service, for starting my docker stack:

```auto

[Unit]
Description=Docker Compose container starter
After=docker.service network-online.target
Requires=docker.service network-online.target

[Service]
WorkingDirectory=/opt/docker
Type=oneshot
RemainAfterExit=yes

#ExecStartPre=/usr/local/bin/docker-compose pull --quiet --parallel
ExecStart=docker-compose -f /opt/docker/docker-compose.yml up --detach

ExecStop=docker-compose -f /opt/docker/docker-compose.yml down

#ExecReload=/usr/local/bin/docker-compose pull --quiet --parallel
ExecReload=docker-compose -f /opt/docker/docker-compose.yml up --detach

[Install]
WantedBy=multi-user.target

```

#### The rclone config contents with secrets removed.

```auto
[gdrive]
type = drive
token = 
root_folder_id = 
client_id = 
client_secret = 
team_drive = 

[gcrypt_direct]
type = crypt
remote = gdrive:/gdrive/crypt
filename_encryption = obfuscate
directory_name_encryption = true
password = 
password2 = 

[seafile]
type = seafile
url = 
user =
pass =
2fa = true
auth_token = 

```

#### A log from the command with the `-vv` flag

```auto
Paste log here

```

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://forum.rclone.org/user_avatar/forum.rclone.org/kapitainsky/32/14450_2.png) [@kapitainsky](https://forum.rclone.org/u/kapitainsky)\
**Post date:** [June 19, 2023, 3:48pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/2 "2023-06-19T15:48:23Z")

</div>

> [@bstrmbrg](#):
>
> - Wait for a while to let other system services start up
> - Start unbound

For this there are two options IMHO:

1. 

add to `unbound.service`

```auto
[Service]
ExecStartPre=/bin/sleep 60

```

1. 

create an `unbound.timer` systemd to control `unbound.service`

```auto
[Timer]
OnBootSec=1min

```

make sure that `unbound.service` is disabled and timer is enabled - `unbound.service` it will be started by timer

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://forum.rclone.org/user_avatar/forum.rclone.org/kapitainsky/32/14450_2.png) [@kapitainsky](https://forum.rclone.org/u/kapitainsky)\
**Post date:** [June 19, 2023, 3:56pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/3 "2023-06-19T15:56:59Z")

</div>

> [@bstrmbrg](#):
>
> If unbound started successfully and the server has internet access, start mount service 1  
> and mount service 2

in your mount services add:

`After=unbound.service`

and you can use [`systemd-networkd-wait-online.service`](https://www.freedesktop.org/software/systemd/man/systemd-networkd-wait-online.service.html) to check for internet connection

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://forum.rclone.org/user_avatar/forum.rclone.org/kapitainsky/32/14450_2.png) [@kapitainsky](https://forum.rclone.org/u/kapitainsky)\
**Post date:** [June 19, 2023, 3:58pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/4 "2023-06-19T15:58:32Z")

</div>

> [@bstrmbrg](#):
>
> Wait until the mounts are available in the file system (no idea how to do this check in the service)

Use:

```auto
[Service]
ExecStartPre=/path/to/rclone_mount_ready.sh

```

and write simple script checking and waiting until mount is ready

---

<div class="post-metadata">

**Author:** ![bstrmbrg](https://forum.rclone.org/letter_avatar_proxy/v4/letter/b/ba8739/32.png) [@bstrmbrg](https://forum.rclone.org/u/bstrmbrg)\
**Post date:** [June 19, 2023, 4:08pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/5 "2023-06-19T16:08:14Z")

</div>

Thanks. For the timer service how would I start the unbound service? Via "systemctl start unbound" or should I copy the original unbound.service?

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://forum.rclone.org/user_avatar/forum.rclone.org/kapitainsky/32/14450_2.png) [@kapitainsky](https://forum.rclone.org/u/kapitainsky)\
**Post date:** [June 19, 2023, 4:11pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/6 "2023-06-19T16:11:00Z")

</div>

timer is bound to service by name

`unbound.timer` starts `unbound.service` when it fires

You do not change anything in `unbound.service` - do not forget to disable it - otherwise systemd will start it regardless of timer or not

this is all what is needed in timer:

```auto
[Timer]
OnBootSec=1min

```

Here more details:

[https://wiki.archlinux.org/title/systemd/Timers](https://wiki.archlinux.org/title/systemd/Timers)

---

<div class="post-metadata">

**Author:** ![bstrmbrg](https://forum.rclone.org/letter_avatar_proxy/v4/letter/b/ba8739/32.png) [@bstrmbrg](https://forum.rclone.org/u/bstrmbrg)\
**Post date:** [June 19, 2023, 4:16pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/7 "2023-06-19T16:16:42Z")

</div>

Ah I see. And the unbound.timer should be in /lib/systemd/system or /etc/systemd/system?

---

<div class="post-metadata">

**Author:** ![kapitainsky](https://forum.rclone.org/user_avatar/forum.rclone.org/kapitainsky/32/14450_2.png) [@kapitainsky](https://forum.rclone.org/u/kapitainsky)\
**Post date:** [June 19, 2023, 4:18pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/8 "2023-06-19T16:18:57Z")

</div>

The same folder where service is seems logical.

---

<div class="post-metadata">

**Author:** ![bstrmbrg](https://forum.rclone.org/letter_avatar_proxy/v4/letter/b/ba8739/32.png) [@bstrmbrg](https://forum.rclone.org/u/bstrmbrg)\
**Post date:** [June 19, 2023, 4:21pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/9 "2023-06-19T16:21:35Z")

</div>

Thanks, I will try your suggestions!

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [July 19, 2023, 4:22pm UTC](https://forum.rclone.org/t/systemd-service-for-rclone-mounts-docker-autostart/39171/10 "2023-07-19T16:22:19Z")

</div>

Closed on July 19, 2023, 4:22pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
