Skip to content

Instantly share code, notes, and snippets.

@ellisgeek
Forked from mendelgusmao/btsync
Last active August 8, 2022 20:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellisgeek/a82a7cc35c4d5bbb2d55 to your computer and use it in GitHub Desktop.
Save ellisgeek/a82a7cc35c4d5bbb2d55 to your computer and use it in GitHub Desktop.
Proper init.d script for btsync. Comes with complete install instructions!
#!/bin/sh
### BEGIN INIT INFO
# Provides: btsync
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: daemonized version of btsync.
# Description: Starts the btsync daemon.
### END INIT INFO
USER="btsync"
DAEMON=/usr/bin/btsync
CONFDIR=/etc/btsync
PIDFILE=/var/run/btsync/btsync.pid
start() {
config=$CONFDIR/config.json
if [ -f $config ]; then
echo "Starting BTSync"
start-stop-daemon --background --oknodo --chuid $USER --user $USER --pidfile $PIDFILE --exec $DAEMON --start -- --config $config
else
echo "Couldn't start BTSync (no $config found)"
fi
}
stop() {
echo "Stopping btsync"
start-stop-daemon --oknodo --chuid $USER --user $USER --pidfile $PIDFILE --stop
}
status() {
if [ -z "$(pgrep -fu $USER $DAEMON)" ]; then
echo "btsync is not running"
else
echo "btsync is running (pid $(pgrep -fu $USER $DAEMON))"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
stop
start
;;
status)
status
;;
*)
echo "Usage: /etc/init.d/btsync {start|stop|reload|force-reload|restart|status}"
exit 1
esac
exit 0
  • Download and install btsync to `/usr/bin``
    • If you are on a 32 bit machine
      • wget -O btsync.tar.gz http://download-new.utorrent.com/endpoint/btsync/os/linux-x86/track/stable
    • If you are on a 64 bit machine
      • wget -O btsync.tar.gz http://download-new.utorrent.com/endpoint/btsync/os/linux-x64/track/stable
    • sudo tar -xvf btsync.tar.gz -C /usr/bin btsync
  • Create a user for btsync
    • I used this sudo adduser --home /var/btsync --no-create-home --shell /usr/sbin/nologin --disabled-login --ingroup btsync
  • Create directories for btsync
    • sudo mkdir /etc/btsync
    • sudo mkdir -p /var/btsync/shared
    • sudo mkdir /var/run/btsync
  • Chown directories so that btsync can write to them
    • sudo chown -R btsync /var/btsync
    • sudo chown btsync /var/run/btsync
  • Create btsync config at /etc/btsync/config.json (See below for example or execute btsync --dump-sample-config to get a sample)
  • Install the above init script to /etc/init.d and make it executable
    • To get the script directly from this gist:
      • sudo wget -O /etc/init.d/btsync https://gist.githubusercontent.com/ellisgeek/a82a7cc35c4d5bbb2d55/raw/93eee792f01fa729b3b979a34752cb6d1929daa6/btsync.sh
    • Otherwise you should know what to do.
  • Make btsync start at boot
    • sudo update-rc.d btsync defaults
  • Execute sudo service btsync start
  • Navigate to http://<IP OR HOST>:8888 to access btsync (Login with the credentials set in the config)

Example configuration:

{
    "device_name": "<DEVICE NAME>",
    "listening_port": 0,
    "storage_path": "/var/btsync",
    "pid_file": "/var/run/btsync/btsync.pid",
    "use_upnp": false,
    "download_limit": 0,
    "upload_limit": 0,
    "webui": {
        "listen": "0.0.0.0:8888",
        "login": "<USERNAME>",
        "password": "<PASSWORD>",
        "allow_empty_password": false,
        "directory_root": "/var/btsync/shared",
        "dir_whitelist": [
            "/var/btsync/shared",
            "/home/<USER>/shared"
        ]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment