Skip to content

Instantly share code, notes, and snippets.

@mohclips
Created December 18, 2020 17:22
Show Gist options
  • Save mohclips/cbbf13357236d81b2edd26ef48a6a9bf to your computer and use it in GitHub Desktop.
Save mohclips/cbbf13357236d81b2edd26ef48a6a9bf to your computer and use it in GitHub Desktop.
init script for Terramaster NAS F2-220
#!/bin/bash
#
# /etc/rc.d/init.d/syncthing
#
# Starts the syncthing daemon on TerraMaster NAS
#
# chkconfig: 345 80 20
# description: the syncthing daemon
# processname: syncthing
# config: /etc/syncthing.conf
# Source function library.
. /etc/init.d/functions
user=mohclips
prog=syncthing
exec=/home/$user/syncthing/$prog
lockfile=/var/lock/subsys/$prog
pidfile=/var/run/$prog
RETVAL=0
check() {
[ `id -u` = 0 ] || exit 4
test -x $exec || exit 5
}
start() {
check
if [ ! -f $lockfile ]; then
echo -n $"Starting $prog: "
#daemon --user $user "nohup $exec" & # 'runuser' does not exist on this system :(
su -l $user -c $exec | logger -t $prog &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch $lockfile
ps aux | grep $exec | grep -v grep | tr -s " " | cut -d " " -f2 > $pidfile
fi
echo
else
echo "Error: $lockfile exists"
status $prog
fi
return $RETVAL
}
stop() {
check
echo -n $"Stopping $prog: "
killproc $exec #&& cat $pidfile | kill -9
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
rm -f $lockfile
rm -f $pidfile
success; echo
else
failure; echo
fi
echo
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=2
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment