Skip to content

Instantly share code, notes, and snippets.

@hdml
Last active November 22, 2023 19:26
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save hdml/7b079c114d3e20bf69f1 to your computer and use it in GitHub Desktop.
Save hdml/7b079c114d3e20bf69f1 to your computer and use it in GitHub Desktop.
How to install Syncthing on Raspberry Pi + start on boot [semi-automatic]

##Run install_syncthing.sh

$ curl -s https://gist.githubusercontent.com/hdml/7b079c114d3e20bf69f1/raw/1cd3647b1db4f80726c145fba725e27993a7fcdb/install_syncthing.sh | sudo bash

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 127.0.0.1 to 0.0.0.0

<gui enabled="true" tls="false">
    <address>127.0.0.1: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 the syncthing service

$ sudo service syncthing start

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.

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
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
mkdir -p /opt/syncthing
cd /opt/syncthing
wget https://github.com/syncthing/syncthing/releases/download/v0.12.19/syncthing-linux-arm-v0.12.19.tar.gz
tar -xzvf *.tar.gz
mv syncthing*/* .
rm *.tar.gz
rm -r syncthing*/
ln -s /opt/syncthing/syncthing /usr/bin/syncthing
cd /etc/init.d/
wget https://gist.githubusercontent.com/hdml/7b079c114d3e20bf69f1/raw/e42d18d8fb966e4ff16135035720d97139867bad/syncthing
chmod +x /etc/init.d/syncthing
update-rc.d syncthing defaults
#!/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=/opt/syncthing/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
@jonneymendoza
Copy link

how can i automatically start syncthing whenever my pi 4 device boots?

@pinazoraso
Copy link

How can I keep Syncthing up to date?
When I type sudo syncthing -upgrade
I get:
INFO: Default folder created and/or linked to new config
FATAL: Upgrade: upgrade unsupported

@jonneymendoza
Copy link

ANyone?

@loket
Copy link

loket commented Jul 17, 2020

Copy link

ghost commented Apr 7, 2022

Hi I get error when trying to upgrade as unsupported
02:14:29 INFO: Default folder created and/or linked to new config
02:14:29 WARNING: Upgrade: upgrade unsupported

The mentioned guide does not provide for upgrade

@Jonny-exe
Copy link

Another solution exists that doesn't need a web browser and works exclusively via CLI commands. Have a look at this gist:

https://gist.github.com/Jonny-exe/9bad76c3adc6e916434005755ea70389

This works with the official syncthing cli

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