From 9b1059acbd0a2054989d14baecb90876eaca4a39 Mon Sep 17 00:00:00 2001 From: eventlOwOp <3064273390@qq.com> Date: Tue, 2 Jul 2024 13:12:35 +0800 Subject: [PATCH] rewrite restart logic --- magisk/handle.sh | 29 ++++++++++++++--------------- magisk/service.sh | 5 +---- magisk/vars.sh | 9 ++++++++- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/magisk/handle.sh b/magisk/handle.sh index 8ad19b9..5aea745 100644 --- a/magisk/handle.sh +++ b/magisk/handle.sh @@ -5,9 +5,6 @@ MODDIR=${0%/*} # load variables . $MODDIR/vars.sh -# LD_LIBRARY_PATH for NDK -export LD_LIBRARY_PATH=/system/lib64:/data/adb/zerotier/lib - log_cli() { echo -e "$1" >> $ZTROOT/run/cli.out } @@ -29,33 +26,35 @@ _stop() { return fi - wait - sleep 1 # sometimes it fails without sleeping - log "stopped zerotier-one" } _start() { - if pid=`pidof zerotier-one`; then - log "zerotier-one already running pid $pid" + if pidof zerotier-one > /dev/null; then + log "zerotier-one already running" else - $ZTROOT/zerotier-one -d >> $ZT_LOG 2>&1 & - pid=`pidof zerotier-one` - log "started zerotier-one pid $pid" + __start + log "started zerotier-one" fi } _status() { # 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 " Active: \033[32mactive (running)\033[0m" log_cli " Main PID: $pid (zerotier-one)" else - read pid_ < $ZTROOT/home/zerotier-one.pid log_cli "○ zerotier-one.service - ZeroTier One - Global Area Networking" log_cli " Active: inactive (dead)" - log_cli " Main PID: $pid_ (code=exited)" + log_cli " Main PID: $pid (code=exited)" fi } +_restart() { + _stop + __start + log "started zerotier-one" +} # ---------------------------------------------- # call from inotifyd @@ -68,7 +67,7 @@ if [[ $# == 2 && "$1" == "w" ]]; then case "$cmd" in "start") _start;; "stop") _stop;; - "restart") _stop; _start;; + "restart") _restart;; "status") _status;; *) log "unknown command $cmd";; esac diff --git a/magisk/service.sh b/magisk/service.sh index 639228b..64a81bf 100644 --- a/magisk/service.sh +++ b/magisk/service.sh @@ -37,11 +37,8 @@ mkdir -p $ZTROOT/run ip 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 -$ZTROOT/zerotier-one -d >> $ZT_LOG 2>&1 & +__start # ---------------------------------------------- # CLI before login diff --git a/magisk/vars.sh b/magisk/vars.sh index cc9ca63..f9a57d3 100644 --- a/magisk/vars.sh +++ b/magisk/vars.sh @@ -9,4 +9,11 @@ DAEMON_LOG=$ZTROOT/run/daemon.log PIPE_CLI=$ZTROOT/run/pipe PIPE_APP=$APPROOT/run/pipe -BB=/data/adb/magisk/busybox \ No newline at end of file +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 & +} \ No newline at end of file