Skip to content

Instantly share code, notes, and snippets.

@LakithKarunaratne
Last active February 8, 2022 19:24
Show Gist options
  • Save LakithKarunaratne/706e06eb994983f3c58912f0e888f5bb to your computer and use it in GitHub Desktop.
Save LakithKarunaratne/706e06eb994983f3c58912f0e888f5bb to your computer and use it in GitHub Desktop.

Setup Resilio Sync

Extract resilio-sync_xxx.tar for your architecture

Copy rslsync to /usr/bin/ or create a symlink

Now you can manually run rslsync in the terminal

continue reading for automation

First Method

Create a .config/resilio-sync folder in $USER $HOME with the structure below

.
├── config.json	# create with `touch` command
├── storage	# mkdir this
│   └── ...	# populated automatically
└── sync.pid 	# created automatically

config.json

Include the contents below

{
    "storage_path" : "/home/lakith/.config/resilio-sync/storage",
    "pid_file" : "/home/lakith/.config/resilio-sync/sync.pid",

    "webui" :
    {
        "force_https": true,
        "listen" : "127.0.0.1:8888"
    }
}

Create a unit file in the systemd path /usr/lib/systemd/user/resilio-sync.service

[Unit]
Description=Resilio Sync service
Documentation=https://help.getsync.com/
After=network.target network-online.target

[Service]
Type=forking
Restart=on-failure
PIDFile=%h/.config/resilio-sync/sync.pid
ExecStart=/usr/bin/rslsync --config /home/$USER/.config/resilio-sync/config.json
ExecStartPost=/bin/sleep 1

[Install]
WantedBy=default.target # ensure this is default target for single user

Systemd Restart

same as the other method

run in the terminal sudo systemctl daemon-reload to load the unit file

run to enable unit file systemctl --user enable resilio-sync

run to start systemctl --user start resilio-sync

use systemctl --user status resilio-sync to check the status or any errors. Ensure proper functionality by restarting the system

by default the localhost:8888 should open up the gui in the browser

Second Method

Auto Script genarally when deployed with the .deb installation, can be done manually. But untested as of writing this. Use caution.

place these files inside /etc/resilio-sync/. May need root permission

  1. config.json
  2. init_user_config.sh
  3. user_config.json

config.json

{
    "storage_path" : "/var/lib/resilio-sync/",
    "pid_file" : "/var/run/resilio-sync/sync.pid",

    "webui" :
    {
        "force_https": true,
        "listen" : "127.0.0.1:8888"
    }
}

init_user_config.sh

This script creates the .config/resilio-sync folder within $USER $HOME

#!/bin/sh

mkdir -p $HOME/.config/resilio-sync

BTSYNC_STORAGE=$HOME/.config/btsync/storage
RESILIO_STORAGE=$HOME/.config/resilio-sync/storage

BTSYNC_CONFIG_PATH=$HOME/.config/btsync/config.json
RESILIO_CONFIG_PATH=$HOME/.config/resilio-sync/config.json

if [ -d ${BTSYNC_STORAGE} ] && [ ! -d ${RESILIO_STORAGE} ]; then
    # Copy btsync storage folder
    cp -r ${BTSYNC_STORAGE} ${RESILIO_STORAGE}
    # Copy btsync config if exist
    if [ -f ${BTSYNC_CONFIG_PATH} ] && [ ! -f ${RESILIO_CONFIG_PATH}]; then
        cp ${BTSYNC_CONFIG_PATH} ${RESILIO_CONFIG_PATH}
        sed -i 's$\.config/btsync/storage$\.config/resilio-sync/storage$g' ${RESILIO_CONFIG_PATH}
        sed -i 's$\.config/btsync/btsync\.pid$\.config/resilio-sync/sync\.pid$g' ${RESILIO_CONFIG_PATH}
    fi
else
    mkdir -p ${RESILIO_STORAGE}
fi

if [ ! -f ${RESILIO_CONFIG_PATH} ]; then
    sed -e "s|{HOME}|$HOME|g" /etc/resilio-sync/user_config.json > ${RESILIO_CONFIG_PATH}
fi

user_config.json

The below contents will be copied over to .config/resilio-sync, you may edit as needed

Further information is on the vendor's site

{
    "storage_path" : "{HOME}/.config/resilio-sync/storage",
    "pid_file" : "{HOME}/.config/resilio-sync/sync.pid",

    "webui" :
    {
        "force_https": true,
        "listen" : "127.0.0.1:8888"
    }
}

Create unit file

This will need to be pasted into the systemd path /usr/lib/systemd/user/resilio-sync.service

[Unit]
Description=Resilio Sync service
Documentation=https://help.getsync.com/
After=network.target network-online.target

[Service]
Type=forking
Restart=on-failure
PIDFile=%h/.config/resilio-sync/sync.pid
ExecStart=/usr/bin/rslsync --config %h/.config/resilio-sync/config.json
ExecStartPre=/etc/resilio-sync/init_user_config.sh
ExecStartPost=/bin/sleep 1

[Install]
WantedBy=default.target

Systemd Restart

same as the other method

run in the terminal sudo systemctl daemon-reload to load the unit file

run to enable unit file systemctl --user enable resilio-sync

run to start systemctl --user start resilio-sync

use systemctl --user status resilio-sync to check the status or any errors. Ensure proper functionality by restarting the system

by default the localhost:8888 should open up the gui in the browser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment