From 68ce50e031352802fbc7bca431f783fbf75304f0 Mon Sep 17 00:00:00 2001 From: frankiejun Date: Tue, 13 Aug 2024 16:21:16 +0200 Subject: [PATCH] fixed --- keepalive.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/keepalive.sh b/keepalive.sh index 38c71b7..f0056bd 100755 --- a/keepalive.sh +++ b/keepalive.sh @@ -2,6 +2,8 @@ installpath="$HOME" +#返回0表示成功, 1表示失败 +#在if条件中,0会执行,1不会执行 checkvlessAlive() { if ps aux | grep app.js | grep -v "grep"; then return 0 @@ -13,22 +15,21 @@ checkvlessAlive() { checkvmessAlive() { local c=0 if ps aux | grep web.js | grep -v "grep" >/dev/null; then - ((c + 1)) + c=$((c + 1)) fi if ps aux | grep cloud | grep -v "grep" >/dev/null; then - ((c + 1)) + c=$((c + 1)) fi if ps aux | grep server.js | grep -v "grep" >/dev/null; then - ((c + 1)) + c=$((c + 1)) fi echo "c=$c" if [ $c -eq 3 ]; then - return 1 + return 0 fi - - return 0 # 有一个或多个进程不在运行 + return 1 # 有一个或多个进程不在运行 } @@ -38,24 +39,25 @@ if [ ! -f config.json ]; then echo "未配置保活项目,请先行配置!" >>a.log exit 0 fi -monitor=$(jq -r ".item[]" config.json) +monitor=($(jq -r ".item[]" config.json)) for obj in "${monitor[@]}"; do if [ "$obj" == "vless" ]; then - if ! checkvlessAlive; then + if ! checkvlessAlive ; then cd ${installpath}/serv00-play/vless if ! ./start.sh; then - echo "RESPONSE:vless restarts failure." + echo "RESPONSE:vless restarted failure." else - echo "RESPONSE:vless restarts successfully." + echo "RESPONSE:vless restarted successfully." fi fi elif [ "$obj" == "vmess" ]; then - if ! checkvmessAlive; then + if ! checkvmessAlive ; then cd ${installpath}/serv00-play/vmess + echo "start vmess" if ! ./start.sh; then - echo "vmess restarts failure." + echo "RESPONSE:vmess restarted failure." else - echo "vmess restarts successfully." + echo "RESPONSE:vmess restarted successfully." fi fi fi