Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to install Syncthing on Raspberry Pi + start on boot
Create a folder in /opt and cd to it
$ sudo mkdir -p /opt/syncthing
$ cd /opt/syncthing
Get the latest arm version of syncthing from github (https://github.com/syncthing/syncthing/releases/) x marks the version number.
$ sudo wget https://github.com/syncthing/syncthing/releases/download/vx.xx.x/syncthing-linux-arm-vx.xx.x.tar.gz
sudo tar -xzvf syncthing-linux-arm-vx.xx.x.tar.gz
sudo rm syncthing-linux-arm-vx.xx.x.tar.gz
Move content one folder up
$ sudo mv syncthing-linux-arm-vx.xx.x/* .
$ sudo rm -r syncthing-linux-arm-vx.xx.x
link to it (not moving) so you can call it using 'syncthing'
$ sudo ln -s /opt/syncthing/syncthing /usr/bin/syncthing
Start syncthing
$ syncthing
Wait until you get something like:
INFO: Device 7NNIJMJ-RQ657WA-RI5YH6L-RQ657WA-RQ657WA-VGKSUYP-U6QBJNA-RQ657WA
write down this number or copy it if you SSH'd to your pi.
quit the operation using CTRL + C.
Change the config file so you can access the GUI from any PC within the network
$ nano ~/.config/syncthing/config.xml
Change
<gui enabled="true" tls="false">
<address>127.0.0.1:8384</address>
</gui>
to
<gui enabled="true" tls="true">
<address>0.0.0.0:8384</address>
</gui>
OPTIONAL: if you forward port 8384 (or any port you would like to use) on your router to you pi, you can access the GUI from anywhere in the world as long as you know you home(public) IP address.
Make sure you use https and enable authentication!
Start syncthing again
$ syncthing
on a PC in the same network, go to the GUI and disable automatic updates.
GUI -> Settings -> Disable Automatic updates
hit save and restart syncthing.
To enable syncthing on boot
cd to /etc/init.d/
$ cd /etc/init.d/
Download the script(Hint: its the script below)
$ sudo wget https://gist.githubusercontent.com/OIWitteveen/3452618e182ce9746343/raw/4cc25a607197f0d58ae8e416a986795cce9cd17e/syncthing
Change the directory line in the script to match the syncthing location
$ sudo nano /etc/init.d/syncthing
Change
DAEMON=/usr/local/bin/syncthing
to
DAEMON=/opt/syncthing/syncthing
exit and save (CTRL + X -> ENTER)
Make the script executable
$ sudo chmod +x /etc/init.d/syncthing
make the script start during boot
$ sudo update-rc.d syncthing defaults
Restart the the pi to apply changes
$ sudo reboot
If there's a new version of syncthing, use
$ sudo syncthing -upgrade
Then reboot the system.
$ sudo reboot
To remove syncthing use
$ sudo rm -r /opt/syncthing
$ sudo rm /usr/bin/syncthing
$ sudo rm -r /home/pi/.config/syncthing
$ sudo rm /etc/init.d/syncthing
optionally, delete any folder used with syncthing.
#!/bin/sh
### BEGIN INIT INFO
# Provides: syncthing
# 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: Multi-user daemonized version of syncthing.
# Description: Starts the syncthing daemon for all registered users.
### END INIT INFO
# Replace with users you want to run syncthing clients for
# syncthing_USERS="<your name here>"
syncthing_USERS="pi"
DAEMON=/usr/local/bin/syncthing
startd() {
for stuser in $syncthing_USERS; do
HOMEDIR=$(getent passwd $stuser | awk -F: '{print $6}')
if [ -f $config ]; then
echo "Starting syncthing for $stuser"
start-stop-daemon -b -o -c $stuser -S -u $stuser -x $DAEMON
else
echo "Couldn't start syncthing for $stuser (no $config found)"
fi
done
}
stopd() {
for stuser in $syncthing_USERS; do
dbpid=$(pgrep -fu $stuser $DAEMON)
if [ ! -z "$dbpid" ]; then
echo "Stopping syncthing for $stuser"
start-stop-daemon -o -c $stuser -K -u $stuser -x $DAEMON
fi
done
}
status() {
for stuser in $syncthing_USERS; do
dbpid=$(pgrep -fu $stuser $DAEMON)
if [ -z "$dbpid" ]; then
echo "syncthing for USER $stuser: not running."
else
echo "syncthing for USER $stuser: running (pid $dbpid)"
fi
done
}
case "$1" in
start) startd
;;
stop) stopd
;;
restart|reload|force-reload) stopd && startd
;;
status) status
;;
*) echo "Usage: /etc/init.d/syncthing {start|stop|reload|force-reload|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment