Created
December 18, 2020 17:22
-
-
Save mohclips/cbbf13357236d81b2edd26ef48a6a9bf to your computer and use it in GitHub Desktop.
init script for Terramaster NAS F2-220
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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