From 9806c42c94f414073ace1ca088161c5f8dd51d31 Mon Sep 17 00:00:00 2001 From: 233boy <31657650+233boy@users.noreply.github.com> Date: Mon, 25 Mar 2019 18:33:07 +0800 Subject: [PATCH] update status check and bbr check --- install.sh | 11 +++--- src/bbr.sh | 7 +++- src/mtproto.sh | 4 ++ src/socks.sh | 4 ++ src/ss-info.sh | 6 ++- src/status.sh | 19 +++++++--- src/v2ray-info.sh | 8 +++- v2ray.sh | 94 +++++++++++++++++------------------------------ 8 files changed, 79 insertions(+), 74 deletions(-) diff --git a/install.sh b/install.sh index 4b4d7d8..af7a696 100755 --- a/install.sh +++ b/install.sh @@ -872,6 +872,9 @@ config() { systemctl restart v2ray backup_config + ## check status + _load status.sh + _check_status } backup_config() { @@ -955,8 +958,6 @@ show_config_info() { _v2_args _v2_info _load ss-info.sh - _load status.sh - _check_status } _install() { @@ -991,13 +992,13 @@ _install() { fi fi [[ $caddy ]] && install_caddy - get_ip - config ## bbr _load bbr.sh - _open_bbr + _try_enable_bbr + get_ip + config show_config_info } diff --git a/src/bbr.sh b/src/bbr.sh index f81654b..e51a828 100644 --- a/src/bbr.sh +++ b/src/bbr.sh @@ -4,14 +4,17 @@ _open_bbr() { echo "net.ipv4.tcp_congestion_control = bbr" >>/etc/sysctl.conf echo "net.core.default_qdisc = fq" >>/etc/sysctl.conf sysctl -p >/dev/null 2>&1 + echo + _green "..由于你的 VPS 内核支持开启 BBR ...已经为你启用 BBR 优化...." + echo } -_kernel_ver() { +_try_enable_bbr() { local _test1=$(uname -r | cut -d\. -f1) local _test2=$(uname -r | cut -d\. -f2) if [[ $_test1 -eq 4 && $_test2 -ge 9 ]] || [[ $_test1 -ge 5 ]]; then _open_bbr + enable_bbr=true fi } -_kernel_ver diff --git a/src/mtproto.sh b/src/mtproto.sh index a1f940f..cfc22e8 100644 --- a/src/mtproto.sh +++ b/src/mtproto.sh @@ -6,6 +6,10 @@ _view_mtproto_info() { fi } _mtproto_info() { + if [[ ! $v2ray_pid ]]; then + _load status.sh + _err_msg + fi [[ -z $ip ]] && get_ip echo echo "---------- Telegram MTProto 配置信息 -------------" diff --git a/src/socks.sh b/src/socks.sh index 08268fe..4adeaa6 100644 --- a/src/socks.sh +++ b/src/socks.sh @@ -6,6 +6,10 @@ _view_socks_info() { fi } _socks_info() { + if [[ ! $v2ray_pid ]]; then + _load status.sh + _err_msg + fi [[ -z $ip ]] && get_ip echo echo "---------- Socks 配置信息 -------------" diff --git a/src/ss-info.sh b/src/ss-info.sh index aa7e10d..7cb6b0b 100644 --- a/src/ss-info.sh +++ b/src/ss-info.sh @@ -1,3 +1,7 @@ +if [[ ! $v2ray_pid ]]; then + _load status.sh + _err_msg +fi [[ -z $ip ]] && get_ip if [[ $shadowsocks ]]; then #local ss="ss://$(echo -n "${ssciphers}:${sspass}@${ip}:${ssport}" | base64 -w 0)#${_site}_ss_${ip}" @@ -40,6 +44,6 @@ if [[ $shadowsocks ]]; then echo -e "$yellow SS + V2ray - Plugin 链接 = ${cyan}${ssplugin}$none" echo fi - echo -e "提示: 输入$cyan v2ray ssqr $none可生成 Shadowsocks 二维码链接" + echo -e "提示: 输入$cyan v2ray ssqr $none可生成 Shadowsocks 二维码链接" echo fi diff --git a/src/status.sh b/src/status.sh index e5bf98f..15ca5dd 100644 --- a/src/status.sh +++ b/src/status.sh @@ -1,10 +1,19 @@ _check_status() { sleep 2 if [[ ! $(pgrep -f /usr/bin/v2ray/v2ray) ]]; then - echo - _red "警告!!! V2Ray 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - _red "警告!!! V2Ray 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - _red "警告!!! V2Ray 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - echo + _err_msg fi + if [[ $v2ray_transport == [45] && $caddy ]] && [[ ! $(pgrep -f /usr/bin/v2ray/v2ray) ]]; then + _err_msg "Caddy" + fi +} +_err_msg() { + local str=$1 + [[ -z $1 ]] && local str="V2Ray" + echo + _red "警告!!! $str 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" + _red "警告!!! $str 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" + _red "警告!!! $str 运行出错!!!! 请检查端口是否冲突!!! 配置是否正确!!!!" + echo + exit 1 } diff --git a/src/v2ray-info.sh b/src/v2ray-info.sh index 504f6a1..42cbc12 100644 --- a/src/v2ray-info.sh +++ b/src/v2ray-info.sh @@ -71,6 +71,13 @@ _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 [[ -z $ip ]] && get_ip echo echo @@ -132,7 +139,6 @@ _v2_info() { echo " 备注: 广告拦截已开启.." echo fi - echo "---------- END -------------" echo echo "V2Ray 客户端使用教程: https://${_site}/post/4/" diff --git a/v2ray.sh b/v2ray.sh index 3697702..ed97a68 100755 --- a/v2ray.sh +++ b/v2ray.sh @@ -2318,34 +2318,30 @@ v2ray_service() { done } start_v2ray() { - if [[ $v2ray_pid ]]; then + if [[ $v2ray_pid ]] || [[ $v2ray_transport == [45] && $caddy ]] && [[ $caddy_pid ]]; then echo echo -e "${green} V2Ray 正在运行...无需再启动$none" echo else - - # systemctl start v2ray - service v2ray start >/dev/null 2>&1 + systemctl start v2ray + if [[ $v2ray_transport == [45] && $caddy ]] && [[ ! $caddy_pid ]]; then + systemctl start caddy + fi echo echo '正在启动....' echo - sleep 3 - if [[ ! $(pgrep -f /usr/bin/v2ray/v2ray) ]]; then - echo - _red "警告!!! V2Ray 启动失败!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - echo - else - echo - _green " V2Ray 启动成功!!!!" - echo - fi + _load status.sh + _check_status + echo + _green " V2Ray 启动成功!!!!" + echo fi + } stop_v2ray() { if [[ $v2ray_pid ]]; then - # systemctl stop v2ray - service v2ray stop >/dev/null 2>&1 + systemctl stop v2ray echo echo -e "${green} V2Ray 已停止$none" echo @@ -2356,21 +2352,17 @@ stop_v2ray() { fi } restart_v2ray() { - # systemctl restart v2ray - service v2ray restart >/dev/null 2>&1 + systemctl restart v2ray + [[ $v2ray_transport == [45] && $caddy ]] && systemctl restart caddy echo echo '正在重启....' echo - sleep 3 - if [[ ! $(pgrep -f /usr/bin/v2ray/v2ray) ]]; then - echo - _red "警告!!! V2Ray 重启失败!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - echo - else - echo - _green " V2Ray 重启成功!!!!" - echo - fi + _load status.sh + _check_status + echo + _green " V2Ray 重启成功!!!!" + echo + } view_v2ray_log() { echo @@ -2639,30 +2631,14 @@ other() { install_bbr() { local test1=$(sed -n '/net.ipv4.tcp_congestion_control/p' /etc/sysctl.conf) local test2=$(sed -n '/net.core.default_qdisc/p' /etc/sysctl.conf) - if [[ $(uname -r | cut -b 1) -eq 4 ]]; then - case $(uname -r | cut -b 3-4) in - 9. | [1-9][0-9]) - if [[ $test1 == "net.ipv4.tcp_congestion_control = bbr" && $test2 == "net.core.default_qdisc = fq" ]]; then - local is_bbr=true - else - local try_enable_bbr=true - fi - ;; - esac - fi - if [[ $is_bbr ]]; then + if [[ $test1 == "net.ipv4.tcp_congestion_control = bbr" && $test2 == "net.core.default_qdisc = fq" ]]; then echo echo -e "$green BBR 已经启用啦...无需再安装$none" echo - elif [[ $try_enable_bbr ]]; then - _load bbr.sh - _open_bbr - echo - echo -e "$green ..由于你的 VPS 内核支持开启 BBR ...已经为你启用 BBR 优化....$none" - echo else - # https://teddysun.com/489.html - bash <(curl -s -L https://github.com/teddysun/across/raw/master/bbr.sh) + _load bbr.sh + _try_enable_bbr + [[ ! $enable_bbr ]] && bash <(curl -s -L https://github.com/teddysun/across/raw/master/bbr.sh) fi } install_lotserver() { @@ -2775,7 +2751,11 @@ config() { [[ $(command -v apache2) ]] && apt-get remove apache2* -y >/dev/null 2>&1 fi fi - do_service restart v2ray + systemctl restart v2ray + + ## check status + _load status.sh + _check_status } backup_config() { _load backup.sh @@ -3010,21 +2990,15 @@ stop) stop_v2ray ;; restart) - [[ $v2ray_transport == [45] && $caddy ]] && do_service restart caddy restart_v2ray ;; reload) - config [[ $v2ray_transport == [45] && $caddy ]] && caddy_config - if [[ ! $(pgrep -f /usr/bin/v2ray/v2ray) ]]; then - echo - _red "警告!!! V2Ray 加载失败!!! 请检查端口是否冲突!!! 配置是否正确!!!!" - echo - else - echo - _green " V2Ray 加载成功!!! 如需查看 V2Ray 配置请使用 v2ray info" - echo - fi + config + echo + _green " V2Ray 加载成功!!! 如需查看 V2Ray 配置请使用 v2ray info" + echo + ;; time) _load sys-info.sh