From c75818fcfe5c46ded9e5fa71a47058195307888b Mon Sep 17 00:00:00 2001 From: dovela <33590269+dovela@users.noreply.github.com> Date: Sat, 30 Jun 2018 15:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=88=86=E7=A6=BB=E4=B8=80=E9=94=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 27 +++++++ ServerStatus1Click.sh | 170 ++++++++++++++++++++++++++++++++++++++++++ run.sh | 3 + 3 files changed, 200 insertions(+) create mode 100644 README.md create mode 100644 ServerStatus1Click.sh create mode 100644 run.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..9ff6a0f --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# ServerStatus1Click + +## 说明 +客户端源码fork自@cppla,一键脚本自制 +
ServerStatus客户端的一键安装脚本,只需输入必要数据即可全自动安装并启动,脚本只需运行一次。 +
脚本在centos7上测试通过,其他发行版未测试。 +
理论上其他版本linux也可使用,请测试通过后提issue,谢谢。 +
欢迎star、fork,本脚本不定时更新,不定时从@cppla处合并新版本ServerStatus源码。 +
不支持window各版本 + +## 使用教程 +```` +wget -N --no-check-certificate https://raw.githubusercontent.com/dovela/ServerStatus/master/ServerStatus1Click.sh +chmod +x ServerStatus1Click.sh +./ServerStatus1Click.sh +```` + +## 其他 +默认远程端口35601,安装依赖选项为安装git、lsof、psutil,建议执行一次 + +## 特别感谢 +* cppla's ServerStatus: https://github.com/cppla/ServerStatus +* ServerStatus: https://github.com/BotoX/ServerStatus +* mojeda: https://github.com/mojeda +* mojeda's ServerStatus: https://github.com/mojeda/ServerStatus +* BlueVM's project: http://www.lowendtalk.com/discussion/comment/169690#Comment_169690 +* 参考了ToyoDAdoubi的一键脚本: https://github.com/ToyoDAdoubi/doubi diff --git a/ServerStatus1Click.sh b/ServerStatus1Click.sh new file mode 100644 index 0000000..a57abb1 --- /dev/null +++ b/ServerStatus1Click.sh @@ -0,0 +1,170 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +#================================================= +# System Required: CentOS 6+/Debian 6+/Ubuntu 14.04+/others(test) +# Description: Auto-install the ServerStatus Client +# Version: 1.1.1 +# Author: dovela +#================================================= + +file="/home/ServerStatus" +status_linux="/home/ServerStatus/clients/client-linux.py" +status_psutil="/home/ServerStatus/clients/client-psutil.py" +client_log_file="/home/ServerStatus/client.log" + +check_pid(){ + PID=`lsof -i:$(awk '{if($0~"PORT") print}' ${status_linux} | awk '{print $3}' | head -n 1) |awk '{print $2}' | tail -n 1` +} + +get_para(){ + server=`awk '{if($0~"SERVER") print}' ${status_linux} | sed 's/"/ /g' | awk '{print $3}' | head -n 1` + port=`awk '{if($0~"PORT") print}' ${status_linux} | awk '{print $3}' | head -n 1` + user=`awk '{if($0~"USER") print}' ${status_linux} | sed 's/"/ /g' | awk '{print $3}' | head -n 1` + passwd=`awk '{if($0~"PASSWORD") print}' ${status_linux} | sed 's/"/ /g' | awk '{print $3}' | head -n 1` + p_server=`awk '{if($0~"SERVER") print}' ${status_psutil} | sed 's/"/ /g' | awk '{print $3}' | head -n 1` + p_port=`awk '{if($0~"PORT") print}' ${status_psutil} | awk '{print $3}' | head -n 1` + p_user=`awk '{if($0~"USER") print}' ${status_psutil} | sed 's/"/ /g' | awk '{print $3}' | head -n 1` + p_passwd=`awk '{if($0~"PASSWORD") print}' ${status_psutil} | sed 's/"/ /g' | awk '{print $3}' | head -n 1` +} + +check_sys(){ + if [[ -f /etc/redhat-release ]]; then + release="centos" + elif cat /etc/issue | grep -q -E -i "debian"; then + release="debian" + elif cat /etc/issue | grep -q -E -i "ubuntu"; then + release="ubuntu" + elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then + release="centos" + elif cat /proc/version | grep -q -E -i "debian"; then + release="debian" + elif cat /proc/version | grep -q -E -i "ubuntu"; then + release="ubuntu" + elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then + release="centos" + fi + bit=`uname -m` +} + +centos_yum(){ + yum install -y epel-release && yum clean all && yum update + yum install -y git lsof python-pip gcc python-devel +} + +debian_apt(){ + apt-get install -y git lsof python-setuptools python-dev build-essential python-pip +} + +install_sss(){ + clear + stty erase '^H' && read -p " 服务端地址:" sserver + stty erase '^H' && read -p " 远程端口(默认35601):" sport + [[ -z ${sport} ]] && sport="35601" + stty erase '^H' && read -p " 客户端username:" suser + stty erase '^H' && read -p " 客户端password:" spasswd + clear + cd /home && git clone https://github.com/cppla/ServerStatus.git && cd ServerStatus && rm -rf ServerStatus1Click.sh + echo 'ServerStatus客户端安装完成' + get_para + sed -i -e "s/${server}/${sserver}/g" ${status_linux} + sed -i -e "s/${port}/${sport}/g" ${status_linux} + sed -i -e "s/${user}/${suser}/g" ${status_linux} + sed -i -e "s/${passwd}/${spasswd}/g" ${status_linux} + sed -i -e "s/${p_server}/${sserver}/g" ${status_psutil} + sed -i -e "s/${p_port}/${sport}/g" ${status_psutil} + sed -i -e "s/${p_user}/${suser}/g" ${status_psutil} + sed -i -e "s/${p_passwd}/${spasswd}/g" ${status_psutil} + clear + echo ' ServerStatus客户端配置完成,请进行下一步' + echo ' 1. 运行 client-linux' + echo ' 2. 运行 client-psutil' + stty erase '^H' && read -p " 请输入数字 [1-2]:" num + case "$num" in + 1) + run_linux + ;; + 2) + run_psutil + ;; +esac +} + +delete_sss(){ + check_pid + [[ ! -z ${PID} ]] && kill -9 ${PID} + rm -rf ${file} + echo -e 'ServerStatus客户端已卸载!' +} + +run_linux(){ + check_pid + [[ ! -z ${PID} ]] && echo -e 'ServerStatus 客户端运行中!' && exit 1 + nohup python ${status_linux} > ${client_log_file} 2>&1 & + echo -e 'ServerStatus-linux客户端已开始运行' +} + +run_psutil(){ + check_pid + [[ ! -z ${PID} ]] && echo -e 'ServerStatus 客户端运行中!' && exit 1 + nohup python ${status_psutil} > ${client_log_file} 2>&1 & + echo -e 'ServerStatus-psutil客户端已开始运行' +} + +stop_client(){ + check_pid + [[ -z ${PID} ]] && echo -e "Error, ServerStatus 客户端没有运行 !" && exit 1 + kill -9 ${PID} +} + +install_env(){ + clear + if [[ ${release} == "centos" ]]; then + centos_yum + else + debian_apt + fi + pip install --upgrade + pip install psutil + echo '依赖环境安装完成,请再次运行脚本' +} + + clear +check_sys +[ $(id -u) != "0" ] && echo -e "Error: You must be root to run this script" && exit 1 +echo -e " 出现问题请在 https://github.com/dovela/ServerStatus1Click 处提issue +———————————— + 1.首次安装并启动 ServerStatus客户端 + 2.运行 client_linux + 3.运行 client_psutil + 4.停止运行 + 5.首次安装linux依赖,直接安装失败请执行 + 6.卸载ServerStatus +———————————— + 输入数字开始,或ctrl + c退出 +" +echo && stty erase '^H' && read -p " 请输入数字[1-6]:" num + case "$num" in + 1) + install_sss + ;; + 2) + run_linux + ;; + 3) + run_psutil + ;; + 4) + stop_client + ;; + 5) + install_env + ;; + 6) + delete_sss + ;; + *) + echo -e "Error,请输入正确的数字 [1-6]!" + ;; +esac diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..5fbaeac --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +kill -9 $(lsof -i:35601 |awk '{print $2}' | tail -n 1) +nohup ./server/sergate --config=server/config.json --web-dir=$(dirname $0 | pwd)/web/ >> run.log 2>&1 & +cd ..