From b061c9a56123263f8d2e6645926c81c2e0e83778 Mon Sep 17 00:00:00 2001 From: 233boy <31657650+233boy@users.noreply.github.com> Date: Mon, 25 Mar 2019 19:34:09 +0800 Subject: [PATCH] optimate status check --- src/client_file.sh | 2 ++ src/mtproto.sh | 6 ++---- src/qr.sh | 2 ++ src/socks.sh | 6 ++---- src/ss-info.sh | 6 ++---- src/status.sh | 19 ++++++++++++++++--- src/v2ray-info.sh | 9 ++------- v2ray.sh | 5 +++++ 8 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/client_file.sh b/src/client_file.sh index ea2c5cb..f323064 100644 --- a/src/client_file.sh +++ b/src/client_file.sh @@ -1,3 +1,5 @@ +_load status.sh +_get_status _get_client_file() { local _link="$(cat $v2ray_client_config | tr -d [:space:] | base64 -w0)" local link="https://233boy.github.io/tools/json.html#${_link}" diff --git a/src/mtproto.sh b/src/mtproto.sh index cfc22e8..2c61c3e 100644 --- a/src/mtproto.sh +++ b/src/mtproto.sh @@ -6,10 +6,8 @@ _view_mtproto_info() { fi } _mtproto_info() { - if [[ ! $v2ray_pid ]]; then - _load status.sh - _err_msg - fi + _load status.sh + _get_status [[ -z $ip ]] && get_ip echo echo "---------- Telegram MTProto 配置信息 -------------" diff --git a/src/qr.sh b/src/qr.sh index 794ce03..0a3d285 100644 --- a/src/qr.sh +++ b/src/qr.sh @@ -1,3 +1,5 @@ +_load status.sh +_get_status _qr_create() { local vmess="vmess://$(cat /etc/v2ray/vmess_qr.json | base64 -w 0)" local link="https://233boy.github.io/tools/qr.html#${vmess}" diff --git a/src/socks.sh b/src/socks.sh index 4adeaa6..fbddc6c 100644 --- a/src/socks.sh +++ b/src/socks.sh @@ -6,10 +6,8 @@ _view_socks_info() { fi } _socks_info() { - if [[ ! $v2ray_pid ]]; then - _load status.sh - _err_msg - fi + _load status.sh + _get_status [[ -z $ip ]] && get_ip echo echo "---------- Socks 配置信息 -------------" diff --git a/src/ss-info.sh b/src/ss-info.sh index 7cb6b0b..2622540 100644 --- a/src/ss-info.sh +++ b/src/ss-info.sh @@ -1,7 +1,5 @@ -if [[ ! $v2ray_pid ]]; then - _load status.sh - _err_msg -fi +_load status.sh +_get_status [[ -z $ip ]] && get_ip if [[ $shadowsocks ]]; then #local ss="ss://$(echo -n "${ssciphers}:${sspass}@${ip}:${ssport}" | base64 -w 0)#${_site}_ss_${ip}" diff --git a/src/status.sh b/src/status.sh index ef3bba6..594459d 100644 --- a/src/status.sh +++ b/src/status.sh @@ -1,19 +1,32 @@ _check_status() { sleep 2 + unset v2ray_pid if [[ ! $(pgrep -f /usr/bin/v2ray/v2ray) ]]; then _err_msg + else + v2ray_pid=true fi + unset caddy_pid if [[ $v2ray_transport == [45] && $caddy ]] && [[ ! $(pgrep -f /usr/local/bin/caddy) ]]; then _err_msg "Caddy" + else + caddy_pid=true + fi +} +_get_status() { + if [[ ! $v2ray_pid ]]; then + _err_msg + elif [[ $v2ray_transport == [45] && $caddy ]] && [[ ! $caddy_pid ]]; then + _err_msg "Caddy" fi } _err_msg() { local str=$1 [[ -z $1 ]] && local str="V2Ray" echo - _red "警告!!! $str 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - _red "警告!!! $str 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - _red "警告!!! $str 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" + _red "警告!!! $str 运行出错!!! 或没有在运行!!!! 请检查!!!!" + _red "警告!!! $str 运行出错!!! 或没有在运行!!!! 请检查!!!!" + _red "警告!!! $str 运行出错!!! 或没有在运行!!!! 请检查!!!!" echo exit 1 } diff --git a/src/v2ray-info.sh b/src/v2ray-info.sh index 42cbc12..5acb4f8 100644 --- a/src/v2ray-info.sh +++ b/src/v2ray-info.sh @@ -71,13 +71,8 @@ _v2_args() { } _v2_info() { - if [[ ! $v2ray_pid ]]; then - _load status.sh - _err_msg - elif [[ $v2ray_transport == [45] && $caddy ]] && [[ ! $caddy_pid ]]; then - _load status.sh - _err_msg "Caddy" - fi + _load status.sh + _get_status [[ -z $ip ]] && get_ip echo echo diff --git a/v2ray.sh b/v2ray.sh index ed97a68..2e7b49b 100755 --- a/v2ray.sh +++ b/v2ray.sh @@ -2559,6 +2559,9 @@ get_v2ray_config_qr_link() { } get_v2ray_multi_vmess_URL_QR() { + + _load status.sh + _get_status echo "---------- V2Ray vmess URL / V2RayNG v0.4.1+ / V2RayN v2.1+ / 仅适合部分客户端 -------------" get_ip _load jqcmd.sh @@ -2571,6 +2574,8 @@ get_v2ray_multi_vmess_URL_QR() { get_v2ray_vmess_URL_link() { + _load status.sh + _get_status echo echo "---------- V2Ray vmess URL / V2RayNG v0.4.1+ / V2RayN v2.1+ / 仅适合部分客户端 -------------" get_ip