This is meant to restart synching on Debian-like systems. Note that the DAEMON_USER
is set to bob
in the file and should be set appropriately to the user that syncthing should run under. Given the nature of syncthing, the PID file is created under the user directory (at the current version, at /home/bob/.config/syncthing/syncthing.pid
).
#! /bin/sh ### BEGIN INIT INFO # Provides: syncthing # Required-Start: $local_fs $remote_fs $network $syslog $named $openvpn # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start syncthing. # Description: Starts the syncthing daemon. ### END INIT INFO ########################################################################### ## Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 ## ## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ## ## rights of fair usage, the disclaimer and warranty conditions. ## ########################################################################### PATH=/sbin:/usr/bin DAEMON=/usr/bin/syncthing DAEMON_USER=bob # Get lsb functions . /lib/lsb/init-functions do_start () { log_begin_msg "Starting syncthing daemon..." HOMEDIR=`getent passwd $DAEMON_USER | cut -d: -f6` if [ -x $DAEMON ]; then HOME="$HOMEDIR" start-stop-daemon --start -c $DAEMON_USER --pidfile $HOMEDIR/.config/syncthing/syncthing.pid --make-pidfile --background --exec $DAEMON fi log_end_msg $? } do_stop () { log_begin_msg "Stopping syncthing daemon..." HOMEDIR=`getent passwd $DAEMON_USER | cut -d: -f6` if [ -x $DAEMON ]; then start-stop-daemon -o -c $DAEMON_USER -K -u $DAEMON_USER -x $DAEMON fi log_end_msg $? } status () { status_of_proc "$DAEMON" syncthing } case "$1" in start) do_start ;; restart) do_stop /bin/sleep 1 do_start ;; status) status ;; stop) do_stop ;; *) echo "Usage: syncthing [start|stop|restart|status]" >&2 exit 3 ;; esac exit 0