目录
1.背景
服务在新环境上部署,服务多,配置多,导致运维人员部署困难、耗时,因此使用脚本自动化部署,方便快速搭建部署。
以下脚本案例支持自动化安装、启动、停止、检查服务状态、重启特定服务、卸载、supervisor监控页面等功能。
这里编写此文的目的主要为了总结,方便后续使用。
2.解压
# tar -zxvf HuaShan.tar.gz (这里你可以写个压缩脚本,解压完毕后,调用里面的install.sh,顺序调用其它脚本)
解压后目录结构为:
bin 源服务位置
checkState.sh 服务运行状态脚本
func 页面脚本公共方法
function Golang脚本公共方法
install.sh 安装脚本
restart.sh 重启脚本
start.sh 启动脚本
stop.sh 停止脚本
uninstall.sh 卸载脚本
3. function
#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
#安装服务类型
installType='0'
#服务路径
TagPath="TagServer"
AlarmPath="AlarmServer"
WhiteListDistributePath="WhitelistDistributeService"
ListDistributePath="LibraryDistributeUniversalService"
PlatformInfoManagerPath="PlatformInfoManager"
ListStorePath="StoreListLibraryServer"
FerrySendPath="FerrySendServer"
FerryRecvPath="FerryRecvServer"
SubscribeDataPath="WhiteListSubscribeSvr"
VCNOpenDoorPath="VCNOpenDoorSvr"
VCNDeviceGainerPath="VCNDeviceGainer"
WebPath="web"
#服务名
TagServer="TagServer"
AlarmServer="AlarmServer"
WhitelistDistributeService="WhitelistDistributeService"
LibraryDistributeUniversalService="LibraryDistributeUniversalService"
PlatformInfoManager="PlatformInfoManager"
StoreListLibraryServer="StoreListLibraryServer"
FerrySendServer="FerrySendServer"
FerryRecvServer="FerryRecvServer"
WhiteListSubscribeSvr="WhiteListSubscribeSvr"
VCNOpenDoorSvr="VCNOpenDoorSvr"
VCNDeviceGainerSvr="VCNDeviceGainer"
web="web"
function InitIcvRoot()
{
# 检查是否已经初始化过ICV_ROOT
res=`echo ${ICV_ROOT}`
if [ ! -n "$res" ]; then
echo "*配置环境变量ICV_ROOT未设置"
# 初始化环境变量
\cp -r bin/ICV_ROOT /home
echo "export ICV_ROOT=/home/ICV_ROOT" >> ~/.bash_profile
source ~/.bash_profile
else
echo "ICV_ROOT环境变量已经设置:" ${res}
echo "*重置ICV_ROOT环境变量"
sed -i '/export ICV_ROOT=/d' ~/.bash_profile
rm -rf ${res}
# 初始化环境变量
\cp -r bin/ICV_ROOT /home
echo "export ICV_ROOT=/home/ICV_ROOT" >> ~/.bash_profile
source ~/.bash_profile
fi
}
# Tag服务
function installTagSvr()
{
echo "*安装Tag服务"
\cp -r bin/TagServer TagServer
}
# Alarm服务
function installAlarmSvr()
{
echo "*安装Alarm服务"
\cp -r bin/AlarmServer AlarmServer
}
# WhiteListDistribute服务
function installWhiteListDistributeSvr()
{
echo "*安装白名单数据接收服务"
\cp -r bin/WhitelistDistributeService WhitelistDistributeService
}
# ListDistribute服务
function installListDistributeSvr()
{
echo "*安装ListDistribute服务"
\cp -r bin/LibraryDistributeUniversalService LibraryDistributeUniversalService
}
# 平台信息管理服务
function installPlatformInfoManager()
{
echo "*平台信息管理服务"
\cp -r bin/PlatformInfoManager PlatformInfoManager
}
# ListStore服务
function installListStoreSvr()
{
echo "*安装名单库存储服务"
\cp -rf bin/StoreListLibraryServer StoreListLibraryServer
}
# 摆渡发送服务
function installFerrySendSvr()
{
echo "*安装摆渡发送服务"
\cp -r bin/FerrySendServer FerrySendServer
}
# 摆渡接收服务
function installFerryRecvSvr()
{
echo "*安装摆渡接收服务"
\cp -r bin/FerryRecvServer FerryRecvServer
}
# 白名单订阅服务
function installSubscribeData()
{
echo "*安装白名单订阅服务"
\cp -r bin/WhiteListSubscribeSvr WhiteListSubscribeSvr
}
# 开门信息下发服务
function installVCNOpenDoorSvr()
{
echo "*安装开门信息下发服务"
\cp -r bin/VCNOpenDoorSvr VCNOpenDoorSvr
}
# 设备列表获取服务
function installVCNDeviceGainer()
{
echo "*安装设备列表获取服务"
\cp -r bin/VCNDeviceGainer VCNDeviceGainer
}
# 打标签服务
function startTagSvr()
{
echo "=========================="
echo "**启动打标签服务开始"
chmod +x ./TagServer/TagServer
nohup ./TagServer/TagServer >/dev/null 2>&1 &
pid=`ps -ef | grep TagServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**打标签服务启动失败 \033[0m"
else
echo "**打标签服务启动成功,pid=${pid}"
fi
echo "**启动打标签服务结束"
}
function stopTagSvr()
{
#echo "**停止打标签服务开始**"
pid=`ps -ef | grep TagServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**打标签服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep TagServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**打标签服务停止成功**"
else
echo -e "\033[31m**打标签服务停止失败** \033[0m"
fi
fi
}
# 告警服务
function startAlarmSvr()
{
echo "=========================="
echo "**启动告警服务开始"
chmod +x ./AlarmServer/AlarmServer
nohup ./AlarmServer/AlarmServer >/dev/null 2>&1 &
pid=`ps -ef | grep AlarmServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**告警服务启动失败 \033[0m"
else
echo "**告警服务启动成功,pid=${pid}"
fi
echo "**启动告警服务结束"
}
function stopAlarmSvr()
{
#echo "**停止告警服务开始**"
pid=`ps -ef | grep AlarmServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**告警服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep AlarmServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**告警服务停止成功**"
else
echo -e "\033[31m**告警服务停止失败** \033[0m"
fi
fi
}
# 白名单分发服务
function startWhiteListDistributeSvr()
{
echo "=========================="
echo "**启动白名单分发服务开始"
chmod +x ./WhitelistDistributeService/WhitelistDistributeService
nohup ./WhitelistDistributeService/WhitelistDistributeService >/dev/null 2>&1 &
pid=`ps -ef | grep WhitelistDistributeService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**白名单分发服务启动失败 \033[0m"
else
echo "**白名单分发服务启动成功,pid=${pid}"
fi
echo "**启动白名单分发服务结束"
}
function stopWhiteListDistributeSvr()
{
#echo "**停止白名单分发服务开始**"
pid=`ps -ef | grep WhitelistDistributeService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**白名单分发服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep WhitelistDistributeService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**白名单分发服务停止成功**"
else
echo -e "\033[31m**白名单分发服务停止失败** \033[0m"
fi
fi
}
# 名单库分发服务
function startListDistributeSvr()
{
echo "=========================="
echo "**启动名单库分发服务开始"
chmod +x ./LibraryDistributeUniversalService/LibraryDistributeUniversalService
nohup ./LibraryDistributeUniversalService/LibraryDistributeUniversalService >/dev/null 2>&1 &
pid=`ps -ef | grep LibraryDistributeUniversalService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**名单库分发服务启动失败 \033[0m"
else
echo "**名单库分发服务启动成功,pid=${pid}"
fi
echo "**启动名单库分发服务结束"
}
function stopListDistributeSvr()
{
#echo "**停止名单库分发服务开始**"
pid=`ps -ef | grep LibraryDistributeUniversalService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**名单库分发服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep LibraryDistributeUniversalService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**名单库分发服务停止成功**"
else
echo -e "\033[31m**名单库分发服务停止失败** \033[0m"
fi
fi
}
# 名单库存储服务
function startListStoreSvr()
{
echo "=========================="
echo "**启动名单库存储服务开始"
chmod +x ./StoreListLibraryServer/StoreListLibraryServer
nohup ./StoreListLibraryServer/StoreListLibraryServer >/dev/null 2>&1 &
pid=`ps -ef | grep StoreListLibraryServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**名单库存储服务启动失败 \033[0m"
else
echo "**名单库存储服务启动成功,pid=${pid}"
fi
echo "**启动名单库存储服务结束"
}
function stopListStoreSvr()
{
#echo "**停止名单库存储服务开始**"
pid=`ps -ef | grep StoreListLibraryServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**名单库存储服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep StoreListLibraryServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**名单库存储服务停止成功**"
else
echo -e "\033[31m**名单库存储服务停止失败** \033[0m"
fi
fi
}
# 平台信息管理服务
function startPlatformInfoManager()
{
echo "=========================="
echo "**启动平台信息管理服务开始"
chmod +x ./PlatformInfoManager/PlatformInfoManager
nohup ./PlatformInfoManager/PlatformInfoManager >/dev/null 2>&1 &
pid=`ps -ef | grep PlatformInfoManager | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**平台信息管理服务启动失败 \033[0m"
else
echo "**平台信息管理服务启动成功,pid=${pid}"
fi
echo "**启动平台信息管理服务结束"
}
function stopPlatformInfoManager()
{
#echo "**停止平台信息管理服务开始**"
pid=`ps -ef | grep PlatformInfoManager | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**平台信息管理服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep PlatformInfoManager | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**平台信息管理服务停止成功**"
else
echo -e "\033[31m**平台信息管理服务停止失败** \033[0m"
fi
fi
}
# 摆渡发送服务
function startFerrySendSvr()
{
echo "=========================="
echo "**启动摆渡发送服务开始"
chmod +x ./FerrySendServer/FerrySendServer
nohup ./FerrySendServer/FerrySendServer >/dev/null 2>&1 &
pid=`ps -ef | grep FerrySendServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**摆渡发送服务启动失败 \033[0m"
else
echo "**摆渡发送服务启动成功,pid=${pid}"
fi
echo "**启动摆渡发送服务结束"
}
function stopFerrySendSvr()
{
#echo "**停止摆渡发送服务开始**"
pid=`ps -ef | grep FerrySendServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**摆渡发送服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep FerrySendServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**摆渡发送服务停止成功**"
else
echo -e "\033[31m**摆渡发送服务停止失败** \033[0m"
fi
fi
}
# 摆渡接收服务
function startFerryRecvSvr()
{
echo "=========================="
echo "**启动摆渡接收服务开始"
chmod +x ./FerryRecvServer/FerryRecvServer
nohup ./FerryRecvServer/FerryRecvServer >/dev/null 2>&1 &
pid=`ps -ef | grep FerryRecvServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**摆渡接收服务启动失败 \033[0m"
else
echo "**摆渡接收服务启动成功,pid=${pid}"
fi
echo "**启动摆渡接收服务结束"
}
function stopFerryRecvSvr()
{
#echo "**停止摆渡接收服务开始**"
pid=`ps -ef | grep FerryRecvServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**摆渡接收服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep FerryRecvServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**摆渡接收服务停止成功**"
else
echo -e "\033[31m**摆渡接收服务停止失败** \033[0m"
fi
fi
}
# 白名单订阅服务
function startSubscribeData()
{
echo "=========================="
echo "**启动白名单订阅服务开始"
chmod +x ./WhiteListSubscribeSvr/WhiteListSubscribeSvr
cd WhiteListSubscribeSvr
nohup ./WhiteListSubscribeSvr >/dev/null 2>&1 &
sleep 2
pid=`ps -ef | grep WhiteListSubscribeSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**白名单订阅服务启动失败 \033[0m"
else
echo "**白名单订阅服务启动成功,pid=${pid}"
fi
cd ${basepath}
echo "**启动白名单订阅服务结束"
}
function stopSubscribeData()
{
#echo "**停止白名单订阅服务开始**"
pid=`ps -ef | grep WhiteListSubscribeSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**白名单订阅服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep WhiteListSubscribeSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**白名单订阅服务停止成功**"
else
echo -e "\033[31m**白名单订阅服务停止失败** \033[0m"
fi
fi
}
# 开门信息下发服务
function startVCNOpenDoorSvr()
{
echo "=========================="
cd ${basepath}
echo "**启动开门信息下发服务开始"
chmod +x ./VCNOpenDoorSvr/VCNOpenDoorSvr
cd VCNOpenDoorSvr
nohup ./VCNOpenDoorSvr >/dev/null 2>&1 &
pid=`ps -ef | grep VCNOpenDoorSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**开门信息下发服务启动失败 \033[0m"
else
echo "**开门信息下发服务启动成功,pid=${pid}"
fi
cd ${basepath}
echo "**启动开门信息下发服务结束"
}
function stopVCNOpenDoorSvr()
{
#echo "**停止开门信息下发服务开始**"
pid=`ps -ef | grep VCNOpenDoorSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**开门信息下发服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep VCNOpenDoorSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**开门信息下发服务停止成功**"
else
echo -e "\033[31m**开门信息下发服务停止失败** \033[0m"
fi
fi
}
# 设备列表获取服务
function startVCNDeviceGainer()
{
echo "=========================="
echo "**启动设备列表获取服务开始"
chmod +x ./VCNDeviceGainer/VCNDeviceGainer
cd VCNDeviceGainer
nohup ./VCNDeviceGainer >/dev/null 2>&1 &
pid=`ps -ef | grep VCNDeviceGainer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**设备列表获取服务启动失败 \033[0m"
else
echo "**设备列表获取服务启动成功,pid=${pid}"
fi
cd ..
echo "**启动设备列表获取服务结束"
}
function stopVCNDeviceGainer()
{
#echo "**停止设备列表获取服务开始**"
pid=`ps -ef | grep VCNDeviceGainer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**设备列表获取服务进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 1
pid1=`ps -ef | grep VCNDeviceGainer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**设备列表获取服务停止成功**"
else
echo -e "\033[31m**设备列表获取服务停止失败** \033[0m"
fi
fi
}
# 清除安装包
function clearInstall()
{
echo "*清除安装包"
#rm -rf bin
#rm -rf install.sh
}
# 安装supervisor
function installSupervisor()
{
echo "*安装supervisor"
cd /opt/HuaShan
mkdir Supervisor
cp -r bin/Supervisor/*.gz Supervisor/
cd Supervisor
#安装setuptools
tar -zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
if [ $? -ne 0 ]; then
echo "*安装setuptools失败"
return 1
fi
echo "*安装setuptools成功"
#安装meld3
cd /opt/HuaShan/Supervisor
tar -zxvf meld3-1.0.2.tar.gz
cd meld3-1.0.2
python setup.py install
if [ $? -ne 0 ]; then
echo "*安装meld3失败"
return 1
fi
echo "*安装meld3成功"
#安装supervisor
cd /opt/HuaShan/Supervisor
tar -zxvf supervisor-3.3.4.tar.gz
cd supervisor-3.3.4
python setup.py install
#验证supervisor安装是否成功
supervisorctl --help
if [ $? -ne 0 ]; then
echo "*安装supervisor失败"
return 1
fi
echo "*安装supervisor成功"
#创建文件夹和配置文件
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
mkdir /etc/supervisor/config.d
sed -i "s/\;\[include\]/\[include\]/g" /etc/supervisor/supervisord.conf
sed -i "s/;files = relative\/directory\/\*.ini/files = \/etc\/supervisor\/config.d\/\*.ini/g" /etc/supervisor/supervisord.conf
if [ $? -ne 0 ]; then
echo "*配置supervisor失败"
return 1
fi
echo "*配置supervisor成功"
#配置Web页面
echo "[inet_http_server]">> /etc/supervisor/supervisord.conf
echo "port=0.0.0.0:9001">> /etc/supervisor/supervisord.conf
echo "username=admin">> /etc/supervisor/supervisord.conf
echo "password=123456">> /etc/supervisor/supervisord.conf
#返回根目录
cd /opt/HuaShan
return 0
}
# 创建监控文件
function createMonitorFile()
{
svrName=$1
echo "*创建${svrName}监控文件"
\cp -r /opt/HuaShan/bin/config.d/${svrName}.ini /etc/supervisor/config.d
}
4.func
#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
# 输入需要的ip地址
local_server_ip=''
redis_ip=''
consul_ip=''
es_ip=''
postgresql_ip=''
kafka_ip=''
# 校验IP地址合法性
function isValidIp() {
local ip=$1
local ret=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
ip=(${ip//\./ }) # 按.分割,转成数组,方便下面的判断
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
ret=$?
fi
return $ret
}
function checkInputIP() {
addr=''
desc=$1
# 输入当前IP地址(确保多网卡时的ip一致性)
while :
do
read -p "**请输入${desc}的IPv4地址:" addr
isValidIp ${addr}
if [ $? -eq 0 ]; then
read -p "[确认直接回车!输入任意字符修改!]" confirm
if [ "${confirm}" = "" ];then
break
fi
else
echo "**输入的IP地址无效,请重试!!!"
fi
done
}
function inputLocalIP(){
# 输入当前IP地址(确保多网卡时的ip一致性)
while :
do
read -p "**请输入本机的IP地址:" local_server_ip
isValidIp ${local_server_ip}
if [ $? -eq 0 ]; then
read -p "[确认直接回车,输入任意字符修改?]" confirm
if [ "${confirm}" = "" ];then
break
fi
else
echo "输入的地址无效,请重试!!!"
fi
done
}
function inputConsulIP(){
# 输入当前IP地址(确保多网卡时的ip一致性)
while :
do
read -p "**请输入Consul的IP地址:" consul_ip
isValidIp ${consul_ip}
if [ $? -eq 0 ]; then
read -p "[确认直接回车,输入任意字符修改?]" confirm
if [ "${confirm}" = "" ];then
break
fi
else
echo "输入的地址无效,请重试!!!"
fi
done
}
function inputPostgresIP(){
# 输入当前IP地址(确保多网卡时的ip一致性)
while :
do
read -p "**请输入Postgres的IP地址:" postgresql_ip
isValidIp ${postgresql_ip}
if [ $? -eq 0 ]; then
read -p "[确认直接回车,输入任意字符修改?]" confirm
if [ "${confirm}" = "" ];then
break
fi
else
echo "输入的地址无效,请重试!!!"
fi
done
}
function inputESIP(){
# 输入当前IP地址(确保多网卡时的ip一致性)
while :
do
read -p "**请输入Elasticsearch的IP地址:" es_ip
isValidIp ${es_ip}
if [ $? -eq 0 ]; then
read -p "[确认直接回车,输入任意字符修改?]" confirm
if [ "${confirm}" = "" ];then
break
fi
else
echo "输入的地址无效,请重试!!!"
fi
done
}
function inputRedisIP(){
# 输入当前IP地址(确保多网卡时的ip一致性)
while :
do
read -p "**请输入Redis的IP地址:" redis_ip
isValidIp ${redis_ip}
if [ $? -eq 0 ]; then
read -p "[确认直接回车,输入任意字符修改?]" confirm
if [ "${confirm}" = "" ];then
break
fi
else
echo "输入的地址无效,请重试!!!"
fi
done
}
function inputKafkaIP(){
# 输入当前IP地址(确保多网卡时的ip一致性)
while :
do
read -p "**请输入kafka的IP地址:" kafka_ip
isValidIp ${kafka_ip}
if [ $? -eq 0 ]; then
read -p "[确认直接回车,输入任意字符修改?]" confirm
if [ "${confirm}" = "" ];then
break
fi
else
echo "输入的地址无效,请重试!!!"
fi
done
}
function IsEnvIP(){
# 输入当前IP地址(确保多网卡时的ip一致性)
# 判断es,consul,pg ip地址是否需要重新输入
echo -e "**Consul,ES,PG,Kafka是否与本机IP一致*"
read -p "[ 如果一致直接回车!否则输入任意字符修改? ]" conf
if [ "${conf}" = "" ]
then
redis_ip=${local_server_ip}
consul_ip=${local_server_ip}
es_ip=${local_server_ip}
postgresql_ip=${local_server_ip}
kafka_ip=${local_server_ip}
else
# 重新输入各个ip
#inputRedisIP
redis_ip=${local_server_ip}
echo -e ""
inputConsulIP
echo -e ""
inputPostgresIP
echo -e ""
inputESIP
echo -e ""
inputKafkaIP
fi
}
function cfgSIP3(){
echo "*配置SIP3开始*"
addr=$1
cd ${basepath}/web/sip3-dist/dist/conf
sed -i "s/\"sip2Ip\":\"http:\/\/127.0.0.1:10002\"/\"sip2Ip\":\"http:\/\/${addr}:10002\"/g" index.js
sed -i "s/\"sip3Ip2\":\"http:\/\/127.0.0.1:10001\"/\"sip3Ip2\":\"http:\/\/${addr}:10001\"/g" index.js
sed -i "s/\"tuzhenIp\":\"http:\/\/127.0.0.1:10001\"/\"tuzhenIp\":\"http:\/\/${addr}:10001\"/g" index.js
echo "*配置SIP3完成*"
}
function cfgRedis(){
echo "*配置Redis开始*"
addr=$1
cd ${basepath}/web/redis-5.0.4
sed -i "s/bind 127.0.0.1/bind ${addr}/g" redis.conf
echo "*配置Redis完成*"
}
function cfgNginx(){
echo "*配置Nginx开始*"
addr=$1
cd ${basepath}/web/nginx/conf
sed -i "s/proxy_pass http:\/\/127.0.0.1:8080/proxy_pass http:\/\/${addr}:8080/g" nginx.conf
sed -i "s/proxy_pass http:\/\/127.0.0.1:8084/proxy_pass http:\/\/${addr}:8084/g" nginx.conf
echo "*配置Nginx完成*"
}
function startRedis(){
echo "**启动Redis开始**"
cd ${basepath}/web/redis-5.0.4
chmod +x redis-server
./redis-server redis.conf > redis.log 2>&1 &
sleep 2
pid=`ps gaux | grep "redis-server" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**启动Redis失败**\033[0m"
else
echo "**启动Redis成功,pid=${pid} "
fi
}
function startNginx(){
echo "**启动Nginx开始**"
cd ${basepath}/web/nginx/sbin
chmod +x nginx
./nginx -c /opt/HuaShan/web/nginx/conf/nginx.conf > /opt/HuaShan/web/nginx/nginx.log 2>&1 &
sleep 2
pid=`ps gaux | grep "/opt/HuaShan/web/nginx/conf/nginx.conf" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**启动Nginx失败** \033[0m"
else
echo "**启动Nginx成功,pid=${pid} "
fi
}
function startSip3(){
l_ip=$1
r_ip=$2
c_ip=$3
echo "**启动Sip3开始**"
cd ${basepath}/web/sip3-dist/dist
nohup java -Xms512m -Xmx2048m -jar -Dservice_gateway.hostname=${l_ip} -Dspring.redis.host=${r_ip} -Dspring.cloud.consul.host=${c_ip} /opt/HuaShan/web/system-application-services.jar > /opt/HuaShan/web/sip3.log 2>&1 &
sleep 5
pid=`ps gaux | grep java | grep "/opt/HuaShan/web/system-application-services.jar" |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**启动Sip3失败** \033[0m"
else
echo "**启动Sip3成功,pid=${pid} "
fi
}
function startDNTWeb(){
pg_ip=$1
c_ip=$2
es_ip=$3
kafka_ip=$4
l_ip=$5
echo "**启动web应用开始**"
cd ${basepath}/web
nohup java -Xms512m -Xmx2048m -jar /opt/HuaShan/web/dataferry-web-0.0.1-SNAPSHOT.jar --spring.datasource.url=jdbc:postgresql://${pg_ip}:5432/huashan --spring.datasource.username=huashan --spring.datasource.password=huashan@123 --spring.cloud.consul.host=${c_ip} --spring.cloud.consul.port=8500 --kafka.bootstrap_servers=${kafka_ip}:9092 --filePath=/opt/HuaShan/web/images/ --fileUrl=http://${l_ip}:19999/images/ --appUrl=http://127.0.0.1:8084 --spring.cloud.consul.discovery.ip-address=${l_ip} --server.port=8084> /opt/HuaShan/web/dataferry-web-out.log 2>&1&
sleep 3
pid=`ps gaux | grep java | grep "/opt/HuaShan/web/dataferry-web-0.0.1-SNAPSHOT" |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**启动web应用失败** \033[0m"
else
echo "**启动web应用成功,pid=${pid} "
fi
}
function stopRedis(){
#echo "**Redis停止开始**"
pid=`ps gaux | grep "redis-server" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**Redis进程不存在 \033[0m"
else
kill -9 ${pid}
sleep 2
pid1=`ps gaux | grep "redis-server" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**Redis停止成功**"
else
echo -e "\033[31m**Redis停止失败** \033[0m"
fi
fi
}
function stopNginx(){
#echo "**Nginx停止开始**"
pid=`ps gaux | grep "/opt/HuaShan/web/nginx/conf/nginx.conf" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**Nginx进程不存在** \033[0m"
else
cd ${basepath}/web/nginx/sbin
./nginx -s stop
sleep 2
pid1=`ps gaux | grep "/opt/HuaShan/web/nginx/conf/nginx.conf" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**Nginx停止成功**"
else
echo -e "\033[31m**Nginx停止失败** \033[0m"
fi
fi
}
function stopSip3(){
#echo "**Sip3停止开始**"
pid=`ps gaux | grep java | grep "/opt/HuaShan/web/system-application-services.jar" |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**Sip3进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 2
pid1=`ps gaux | grep java | grep "/opt/HuaShan/web/system-application-services.jar" |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**Sip3停止成功**"
else
echo -e "\033[31m**Sip3停止失败** \033[0m"
fi
fi
}
function stopDNTWeb(){
#echo "**Web停止开始**"
pid=`ps gaux | grep java | grep dataferry-web-0.0.1-SNAPSHOT.jar |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**Web应用进程不存在** \033[0m"
else
kill -9 ${pid}
sleep 4
pid1=`ps gaux | grep java | grep dataferry-web-0.0.1-SNAPSHOT.jar |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "**Web应用停止成功**"
else
echo -e "\033[31m**Web应用停止失败** \033[0m"
fi
fi
}
# 安装Web页面
function installWeb()
{
echo "*安装Web页面"
\cp -r bin/web web
# 修改sip3、nginx配置
echo '============================'
cfgSIP3 ${local_server_ip}
cfgRedis ${local_server_ip}
cfgNginx ${local_server_ip}
echo '============================'
}
# 启动SIP3/Nginx/Redis
function startSIP3()
{
startRedis
startNginx
startSip3 ${local_server_ip} ${redis_ip} ${consul_ip}
}
# 停止SIP3/Nginx/Redis
function stopSIP3()
{
stopRedis
stopNginx
stopSip3
}
# 启动Web页面
function startWeb()
{
startDNTWeb ${postgresql_ip} ${consul_ip} ${es_ip} ${kafka_ip} ${local_server_ip}
}
# 停止Web页面
function stopWeb()
{
stopDNTWeb
}
5.install.sh
#!/bin/bash
currentUser=$(whoami)
if [ "$currentUser" != "root" ];then
echo "当前用户为非root,请切换用户:${currentUser}"
exit 1
fi
function installSvr()
{
arg1=$1
case $arg1 in
1)
echo "打标签服务"
# 打标签服务
installTagSvr
# 创建监控文件-打标签服务
createMonitorFile ${TagServer}
;;
2)
echo "告警服务"
# 告警服务
installAlarmSvr
# 创建监控文件-告警服务
createMonitorFile ${AlarmServer}
;;
3)
echo "白名单分发服务"
# 白名单分发服务
installWhiteListDistributeSvr
# 创建监控文件-白名单分发服务
createMonitorFile ${WhitelistDistributeService}
;;
4)
# 名单库分发服务
installListDistributeSvr
# 创建监控文件-名单库分发服务
createMonitorFile ${LibraryDistributeUniversalService}
;;
5)
# 名单库存储服务
installListStoreSvr
# 创建监控文件-名单库存储服务
createMonitorFile ${PlatformInfoManager}
;;
6)
# 平台信息管理服务
installPlatformInfoManager
# 创建监控文件-平台信息管理服务
createMonitorFile ${StoreListLibraryServer}
;;
7)
# 摆渡发送服务
installFerrySendSvr
# 创建监控文件-摆渡发送服务
createMonitorFile ${FerrySendServer}
;;
8)
# 摆渡接收服务
installFerryRecvSvr
# 创建监控文件-摆渡接收服务
createMonitorFile ${FerryRecvServer}
;;
9)
# 白名单订阅服务
installSubscribeData
# 创建监控文件-白名单订阅服务
createMonitorFile ${WhiteListSubscribeSvr}
;;
10)
# 开门信息下发服务
installVCNOpenDoorSvr
# 创建监控文件-开门信息下发服务
createMonitorFile ${VCNOpenDoorSvr}
;;
11)
# 设备列表获取服务
installVCNDeviceGainer
# 创建监控文件-设备列表获取服务
createMonitorFile ${VCNDeviceGainerSvr}
;;
12)
# Web页面
installWeb
# 创建监控文件-Web页面
#createMonitorFile ${web}
;;
*)
esac
}
echo "*******************************"
echo "* 开始安装 *"
echo "*******************************"
#规定在opt目录下安装
currentpath='/opt'
if [ $currentpath != "/opt/HuaShan" ] ;then
cd "/opt/HuaShan"
fi
# 引入 function
currentpath=$(pwd)
. $currentpath/function
# 引入 func
currentpath=$(pwd)
. $currentpath/func
echo "**当前安装目录:" ${currentpath}
# 配置环境变量ICV_ROOT
InitIcvRoot
source ~/.bash_profile
#配置IP
inputLocalIP
IsEnvIP
# 将地址写入到func的addr变量中
sed -i "s/local_server_ip=''/local_server_ip='${local_server_ip}'/g" ${currentpath}/func
sed -i "s/consul_ip=''/consul_ip='${consul_ip}'/g" ${currentpath}/func
sed -i "s/es_ip=''/es_ip='${es_ip}'/g" ${currentpath}/func
sed -i "s/postgresql_ip=''/postgresql_ip='${postgresql_ip}'/g" ${currentpath}/func
sed -i "s/redis_ip=''/redis_ip='${redis_ip}'/g" ${currentpath}/func
sed -i "s/kafka_ip=''/kafka_ip='${kafka_ip}'/g" ${currentpath}/func
# 安装supervisor
installSupervisor
res=`echo $?`
if [ $res = "1" ]; then
exit 1
fi
# 指定安装服务类型
echo -e "\033[035m******************************\033[0m"
echo -e "\033[036m* 请选择安装的服务类型 *\033[0m"
echo -e "\033[032m* 0 : 专网侧 *\033[0m"
echo -e "\033[034m* 1 : 内网侧 *\033[0m"
echo -e "\033[035m******************************\033[0m"
#选择需要安装的服务类型
input=""
while :
do
read -r -p "请选择安装服务的类型: " input
case $input in
[0-1])
break
;;
*)
echo "请输入有效的数字:"
;;
esac
done
# 安装对应服务
case $input in
0)
echo -e "\033[033m******************************\033[0m"
echo -e "\033[032m* 专网侧安装的服务列表 *\033[0m"
echo -e "\033[033m******************************\033[0m"
echo -e "\033[031m* 0 : 全部安装 *\033[0m"
echo -e "\033[033m******************************\033[0m"
echo -e "\033[032m* 1 : 打标签服务 *\033[0m"
echo -e "\033[032m* 2 : 告警服务 *\033[0m"
echo -e "\033[032m* 3 : 白名单分发服务 *\033[0m"
echo -e "\033[032m* 4 : 名单库分发服务 *\033[0m"
echo -e "\033[032m* 5 : 名单库存储服务 *\033[0m"
echo -e "\033[032m* 6 : 平台信息管理服务 *\033[0m"
echo -e "\033[032m* 7 : 摆渡发送服务 *\033[0m"
echo -e "\033[032m* 8 : 摆渡接收服务 *\033[0m"
echo -e "\033[032m* 9 : 白名单订阅服务 *\033[0m"
echo -e "\033[032m* 10: 开门信息下发服务 *\033[0m"
echo -e "\033[032m* 11: 设备列表获取服务 *\033[0m"
echo -e "\033[032m* 12: Web页面 *\033[0m"
echo -e "\033[033m******************************\033[0m"
echo -e "\033[031m* 13: 退出安装 *\033[0m"
echo -e "\033[033m******************************\033[0m"
# 初始化动态库的路径,C++服务运行需要
if [ ! -f "/etc/ld.so.conf.d/huashan.conf" ]; then
cp -r bin/lib lib
sleep 2
touch /etc/ld.so.conf.d/huashan.conf
echo "/usr/lib64">> /etc/ld.so.conf.d/huashan.conf
echo "${currentpath}/lib">> /etc/ld.so.conf.d/huashan.conf
echo "${currentpath}/lib/cpprest">> /etc/ld.so.conf.d/huashan.conf
echo "${currentpath}/lib/sdk">> /etc/ld.so.conf.d/huashan.conf
echo "${currentpath}/lib/boost">> /etc/ld.so.conf.d/huashan.conf
sudo ldconfig
else
echo "*动态库配置文件huashan.conf已存在"
fi
#选择需要安装的服务列表
num=""
while :
do
read -r -p "请选择安装服务的编号(13表示退出安装): " num
case $num in
0)
# 打标签服务
installTagSvr
# 告警服务
installAlarmSvr
# 白名单分发服务
installWhiteListDistributeSvr
# 名单库分发服务
installListDistributeSvr
# 名单库存储服务
installListStoreSvr
# 平台信息管理服务
installPlatformInfoManager
# 摆渡发送服务
installFerrySendSvr
# 摆渡接收服务
installFerryRecvSvr
# 白名单订阅服务
installSubscribeData
# 开门信息下发服务
installVCNOpenDoorSvr
# 设备列表获取服务
installVCNDeviceGainer
# Web页面
installWeb
# 创建监控文件-打标签服务
createMonitorFile ${TagServer}
# 创建监控文件-告警服务
createMonitorFile ${AlarmServer}
# 创建监控文件-白名单分发服务
createMonitorFile ${WhitelistDistributeService}
# 创建监控文件-名单库分发服务
createMonitorFile ${LibraryDistributeUniversalService}
# 创建监控文件-名单库存储服务
createMonitorFile ${PlatformInfoManager}
# 创建监控文件-平台信息管理服务
createMonitorFile ${StoreListLibraryServer}
# 创建监控文件-摆渡发送服务
createMonitorFile ${FerrySendServer}
# 创建监控文件-摆渡接收服务
createMonitorFile ${FerryRecvServer}
# 创建监控文件-白名单订阅服务
createMonitorFile ${WhiteListSubscribeSvr}
# 创建监控文件-开门信息下发服务
createMonitorFile ${VCNOpenDoorSvr}
# 创建监控文件-设备列表获取服务
createMonitorFile ${VCNDeviceGainerSvr}
# 创建监控文件-Web页面
#createMonitorFile ${web}
break
;;
[1][0-2]|[1-9])
installSvr ${num}
;;
13)
echo "安装完成,退出安装过程"
break
;;
*)
echo "请输入有效的数字:"
;;
esac
done
;;
1)
echo -e "\033[033m******************************\033[0m"
echo -e "\033[034m* 专网侧安装的服务列表 *\033[0m"
echo -e "\033[034m* 1 : 摆渡发送服务 *\033[0m"
echo -e "\033[034m* 2 : 摆渡接收服务 *\033[0m"
echo -e "\033[033m******************************\033[0m"
sed -i "s/installType='0'/installType='1'/g" ${currentpath}/func
# 摆渡发送服务
installFerrySendSvr
# 摆渡接收服务
installFerryRecvSvr
# 创建监控文件-摆渡发送服务
createMonitorFile ${FerrySendServer}
# 创建监控文件-摆渡接收服务
createMonitorFile ${FerryRecvServer}
;;
*)
esac
# 清除安装包
clearInstall
echo "*******************************"
echo "* 安装完成 *"
echo "*******************************"
6.start.sh
#!/bin/bash
# root用户
currentUser=$(whoami)
if [ "$currentUser" != "root" ];then
echo "当前用户为非root,请切换root用户:${currentUser}"
exit 1
fi
#错误输出高亮格式
#字颜色:30—–37
#echo -e "\033[30m 黑色字 \033[0m"
#echo -e "\033[31m 红色字 \033[0m"
#echo -e "\033[32m 绿色字 \033[0m"
#echo -e "\033[33m 黄色字 \033[0m"
#echo -e "\033[34m 蓝色字 \033[0m"
#echo -e "\033[35m 紫色字 \033[0m"
#echo -e "\033[36m 天蓝字 \033[0m"
#echo -e "\033[37m 白色字 \033[0m"
#字背景颜色范围:40—–47
#echo -e "\033[40;37m 黑底白字 \033[0m"
#echo -e "\033[41;37m 红底白字 \033[0m"
#echo -e "\033[42;37m 绿底白字 \033[0m"
#echo -e "\033[43;37m 黄底白字 \033[0m"
#echo -e "\033[44;37m 蓝底白字 \033[0m"
#echo -e "\033[45;37m 紫底白字 \033[0m"
#echo -e "\033[46;37m 天蓝底白字 \033[0m"
#echo -e "\033[47;30m 白底黑字 \033[0m"
echo "****************************"
echo "*** 启动后台服务开始 ****"
echo "****************************"
# 进入目录
cd "/opt/HuaShan"
# 引入function
currentpath=$(pwd)
. $currentpath/function
# 引入func
XQ
. $currentpath/func
echo '==========================='
if [ "$installType" == '0' ]
then
# 打标签服务
startTagSvr
# 告警服务
startAlarmSvr
# 白名单分发服务
startWhiteListDistributeSvr
# 名单库分发服务
startListDistributeSvr
# 名单库存储服务
startListStoreSvr
# 平台信息管理服务
startPlatformInfoManager
# 摆渡发送服务
startFerrySendSvr
# 摆渡接收服务
startFerryRecvSvr
# 白名单订阅服务
startSubscribeData
# 开门信息下发服务
startVCNOpenDoorSvr
# 设备列表获取服务
startVCNDeviceGainer
# Web页面
startWeb
else
if [ "$installType" == '1' ]
then
# 摆渡发送服务
startFerrySendSvr
# 摆渡接收服务
startFerryRecvSvr
else
echo -e "\033[31m*服务类型错误,请检查脚本,installType=${installType}\033[0m"
fi
fi
# 启动supervisor
supervisord -c /etc/supervisor/supervisord.conf
echo '==========================='
echo "****************************"
echo "*** 启动后台服务完成 ****"
echo "****************************"
7.checState.sh
#!/bin/bash
currentUser=$(whoami)
if [ "$currentUser" != "root" ];then
echo "当前用户为非root:${currentUser}"
exit 1
fi
# 打标签服务
function checkTagSvr()
{
pid=`ps -ef | grep TagServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到打标签服务进程 \033[0m"
else
echo "*检测到打标签服务进程,pid=${pid}"
fi
}
# 告警服务
function checkAlarmSvr()
{
pid=`ps -ef | grep AlarmServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到告警服务进程 \033[0m"
else
echo "*检测到告警服务进程,pid=${pid}"
fi
}
# 白名单分发服务
function checkWhiteListDistributeSvr()
{
pid=`ps -ef | grep WhitelistDistributeService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到白名单分发服务进程 \033[0m"
else
echo "*检测到白名单分发服务进程,pid=${pid}"
fi
}
# 名单库分发服务
function checkListDistributeSvr()
{
pid=`ps -ef | grep LibraryDistributeUniversalService | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到名单库分发服务进程 \033[0m"
else
echo "*检测到名单库分发服务进程,pid=${pid}"
fi
}
# 平台信息管理服务
function checkPlatformInfoManager()
{
pid=`ps -ef | grep PlatformInfoManager | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到平台信息管理服务进程 \033[0m"
else
echo "*检测到平台信息管理服务进程,pid=${pid}"
fi
}
# 名单库存储服务
function checkListStoreSvr()
{
pid=`ps -ef | grep StoreListLibraryServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到名单库存储服务进程 \033[0m"
else
echo "*检测到名单库存储服务进程,pid=${pid}"
fi
}
# 摆渡发送服务
function checkFerrySendSvr()
{
pid=`ps -ef | grep FerrySendServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到摆渡发送服务进程 \033[0m"
else
echo "*检测到摆渡发送服务进程,pid=${pid}"
fi
}
# 摆渡接收服务
function checkFerryRecvSvr()
{
pid=`ps -ef | grep FerryRecvServer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到摆渡接收服务进程 \033[0m"
else
echo "*检测到摆渡接收服务进程,pid=${pid}"
fi
}
# 白名单订阅服务
function checkSubscribeData()
{
pid=`ps -ef | grep WhiteListSubscribeSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到白名单订阅服务进程 \033[0m"
else
echo "*检测到白名单订阅服务进程,pid=${pid}"
fi
}
# 开门信息下发服务
function checkVCNOpenDoorSvr()
{
pid=`ps -ef | grep VCNOpenDoorSvr | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到开门信息下发服务进程 \033[0m"
else
echo "*检测到开门信息下发服务进程,pid=${pid}"
fi
}
# 设备列表获取服务
function checkVCNDeviceGainer()
{
pid=`ps -ef | grep VCNDeviceGainer | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m*未检测到设备列表获取服务进程 \033[0m"
else
echo "*检测到设备列表获取服务进程,pid=${pid}"
fi
}
function checkRedis(){
#echo "**Redis检查开始**"
pid=`ps gaux | grep "redis-server" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**未检测到Redis进程 \033[0m"
else
echo "**检测到Redis进程,pid=${pid}"
fi
}
function checkNginx(){
#echo "**Nginx检查开始**"
pid=`ps gaux | grep "/opt/HuaShan/web/nginx/conf/nginx.conf" | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**未检测到Nginx进程 \033[0m"
else
echo "**检测到Nginx进程,pid=${pid}"
fi
}
function checkSip3(){
#echo "**Sip3检查开始"
pid=`ps gaux | grep java | grep "/opt/HuaShan/web/system-application-services.jar" |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**未检测到Sip3进程 \033[0m"
else
echo "**检测到Sip3进程,pid=${pid}"
fi
}
function checkDNTWeb(){
#echo "**Web应用检查开始"
pid=`ps gaux | grep java | grep "/opt/HuaShan/web/dataferry-web-0.0.1-SNAPSHOT" |grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo -e "\033[31m**未检测到Web应用进程 \033[0m"
else
echo "**检测到Web应用进程,pid=${pid}"
fi
}
# Web页面
function checkWeb()
{
echo -e "\033[034m------------------------------\033[0m"
checkRedis
checkNginx
checkSip3
checkDNTWeb
echo -e "\033[034m------------------------------\033[0m"
}
# 进入目录
cd "/opt/HuaShan"
# 引入function
currentpath=$(pwd)
. $currentpath/function
# 引入func
currentpath=$(pwd)
. $currentpath/func
echo "****************************"
echo "****检测服务运行状态开始****"
echo "****************************"
if [ "$installType" == '0' ]
then
# 打标签服务
checkTagSvr
# 告警服务
checkAlarmSvr
# 白名单分发服务
checkWhiteListDistributeSvr
# 名单库分发服务
checkListDistributeSvr
# 名单库存储服务
checkListStoreSvr
# 平台信息管理服务
checkPlatformInfoManager
# 摆渡发送服务
checkFerrySendSvr
# 摆渡接收服务
checkFerryRecvSvr
# 白名单订阅服务
checkSubscribeData
# 开门信息下发服务
checkVCNOpenDoorSvr
# 设备列表获取服务
checkVCNDeviceGainer
# Web页面
checkWeb
else
if [ "$installType" == '1' ]
then
# 摆渡发送服务
checkFerrySendSvr
# 摆渡接收服务
checkFerryRecvSvr
else
echo -e "\033[31m*服务类型错误,请检查脚本,installType=${installType}\033[0m"
fi
fi
echo "****************************"
echo "****检测服务运行状态完成****"
echo "****************************"
8.restart.sh
#!/bin/bash
currentUser=$(whoami)
if [ "$currentUser" != "root" ];then
echo "当前用户为非root:${currentUser}"
exit 1
fi
# 打标签服务
function restartTagSvr()
{
echo "=========================="
stopTagSvr
startTagSvr
echo "=========================="
}
# 告警服务
function restartAlarmSvr()
{
echo "=========================="
stopAlarmSvr
startAlarmSvr
echo "=========================="
}
# 白名单分发服务
function restartWhiteListDistributeSvr()
{
echo "=========================="
stopWhiteListDistributeSvr
startWhiteListDistributeSvr
echo "=========================="
}
# 名单库分发服务
function restartListDistributeSvr()
{
echo "=========================="
stopListDistributeSvr
startListDistributeSvr
echo "=========================="
}
# 平台信息管理服务
function restartPlatformInfoManager()
{
echo "=========================="
stopPlatformInfoManager
startPlatformInfoManager
echo "=========================="
}
# 名单库存储服务
function restartListStoreSvr()
{
echo "=========================="
stopListStoreSvr
startListStoreSvr
echo "=========================="
}
# 摆渡发送服务
function restartFerrySendSvr()
{
echo "=========================="
stopFerrySendSvr
startFerrySendSvr
echo "=========================="
}
# 摆渡接收服务
function restartFerryRecvSvr()
{
echo "=========================="
stopFerryRecvSvr
startFerryRecvSvr
echo "=========================="
}
# 白名单订阅服务
function restartSubscribeData()
{
echo "=========================="
stopSubscribeData
startSubscribeData
echo "=========================="
}
# 开门信息下发服务
function restartVCNOpenDoorSvr()
{
echo "=========================="
stopVCNOpenDoorSvr
startVCNOpenDoorSvr
echo "=========================="
}
# 设备列表获取服务
function restartVCNDeviceGainer()
{
echo "=========================="
stopVCNDeviceGainer
startVCNDeviceGainer
echo "=========================="
}
# SIP3/Nginx/Redis
function restartSIP3()
{
echo "=========================="
stopSIP3
startSIP3
echo "=========================="
}
# Web页面
function restartWeb()
{
echo "=========================="
stopWeb
startWeb
echo "=========================="
}
# 进入目录
cd "/opt/HuaShan"
# 引入function
currentpath=$(pwd)
. $currentpath/function
# 引入func
currentpath=$(pwd)
. $currentpath/func
echo -e "\033[035m******************************\033[0m"
echo -e "\033[034m* 请选择重启的服务编号 *\033[0m"
echo -e "\033[032m* 0 : 全部重启 *\033[0m"
echo -e "\033[032m* 1 : 打标签服务 *\033[0m"
echo -e "\033[032m* 2 : 告警服务 *\033[0m"
echo -e "\033[032m* 3 : 白名单分发服务 *\033[0m"
echo -e "\033[032m* 4 : 名单库分发服务 *\033[0m"
echo -e "\033[032m* 5 : 名单库存储服务 *\033[0m"
echo -e "\033[032m* 6 : 平台信息管理服务 *\033[0m"
echo -e "\033[032m* 7 : 摆渡发送服务 *\033[0m"
echo -e "\033[032m* 8 : 摆渡接收服务 *\033[0m"
echo -e "\033[032m* 9 : 白名单订阅服务 *\033[0m"
echo -e "\033[032m* 10: 开门信息下发服务 *\033[0m"
echo -e "\033[032m* 11: 设备列表获取服务 *\033[0m"
echo -e "\033[032m* 12: SIP3/Nginx/Redis *\033[0m"
echo -e "\033[032m* 13: Web页面 *\033[0m"
echo -e "\033[035m******************************\033[0m"
#选择需要重启的服务
input=""
while :
do
read -r -p "请选择重启的后台服务: " input
case $input in
[1][0-3]|[0-9])
break
;;
*)
echo "请输入有效的数字:"
;;
esac
done
if [ "$installType" == '0' ]
then
# 启动对应服务
case $input in
0)
# 打标签服务
restartTagSvr
# 告警服务
restartAlarmSvr
# 白名单分发服务
restartWhiteListDistributeSvr
# 名单库分发服务
restartListDistributeSvr
# 名单库存储服务
restartListStoreSvr
# 平台信息管理服务
restartPlatformInfoManager
# 摆渡发送服务
restartFerrySendSvr
# 摆渡接收服务
restartFerryRecvSvr
# 白名单订阅服务
restartSubscribeData
# 开门信息下发服务
restartVCNOpenDoorSvr
# 设备列表获取服务
restartVCNDeviceGainer
# Web页面
restartWeb
;;
1)
# 打标签服务
restartTagSvr
;;
2)
# 告警服务
restartAlarmSvr
;;
3)
# 白名单分发服务
restartWhiteListDistributeSvr
;;
4)
# 名单库分发服务
restartListDistributeSvr
;;
5)
# 名单库存储服务
restartListStoreSvr
;;
6)
# 平台信息管理服务
restartPlatformInfoManager
;;
7)
# 摆渡发送服务
restartFerrySendSvr
;;
8)
# 摆渡接收服务
restartFerryRecvSvr
;;
9)
# 白名单订阅服务
restartSubscribeData
;;
10)
# 开门信息下发服务
restartVCNOpenDoorSvr
;;
11)
# 设备列表获取服务
restartVCNDeviceGainer
;;
12)
# SIP3/Nginx/Redis
restartSIP3
;;
13)
# Web页面
restartWeb
;;
*)
esac
else
if [ "$installType" == '1' ]
then
# 启动对应服务
case $input in
0)
# 摆渡发送服务
restartFerrySendSvr
# 摆渡接收服务
restartFerryRecvSvr
;;
7)
# 摆渡发送服务
restartFerrySendSvr
;;
8)
# 摆渡接收服务
restartFerryRecvSvr
;;
*)
echo -e "\033[31m*输入的重启服务序号不存在,请检查,input=${input}\033[0m"
;;
esac
else
echo -e "\033[31m*服务类型错误,请检查脚本,installType=${installType}\033[0m"
fi
fi
9. stop.sh
#!/bin/bash
echo "*******************************"
echo "* 卸载服务开始 *"
echo "*******************************"
# 进入目录
cd "/opt/HuaShan"
# 卸载supervisor
if [ ! -f "/etc/supervisor/supervisord.conf" ]; then
echo "*supervisord.conf不存在,无需卸载"
else
echo "*supervisord.conf文件存在"
pid=`ps gaux | grep supervisord | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid}" = "" ]
then
echo "supervisord进程不存在"
else
kill -9 ${pid}
pid1=`ps gaux | grep supervisord | grep -v grep |head -n 1| awk '{print $2}'`
if [ "${pid1}" = "" ];then
echo "supervisord停止成功"
else
echo "supervisord停止失败"
echo -e "\033[31监控msupervisord停止失败, 重新卸载\033[0m"
exit 1
fi
fi
rm -rf /etc/supervisor
fi
#停止服务"
./stop.sh
echo "*清除ICV_ROOT的环境变量"
ICV_ROOT=${ICV_ROOT}
# 删除icv_root环境变量
sed -i '/export ICV_ROOT=/d' ~/.bash_profile
source ~/.bash_profile
rm -rf ${icvroot}
# 初始化动态库的路径,C++服务运行需要
if [ ! -f "/etc/ld.so.conf.d/huashan.conf" ]; then
echo "*动态库文件huashan.conf不存在,无需卸载"
else
echo "*动态库文件huashan.conf存在"
rm -rf /etc/ld.so.conf.d/huashan.conf
sudo ldconfig
fi
# 清除安装包
echo "*清除安装包"
#install_pack="/opt/HuaShan"
#rm -rf ${install_pack}
rm -rf AlarmServer Supervisor FerryRecvServer log localDB.db3 FerrySendServer lib LibraryDistributeUniversalService PlatformInfoManager StoreListLibraryServer TagServer VCNDeviceGainer VCNOpenDoorSvr web WhitelistDistributeService WhiteListSubscribeSvr
echo "*******************************"
echo "* 卸载服务完成 *"
echo "*******************************"