Linux uninstall and init script.

This commit is contained in:
Adam Ierymenko 2013-11-08 14:32:23 -05:00
commit 085ad9073b
2 changed files with 76 additions and 92 deletions

View file

@ -17,99 +17,81 @@
# networks. See https://www.zerotier.com/ for more information.
### END INIT INFO
RETVAL=0
prog="zerotier-one"
exec="/var/lib/zerotier-one/zerotier-one"
lockfile="/var/lock/subsys/zerotier-one"
pidfile="/var/lib/zerotier-one/zerotier-one.pid"
#
# This script is written to avoid distro-specific dependencies, so it does not
# use the rc bash script libraries found on some systems. It should work on
# just about anything, even systems using Upstart. Upstart native support may
# come in the future.
#
# Source function library.
. /etc/rc.d/init.d/functions
zthome=/var/lib/zerotier-one
start() {
if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
daemon $exec
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
}
# Add $zthome to path so we can invoke zerotier-one naked, makes it look
# better in a ps listing.
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$zthome
stop() {
if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
echo -n $"Stopping $prog: "
pid=0
if [ -f "$pidfile" ]; then
pid=`cat $pidfile`
fi
if [ "$pid" -gt 0 ]; then
kill -TERM $pid
RETVAL=3
if [ "$UID" -ne 0 ]; then
echo "Init script must be called as root."
exit 4
fi
if [ ! -f "$zthome/zerotier-one" ]; then
echo "ZeroTier One is not installed in $zthome."
exit 5
fi
pid=0
if [ -f "$zthome/zerotier-one.pid" ]; then
pid=`cat $zthome/zerotier-one.pid`
fi
running=0
if [ "$pid" -gt 0 ]; then
if [ "`readlink -nf /proc/$pid/exe`" = "$zthome/zerotier-one" ]; then
running=1
else
failure $"Stopping $prog"
rm -f "$zthome/zerotier-one.pid"
fi
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
}
restart() {
stop
start
}
reload() {
stop
start
}
force_reload() {
restart
}
rh_status() {
status -p $pidfile $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
fi
case "$1" in
start)
rh_status_q && exit 0
$1
if [ $running -eq 0 ]; then
echo "ZeroTier One already running."
exit 0
fi
echo "Starting ZeroTier One..."
nohup zerotier-one >>/dev/null 2>&1 &
disown %1
exit 0
;;
stop)
rh_status_q || exit 0
$1
if [ $running -gt 0 ]; then
echo "Stopping ZeroTier One..."
kill -TERM $pid
else
echo "ZeroTier One is not running."
fi
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
restart|reload|force-reload|condrestart|try-restart)
echo "Restarting ZeroTier One..."
if [ $running -gt 0 ]; then
kill -TERM $pid
fi
while [ -f "$zthome/zerotier-one.pid" ]; do sleep 1; done
nohup zerotier-one >>/dev/null 2>&1 &
disown %1
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
if [ $running -gt 0 ]; then
exit 0
else
exit 3
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
exit 0