Skip to content

Instantly share code, notes, and snippets.

@mtfurlan
Created July 5, 2016 03:58
Show Gist options
  • Save mtfurlan/1d7ff0dcbee5a044a7d2ec9ac0202b64 to your computer and use it in GitHub Desktop.
Save mtfurlan/1d7ff0dcbee5a044a7d2ec9ac0202b64 to your computer and use it in GitHub Desktop.
#!/bin/bash
### BEGIN INIT INFO
# Provides: syncthing
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Syncthing
### END INIT INFO
#init info for something in the debian init system. Don't remember.
BIN=/usr/local/bin/syncthing
RUN=/var/run/syncthing.pid
USER=mark
CONFIG=/home/mark/.config/syncthing
LOG=/var/log/syncthing.log
case "$1" in
stop)
pid=$(pgrep -f $BIN | head -n1)
if [[ ! -z $pid ]]; then
echo "Stop Syncthing... $pid"
kill "$pid"
else
echo "Syncthing is not running..."
exit 1
fi
;;
start)
echo "Start Syncthing..."
read -r -d '' command <<- EOF
$BIN \
-no-browser \
-home=$CONFIG \
-logfile=$LOG \
-logflags=3 \
&>/dev/null
EOF
nohup su -- $USER -c "$command" &> /dev/null &
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 { start | stop | restart }" >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment