Control Rclone / Plexdrive with Supervisord
June 30th, 2021, 22:03

Introduction

In this tutorial we are going to use supervisord to control rclone / plexdrive as a service on our SSH app. Setting up services with supervisord will also automatically start them when your SSH app starts. Supervisord comes preinstalled in your SSH app (16.04 / 18.04 / 20.04).


Prerequisites

  • Rclone:
    You will have to have added a remote on your rclone. In case you have not added one yet, please complete steps 1 - 3 from our wiki article: Set up an rclone mount using ssh.
  • Plexdrive:
    You will have to have completed plexdrive setup. In case you have not, check out our wiki article: Set up Plexdrive.


Stop any fusemounts and screens before continuing.


Step 1 - Install a text editor

Install nano editor on your system:

sudo apt-get update && sudo apt-get install nano


Step 2 - Create log files

For Rclone:

touch /mnt/shared/logs/rclone.log
touch /mnt/shared/logs/rclone-error.log


For Plexdrive:

touch /mnt/shared/logs/plexdrive.log
touch /mnt/shared/logs/plexdrive-error.log


Step 3 - Create program conf file for supervisord

Create a .conf file for each program you want to control

For Rclone create a rclone.conf file:

nano /etc/supervisor/conf.d/rclone.conf

Type in:

[program:rclone]
command=sh /mnt/shared/config/rclone_script.sh
stdout_logfile = /mnt/shared/logs/rclone.log
stderr_logfile = /mnt/shared/logs/rclone-error.log

To exit and save the file, press Ctrl+X, type y and press Enter.


For Plexdrive create a plexdrive.conf file:

nano /etc/supervisor/conf.d/plexdrive.conf

Type in:

[program:plexdrive]
command=sh /mnt/shared/config/plexdrive_script.sh
stdout_logfile = /mnt/shared/logs/plexdrive.log
stderr_logfile = /mnt/shared/logs/plexdrive-error.log

To exit and save the file, press Ctrl+X, type y and press Enter.


Step 4 - Create a script to run our program

For Rclone:

nano /mnt/shared/config/rclone_script.sh

Type in:

#!/bin/bash
fusermount -uz "/mnt/shared/fusemounts/google"
exec rclone mount google:/ /mnt/shared/fusemounts/google --timeout 1h --tpslimit 10 --dir-cache-time 5m --vfs-cache-mode writes --vfs-cache-max-age 1h --vfs-cache-max-size 100G --vfs-read-chunk-size-limit 1024M --vfs-read-chunk-size 26M --buffer-size 16M --cache-dir /mnt/shared/config/rclone/cache --allow-other --gid 911 --uid 911

To exit and save the file, press Ctrl+X, type y and press Enter.

Mind the exec before rclone command.

Make it executable

chmod +x /mnt/shared/config/rclone_script.sh


For Plexdrive:

nano /mnt/shared/config/plexdrive_script.sh

Type in:

#!/bin/bash
fusermount -uz "/mnt/shared/fusemounts/plexdrive"
exec plexdrive -v 3 --refresh-interval=1m --chunk-check-threads=16 --chunk-load-threads=16 --chunk-load-ahead=16 --max-chunks=256 --chunk-size=5M mount -o allow_other --gid=911 --uid=911 --cache-file=/mnt/shared/config/plexdrive/cache.bolt -c /mnt/shared/config/plexdrive/ /mnt/shared/fusemounts/plexdrive

To exit and save the file, press Ctrl+X, type y and press Enter.

Mind the exec before plexdrive command.

Make it executable

chmod +x /mnt/shared/config/plexdrive_script.sh


Step 5 - Reload supervisord

Tell supervisord load the changes:

supervisorctl reread

You should get something like:

root@wiki:/# supervisorctl reread
rclone: available
plexdrive: available

Tell supervisord to load and start the new program:

supervisorctl update

You should get something like:

root@wiki:/# supervisorctl update
rclone: added process group
plexdrive: added process group


Step 6 - Verify that it is running

You can use supervisorctl status to check if they are running:

root@wiki:/# supervisorctl status
rclone RUNNING pid 154, uptime 0:00:19
plexdrive RUNNING pid 155, uptime 0:00:20
sshd RUNNING pid 8, uptime 0:05:37


Notes

  • Processes have to run in the foreground, not in the background (daemon).
  • Supervisord should not be used to run one-off scripts. It will try to keep the process alive, so it will re-run it after it exits.
  • You should avoid making changes on ssh.conf, cause you might lock yourself out of your SSH app.


Conclusion

You have successfully setup your rclone / plexdrive to run with Supervisord.