Install Syncthing Raspberry Pi – BitTorrent Sync Alternative

raspberry-pi-syncthingBitTorrent Sync has gotten heavy on resources so users are looking for alternatives to run on low-powered devices like the Raspberry Pi. Enter Syncthing which is written in go and has a significantly lower memory footprint compared to BitTorrent Sync. You can run the Syncthing server on Windows, Linux (Ubuntu, Debian, Arch), Mac OSX and others. There is an Android app for Syncthing too. This guide was tested on the Raspberry Pi 2 running Minibian Wheezy (a lightweight Raspbian) and is part of my Media Server Installer. The procedure below will work on any Ubuntu / Debian based system and SBCs which run Python like the Banana Pi, Orange Pi and other SBCs or x86 (32-bit) and x64 (64-bit) devices.

If you are trying to figure out which hardware would work best for you, consider reading the Pi benchmarks.

Pi Unit
Processor
RAM
RAM Bus
Network
WiFi
USB
SATA
Cost
Raspberry Pi 3
1.2 GHz ARMv8
Quad Core
1 GB DDR2
450 MHz
100 Mbit
Yes
4
No
$35
Raspberry Pi 2
900 MHz ARMv7
Quad Core
1 GB DDR2
450 MHz
100 Mbit
No
4
No
$35.00
Raspberry Pi
700 MHz ARMv6
Single Core
512 MB SDRAM
400 MHz
100 Mbit
No
4
No
$25
Banana Pi
1 GHz ARMv7
Dual Core
1 GB DDR3
432 MHz
Gigabit
No
2
Yes
$36.99
Banana Pi Pro
1 GHz ARMv7
Dual Core
1 GB DDR3
432 MHz
Gigabit
Yes
2
Yes
$45.00

Install Syncthing Raspberry Pi

Download the Syncthing repository gpg key

wget -O - https://syncthing.net/release-key.txt | sudo apt-key add -

Add the Syncthing repository

echo "deb http://apt.syncthing.net/ syncthing release" | sudo tee -a /etc/apt/sources.list.d/syncthing-release.list

Update your repositories and install Syncthing on the Raspberry Pi

sudo apt-get update
sudo apt-get install syncthing -y

Now start Syncthing to do some initial set up

syncthing

Syncthing doesn't start with remote access support so kill the process after you see this so we can edit the configuration file

[monitor] 17:45:33 INFO: Starting syncthing
[start] 17:45:33 INFO: Generating RSA key and certificate for syncthing...
[HR2B5] 17:47:33 INFO: syncthing v0.11.12 (go1.4.2 linux-arm default) unknown-user@syncthing-builder 2015-07-05 09:24:21 UTC
[HR2B5] 17:47:33 INFO: My ID: HR2B56D-52WUAGB-36PBQRH-VBU3AAN-YS6SXIM-LJXVBZP-BR3CEMP-STI4EQW
[HR2B5] 17:47:33 INFO: No config file; starting with empty defaults
[HR2B5] 17:47:33 INFO: Edit /home/pi/.config/syncthing/config.xml to taste or use the GUI
[HR2B5] 17:47:33 INFO: Database block cache capacity 8192 KiB
[HR2B5] 17:47:33 OK: Ready to synchronize default (read-write)
[HR2B5] 17:47:33 INFO: Starting web GUI on http://127.0.0.1:8384/
[HR2B5] 17:47:33 INFO: Loading HTTPS certificate: open /home/pi/.config/syncthing/https-cert.pem: no such file or directory
[HR2B5] 17:47:33 INFO: Creating new HTTPS certificate
[HR2B5] 17:47:33 INFO: Generating RSA key and certificate for raspberrypi...
[HR2B5] 17:47:33 INFO: Completed initial scan (rw) of folder default

Kill the syncthing process with Ctrl+C in the Terminal

Edit the Syncthing configuration file

nano /home/pi/.config/syncthing/config.xml

Change this line from the local loopback 127.0.0.1 to the any address code 0.0.0.0

Change tls to true if you want an SSL connection for the Syncthing web interface

<gui enabled="true" tls="false">
 <address>0.0.0.0:8384</address>
 <apikey>VbsKT2fCELYldTI74Tk4BKCbJP8Frlij</apikey>
</gui>

Autostart Syncthing on Raspberry Pi

Create the Syncthing init.d script

sudo nano /etc/init.d/syncthing

Paste the Syncthing init.d startup script, change your DAEMON_USER in case you do not have a pi user

#!/bin/sh
### BEGIN INIT INFO
# Provides:          Syncthing
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Syncthing
# Description:       Syncthing is for backups
### END INIT INFO
 
 
# Documentation available at
# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
# Debian provides some extra functions though
. /lib/lsb/init-functions
 
 
DAEMON_NAME="syncthing"
DAEMON_USER=pi
DAEMON_PATH="/usr/bin/syncthing"
DAEMON_OPTS=""
DAEMON_PWD="${PWD}"
DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description")
DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
DAEMON_NICE=0
DAEMON_LOG='/var/log/syncthing'
 
[ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}"
 
do_start() {
  local result
 
	pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
	if [ $? -eq 0 ]; then
		log_warning_msg "${DAEMON_NAME} is already started"
		result=0
	else
		log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
		touch "${DAEMON_LOG}"
		chown $DAEMON_USER "${DAEMON_LOG}"
		chmod u+rw "${DAEMON_LOG}"
		if [ -z "${DAEMON_USER}" ]; then
			start-stop-daemon --start --quiet --oknodo --background \
				--nicelevel $DAEMON_NICE \
				--chdir "${DAEMON_PWD}" \
				--pidfile "${DAEMON_PID}" --make-pidfile \
				--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
			result=$?
		else
			start-stop-daemon --start --quiet --oknodo --background \
				--nicelevel $DAEMON_NICE \
				--chdir "${DAEMON_PWD}" \
				--pidfile "${DAEMON_PID}" --make-pidfile \
				--chuid "${DAEMON_USER}" \
				--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
			result=$?
		fi
		log_end_msg $result
	fi
	return $result
}
 
do_stop() {
	local result
 
	pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
	if [ $? -ne 0 ]; then
		log_warning_msg "${DAEMON_NAME} is not started"
		result=0
	else
		log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
		killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
		result=$?
		log_end_msg $result
		rm "${DAEMON_PID}"
	fi
	return $result
}
 
do_restart() {
	local result
	do_stop
	result=$?
	if [ $result = 0 ]; then
		do_start
		result=$?
	fi
	return $result
}
 
do_status() {
	local result
	status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
	result=$?
	return $result
}
 
do_usage() {
	echo $"Usage: $0 {start | stop | restart | status}"
	exit 1
}
 
case "$1" in
start)   do_start;   exit $? ;;
stop)    do_stop;    exit $? ;;
restart) do_restart; exit $? ;;
status)  do_status;  exit $? ;;
*)       do_usage;   exit  1 ;;
esac

Make the Syncthing init.d script executable

sudo chmod +x /etc/init.d/syncthing

Set Syncthing to start on boot

sudo update-rc.d syncthing defaults

Now you can start Syncthing like this

sudo service syncthing start

Syncthing web interface will be available on port 8384, a configuration guide is in progress for syncing between a Banana Pi and Raspberry Pi.

You have now installed Syncthing the BitTorrent (btsync) alternative on your Raspberry Pi.