diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-11-08 14:32:23 -0500 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-11-08 14:32:23 -0500 |
commit | 085ad9073bb1594f9116d6bfe8baf46a6b346958 (patch) | |
tree | 4e23b8c1395bdf2aa1c99c781153f929da5387ea | |
parent | 34302edcc59a7bf0a3e08fc053683764a158c95f (diff) | |
download | infinitytier-085ad9073bb1594f9116d6bfe8baf46a6b346958.tar.gz infinitytier-085ad9073bb1594f9116d6bfe8baf46a6b346958.zip |
Linux uninstall and init script.
-rwxr-xr-x | installer/linux/init.d/zerotier-one | 136 | ||||
-rwxr-xr-x | installer/linux/uninstall.sh | 30 |
2 files changed, 75 insertions, 91 deletions
diff --git a/installer/linux/init.d/zerotier-one b/installer/linux/init.d/zerotier-one index 5457d43b..4c8c5038 100755 --- a/installer/linux/init.d/zerotier-one +++ b/installer/linux/init.d/zerotier-one @@ -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" - -# Source function library. -. /etc/rc.d/init.d/functions +# +# 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. +# -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 -} +zthome=/var/lib/zerotier-one -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 - else - failure $"Stopping $prog" - fi - retval=$? - echo - [ $retval -eq 0 ] && rm -f $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 -restart() { - stop - start -} +if [ "$UID" -ne 0 ]; then + echo "Init script must be called as root." + exit 4 +fi -reload() { - stop - start -} +if [ ! -f "$zthome/zerotier-one" ]; then + echo "ZeroTier One is not installed in $zthome." + exit 5 +fi -force_reload() { - restart -} +pid=0 +if [ -f "$zthome/zerotier-one.pid" ]; then + pid=`cat $zthome/zerotier-one.pid` +fi -rh_status() { - status -p $pidfile $prog -} - -rh_status_q() { - rh_status >/dev/null 2>&1 -} +running=0 +if [ "$pid" -gt 0 ]; then + if [ "`readlink -nf /proc/$pid/exe`" = "$zthome/zerotier-one" ]; then + running=1 + else + rm -f "$zthome/zerotier-one.pid" + fi +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 - ;; - restart) - $1 + if [ $running -gt 0 ]; then + echo "Stopping ZeroTier One..." + kill -TERM $pid + else + echo "ZeroTier One is not running." + fi ;; - 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 diff --git a/installer/linux/uninstall.sh b/installer/linux/uninstall.sh index ba1418a1..1a8fe34c 100755 --- a/installer/linux/uninstall.sh +++ b/installer/linux/uninstall.sh @@ -3,32 +3,34 @@ export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin if [ "$UID" -ne 0 ]; then - echo "Must be run as root; try: sudo ./uninstall.sh" + echo "Must be run as root; try: sudo $0" exit 1 fi +echo + echo "Going to uninstall zerotier-one, hit CTRL+C to abort." echo "Waiting 5 seconds..." sleep 5 -ztpath="/Library/Application Support/ZeroTier/One" - echo "Killing any running zerotier-one service..." -killall -TERM zerotier-one -sleep 3 +killall -q -TERM zerotier-one +sleep 2 killall -q -KILL zerotier-one echo "Erasing binary and support files..." -cd $ztpath -rm -fv zerotier-one -rm -rfv updates.d -rm -fv *.persist -rm -rfv networks.d -rm -fv authtoken.secret -rm -fv identity.public +cd /var/lib/zerotier-one +rm -fv zerotier-one *.persist authtoken.secret identity.public *.log +rm -rfv updates.d networks.d iddb.d echo "Removing init items..." -chkconfig zerotier-one off rm -fv /etc/init.d/zerotier-one +find /etc/rc*.d -name '???zerotier-one' -print0 | xargs -0 rm -fv + +echo "Done." +echo +echo "Your ZeroTier One identity is still preserved in /var/lib/zerotier-one" +echo "as identity.secret and can be manually deleted if you wish. Save it if" +echo "you wish to re-use the address of this node, as it cannot be regenerated." -echo "Done. (identity still preserved in $ztpath)" +echo |