rclone Systemd startup mount script

rclone Systemd startup mount script

Get Social!
rclone

Rclone is a command line utility used for reading and writing to almost any type of cloud or remote storage. From Google Drive to Ceph, rclone supports almost any cloud-based remote storage platform you can think of. You can perform upload, download or synchronisation operations between local storage and remote cloud storage, or between remote storage directly.

In addition to this, rclone has an experimental mount feature that lets a user mount a remote cloud storage provider, such as s3 or Google Drive, as a local filesystem. You can then use the mounted filesystem as if it were a local device, albeit with some performance considerations.

Before we get going, make sure you have rclone installed on your system and configured with a remote. 

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

Once you have a remote defined, it’s time to create the mountpoint and systemd script. I’ll be using Google Drive for this example, but the mount command works for any supported remote.

Create the mount point directory to use for the remote storage:

mkdir /mnt/google-drive

Next, create the below systemd script and edit it as required:

vi /etc/systemd/system/rclone.service
# /etc/systemd/system/rclone.service
[Unit]
Description=Google Drive (rclone)
AssertPathIsDirectory=/mnt/google-drive
After=plexdrive.service

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount \
        --config=/root/.config/rclone/rclone.conf \
        --allow-other \
        --cache-tmp-upload-path=/tmp/rclone/upload \
        --cache-chunk-path=/tmp/rclone/chunks \
        --cache-workers=8 \
        --cache-writes \
        --cache-dir=/tmp/rclone/vfs \
        --cache-db-path=/tmp/rclone/db \
        --no-modtime \
        --drive-use-trash \
        --stats=0 \
        --checkers=16 \
        --bwlimit=40M \
        --dir-cache-time=60m \
        --cache-info-age=60m gdrive:/ /mnt/google-drive
ExecStop=/bin/fusermount -u /mnt/google-drive
Restart=always
RestartSec=10

[Install]
WantedBy=default.target

The important parts are detailed below, however, there are various other options are detailed on the rclone mount documentation page.

  • –config – the path to the config file created by rclone config. This is usually located in the users home directory.
  • gdrive:/ /mnt/google-drive – details two things; firstly the config name created in rclone config, and secondly the mount point on the local filesystem to use.

Once all this is in place you’ll need to start the service and enable the service at system startup (if required)

systemctl start rclone
systemctl enable rclone

CockroachDB systemd script

Get Social!

This is a simple systemd script for CockroachDB. It works for single node installations or multiple nodes, however you’ll need to manually join each node to the cluster before using the systemd script. 

Create the systemd file and add the following content:

vi /etc/systemd/system/cockroach.service
[Unit]
Description=CockroachDB

[Install]
WantedBy=multi-user.target

[Service]
ExecStartPre=/bin/bash -c "test -f /etc/cockroachdb/hosts && (/bin/systemctl set-environment JOIN_SWITCH=--join=$(test -f /etc/cockroachdb/hosts && cat /dev/null /etc/cockroachdb/hosts)) || exit 0"
ExecStartPre=/bin/bash -c "test -f /etc/cockroachdb/host && (/bin/systemctl set-environment HOST_SWITCH=--host=$(test -f /etc/cockroachdb/host && cat /dev/null /etc/cockroachdb/host)) || exit 0"

ExecStart=/usr/local/bin/cockroach start --certs-dir=/etc/cockroachdb/certs \
                                         --store=/var/data/cockroachdb/ \
                                         --cache=.40 \
                                         --max-sql-memory=.30 \
                                         --external-io-dir=/tmp/cockroachdb/externalio \
                                         --temp-dir=/tmp/ \
                                         --port=26257 \
                                         --http-port=7005 \
                                         --logtostderr=ERROR \
                                         --log-dir=/var/logs/cockroachdb \
                                         $JOIN_SWITCH $HOST_SWITCH

ExecStop=/usr/local/bin/cockroach quit --certs-dir=/etc/cockroachdb/certs
SyslogIdentifier=cockroachdb
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
LimitNOFILE=35000

Note that there are several paths specified in the above file which may need to be tailored to your installation requirements.

Run the following to enable the service on system start, and to start the CockroachDB service.

systemctl enable cockroach # enable on startup
systemctl start cockroach  # start CockroachDB

If your host belongs to a cluster, create a hosts file containing the hosts of other nodes in your cluster that will be read when starting your local node. For multiple nodes, use a comma to separate each hostname and port combination.

vi /etc/cockroachdb/hosts
server1.jamescoyle.net:26257,server2.jamescoyle.net:26257

Add systemd Startup Script For CouchDB

Get Social!

couchdb-whiteCurrently, version 2.0 of CouchDB doesn’t come with any form of startup script. I’m sure that as the CouchDB 2 branch becomes more mature and it’s added to the various software repositories startup scripts will be shipped as standard, but until then we have to make do.

The below script is a systemd startup script with a cat command to create the file with the required content in the systemd config directories. Run the below script to create the startup file. You’ll need to change /usr/bin/couchdb to be the location of your couchdb executable.

cat <<EOT >> /etc/systemd/system/couchdb.service
[Unit]
Description=Couchdb service
After=network.target

[Service]
Type=simple
User=couchdb
ExecStart=/usr/bin/couchdb -o /dev/stdout -e /dev/stderr
Restart=always
EOT

You’ll then need to reload the systemd daemon and add the couchdb service to the startup routine. Run the below commands to enable CouchDB at machine startup.

systemctl  daemon-reload
systemctl  start couchdb.service
systemctl  enable couchdb.service

 


Visit our advertisers

Search

Quick Poll

Do you use ZFS on Linux?

Visit our advertisers