Heres an init.d script for Debian and anyone running syncthing on ZFS, this maybe very clear for some, but I knew nothing about init scripts before this and so I thought I might save someone the trouble. You just have to replace to bits of text. 1. the user you want to run it under 2. the path to syncthing
note: I didnt create this init script. the original was posted on these forums, they took it form btsync init script, I changed it a bit.
#!/bin/sh
### BEGIN INIT INFO
# Provides: syncthing
# Required-Start: $local_fs $remote_fs $network zfs-mount zfs zvol
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $network zfs-mount zfs zvol
# 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="<USER NAME>"
DAEMON=<PATH TO SYNCTHING>
startd() {
for stuser in $syncthing_USERS; do
HOMEDIR=$(getent passwd $stuser | awk -F: '{print $6}')
if [ -f $config ]; then
echo "Starting syncthiing 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