2013-11-06 19:43:47 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# zerotier-one Virtual distributed Ethernet service
|
|
|
|
#
|
2013-11-07 19:51:26 +00:00
|
|
|
# chkconfig: 2345 11 89
|
2013-11-06 19:43:47 +00:00
|
|
|
# description: ZeroTier One provides public and private distributed ethernet \
|
|
|
|
# networks. See https://www.zerotier.com/ for more information.
|
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
2015-12-01 18:19:10 +00:00
|
|
|
# Provides: zerotier-one
|
|
|
|
# Required-Start: $local_fs $network
|
|
|
|
# Required-Stop: $local_fs
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Start ZeroTier One
|
|
|
|
# Description: ZeroTier One provides public and private distributed ethernet \
|
|
|
|
# networks. See https://www.zerotier.com/ for more information.
|
2013-11-06 19:43:47 +00:00
|
|
|
### END INIT INFO
|
|
|
|
|
2013-11-08 19:32:23 +00:00
|
|
|
#
|
|
|
|
# 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
|
2015-12-01 18:19:10 +00:00
|
|
|
# just about anything.
|
2013-11-08 19:32:23 +00:00
|
|
|
#
|
2013-11-06 19:43:47 +00:00
|
|
|
|
2013-11-08 19:32:23 +00:00
|
|
|
zthome=/var/lib/zerotier-one
|
2013-11-06 19:43:47 +00:00
|
|
|
|
2013-11-08 19:32:23 +00:00
|
|
|
# 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
|
2013-11-06 19:43:47 +00:00
|
|
|
|
2014-03-05 22:57:25 +00:00
|
|
|
if [ "`id -u`" -ne 0 ]; then
|
2013-11-08 19:32:23 +00:00
|
|
|
echo "Init script must be called as root."
|
|
|
|
exit 4
|
|
|
|
fi
|
2013-11-06 19:43:47 +00:00
|
|
|
|
2013-11-08 19:32:23 +00:00
|
|
|
if [ ! -f "$zthome/zerotier-one" ]; then
|
|
|
|
echo "ZeroTier One is not installed in $zthome."
|
|
|
|
exit 5
|
|
|
|
fi
|
2013-11-06 19:43:47 +00:00
|
|
|
|
2013-11-08 19:32:23 +00:00
|
|
|
pid=0
|
|
|
|
if [ -f "$zthome/zerotier-one.pid" ]; then
|
|
|
|
pid=`cat $zthome/zerotier-one.pid`
|
|
|
|
fi
|
2013-11-06 19:43:47 +00:00
|
|
|
|
2013-11-08 19:32:23 +00:00
|
|
|
running=0
|
|
|
|
if [ "$pid" -gt 0 ]; then
|
2014-10-13 16:55:16 +00:00
|
|
|
exepath=`readlink /proc/$pid/exe 2>/dev/null | grep zerotier-one`
|
|
|
|
if [ -n "$exepath" ]; then
|
2013-11-08 19:32:23 +00:00
|
|
|
running=1
|
|
|
|
fi
|
|
|
|
fi
|
2013-11-06 19:43:47 +00:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2013-11-08 22:37:47 +00:00
|
|
|
if [ $running -gt 0 ]; then
|
2013-11-08 19:32:23 +00:00
|
|
|
echo "ZeroTier One already running."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "Starting ZeroTier One..."
|
2014-03-03 20:00:26 +00:00
|
|
|
zerotier-one -d
|
2013-11-06 19:43:47 +00:00
|
|
|
;;
|
|
|
|
stop)
|
2013-11-08 19:32:23 +00:00
|
|
|
if [ $running -gt 0 ]; then
|
|
|
|
echo "Stopping ZeroTier One..."
|
|
|
|
kill -TERM $pid
|
2014-10-13 15:15:00 +00:00
|
|
|
sleep 0.25
|
|
|
|
if [ -f "$zthome/zerotier-one.pid" ]; then
|
|
|
|
sleep 0.5
|
|
|
|
fi
|
|
|
|
if [ -f "$zthome/zerotier-one.pid" ]; then
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
if [ -f "$zthome/zerotier-one.pid" ]; then
|
|
|
|
kill -KILL $pid >>/dev/null 2>&1
|
|
|
|
rm -f "$zthome/zerotier-one.pid"
|
|
|
|
fi
|
2013-11-08 19:32:23 +00:00
|
|
|
else
|
|
|
|
echo "ZeroTier One is not running."
|
|
|
|
fi
|
2013-11-06 19:43:47 +00:00
|
|
|
;;
|
2013-11-08 19:32:23 +00:00
|
|
|
restart|reload|force-reload|condrestart|try-restart)
|
|
|
|
echo "Restarting ZeroTier One..."
|
|
|
|
if [ $running -gt 0 ]; then
|
2014-10-13 15:15:00 +00:00
|
|
|
kill -TERM $pid >>/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
sleep 0.25
|
|
|
|
if [ -f "$zthome/zerotier-one.pid" ]; then
|
|
|
|
sleep 0.5
|
|
|
|
fi
|
|
|
|
if [ -f "$zthome/zerotier-one.pid" ]; then
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
if [ -f "$zthome/zerotier-one.pid" ]; then
|
|
|
|
kill -KILL $pid >>/dev/null 2>&1
|
|
|
|
rm -f "$zthome/zerotier-one.pid"
|
2013-11-08 19:32:23 +00:00
|
|
|
fi
|
2014-03-03 20:00:26 +00:00
|
|
|
zerotier-one -d
|
2013-11-06 19:43:47 +00:00
|
|
|
;;
|
|
|
|
status)
|
2013-11-08 19:32:23 +00:00
|
|
|
if [ $running -gt 0 ]; then
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit 3
|
|
|
|
fi
|
2013-11-06 19:43:47 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
|
|
|
|
exit 2
|
|
|
|
esac
|
2013-11-08 19:32:23 +00:00
|
|
|
|
|
|
|
exit 0
|