rewrite restart logic
This commit is contained in:
+14
-15
@@ -5,9 +5,6 @@ MODDIR=${0%/*}
|
|||||||
# load variables
|
# load variables
|
||||||
. $MODDIR/vars.sh
|
. $MODDIR/vars.sh
|
||||||
|
|
||||||
# LD_LIBRARY_PATH for NDK
|
|
||||||
export LD_LIBRARY_PATH=/system/lib64:/data/adb/zerotier/lib
|
|
||||||
|
|
||||||
log_cli() {
|
log_cli() {
|
||||||
echo -e "$1" >> $ZTROOT/run/cli.out
|
echo -e "$1" >> $ZTROOT/run/cli.out
|
||||||
}
|
}
|
||||||
@@ -29,33 +26,35 @@ _stop() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wait
|
|
||||||
sleep 1 # sometimes it fails without sleeping
|
|
||||||
|
|
||||||
log "stopped zerotier-one"
|
log "stopped zerotier-one"
|
||||||
}
|
}
|
||||||
_start() {
|
_start() {
|
||||||
if pid=`pidof zerotier-one`; then
|
if pidof zerotier-one > /dev/null; then
|
||||||
log "zerotier-one already running pid $pid"
|
log "zerotier-one already running"
|
||||||
else
|
else
|
||||||
$ZTROOT/zerotier-one -d >> $ZT_LOG 2>&1 &
|
__start
|
||||||
pid=`pidof zerotier-one`
|
log "started zerotier-one"
|
||||||
log "started zerotier-one pid $pid"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
_status() {
|
_status() {
|
||||||
# fake systemd lol
|
# fake systemd lol
|
||||||
if pid=`pidof zerotier-one`; then
|
read pid < $ZTROOT/home/zerotier-one.pid
|
||||||
|
|
||||||
|
if pidof zerotier-one > /dev/null; then
|
||||||
log_cli "\033[32m●\033[0m zerotier-one.service - ZeroTier One - Global Area Networking"
|
log_cli "\033[32m●\033[0m zerotier-one.service - ZeroTier One - Global Area Networking"
|
||||||
log_cli " Active: \033[32mactive (running)\033[0m"
|
log_cli " Active: \033[32mactive (running)\033[0m"
|
||||||
log_cli " Main PID: $pid (zerotier-one)"
|
log_cli " Main PID: $pid (zerotier-one)"
|
||||||
else
|
else
|
||||||
read pid_ < $ZTROOT/home/zerotier-one.pid
|
|
||||||
log_cli "○ zerotier-one.service - ZeroTier One - Global Area Networking"
|
log_cli "○ zerotier-one.service - ZeroTier One - Global Area Networking"
|
||||||
log_cli " Active: inactive (dead)"
|
log_cli " Active: inactive (dead)"
|
||||||
log_cli " Main PID: $pid_ (code=exited)"
|
log_cli " Main PID: $pid (code=exited)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
_restart() {
|
||||||
|
_stop
|
||||||
|
__start
|
||||||
|
log "started zerotier-one"
|
||||||
|
}
|
||||||
|
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
# call from inotifyd
|
# call from inotifyd
|
||||||
@@ -68,7 +67,7 @@ if [[ $# == 2 && "$1" == "w" ]]; then
|
|||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
"start") _start;;
|
"start") _start;;
|
||||||
"stop") _stop;;
|
"stop") _stop;;
|
||||||
"restart") _stop; _start;;
|
"restart") _restart;;
|
||||||
"status") _status;;
|
"status") _status;;
|
||||||
*) log "unknown command $cmd";;
|
*) log "unknown command $cmd";;
|
||||||
esac
|
esac
|
||||||
|
|||||||
+1
-4
@@ -37,11 +37,8 @@ mkdir -p $ZTROOT/run
|
|||||||
ip rule add from all lookup main pref 1
|
ip rule add from all lookup main pref 1
|
||||||
ip -6 rule add from all lookup main pref 1
|
ip -6 rule add from all lookup main pref 1
|
||||||
|
|
||||||
# LD_LIBRARY_PATH for NDK
|
|
||||||
export LD_LIBRARY_PATH=$ZTROOT/lib
|
|
||||||
|
|
||||||
# start zerotier
|
# start zerotier
|
||||||
$ZTROOT/zerotier-one -d >> $ZT_LOG 2>&1 &
|
__start
|
||||||
|
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
# CLI before login
|
# CLI before login
|
||||||
|
|||||||
+8
-1
@@ -9,4 +9,11 @@ DAEMON_LOG=$ZTROOT/run/daemon.log
|
|||||||
PIPE_CLI=$ZTROOT/run/pipe
|
PIPE_CLI=$ZTROOT/run/pipe
|
||||||
PIPE_APP=$APPROOT/run/pipe
|
PIPE_APP=$APPROOT/run/pipe
|
||||||
|
|
||||||
BB=/data/adb/magisk/busybox
|
BB=/data/adb/magisk/busybox
|
||||||
|
|
||||||
|
# LD_LIBRARY_PATH for NDK
|
||||||
|
export LD_LIBRARY_PATH=/system/lib64:/data/adb/zerotier/lib
|
||||||
|
|
||||||
|
__start() {
|
||||||
|
nohup $ZTROOT/zerotier-one -d &>> $ZT_LOG &
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user