#!/bin/sh
declare -A modules=(["gateway"]="zt-gateway" ["auth"]="zt-auth" ["site"]="zt-modules-site" ["system"]="zt-modules-system" ["chip"]="zt-modules-chip")
name=""
zt_start(){
zt_get $1
if [ "$name" = "" ]
then
echo "$1 not found"
else
pid=`ps axu | grep $name | grep -v grep `
if [ ! -n "$pid" ]; then
echo -e "$name Active(\033[31mdead\033[0m) , it's will be restart now".
/usr/bin/java -jar /data/www/ztgl_server/$name.jar -Xms512m -Xmx512m -Xmn256m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/www/ztgl_server/logs/$name-gc.log >> /data/www/ztgl_server/logs/$name.log 2>&1 &
echo -e "$name Active(\033[32mrunning\033[0m)"
else
echo -e "$name Active(\033[32mrunning\033[0m)"
fi
fi
}
zt_stop(){
zt_get $1
if [ "$name" != "" ]
then
echo "ps axu | grep $name | grep -v grep | awk '{print $2}' | xargs -i sudo kill -9 {}"
ps axu | grep $name | grep -v grep | awk '{print $2}' | xargs -i sudo kill -9 {}
echo -e "\033[32m{$name} was killed.\033[0m"
else
echo "$1 not found"
fi
}
zt_restart(){
zt_stop $1
zt_start $1
}
zt_get(){
for i in ${!modules[@]}
do
if [ "$i" = "$1" ]
then
name=${modules[$i]}
break
fi
done
}
show_help()
{
printf "
Usage: $0 [OPTIONS]
OPTIONS: start | stop | restart
example: monitor.sh gateway restart
"
}
case $2 in
"start" )
zt_start $1
exit
;;
"stop" )
zt_stop $1
exit
;;
"restart" )
zt_restart $1
exit
;;
*)
show_help
exit
;;
esac
#!/bin/bash
declare -A modules=(["gateway"]="zt-gateway" ["auth"]="zt-auth" ["site"]="zt-modules-site" ["system"]="zt-modules-system" ["chip"]="zt-modules-chip" ["equipment"]="zt-modules-equipment")
declare -A jarpaths=(["gateway"]="/home/qqmovie/ztgl/zt-gateway/target/zt-gateway.jar" ["auth"]="/home/qqmovie/ztgl/zt-auth/target/zt-auth.jar" ["site"]="/home/qqmovie/ztgl/zt-modules/zt-site/target/zt-modules-site.jar" ["system"]="/home/qqmovie/ztgl/zt-modules/zt-system/target/zt-modules-system.jar" ["chip"]="/home/qqmovie/ztgl/zt-modules/zt-chip/target/zt-modules-chip.jar" ["equipment"]="/home/qqmovie/ztgl/zt-modules/zt-equipment/target/zt-modules-equipment.jar")
name=""
jarpath=""
zt_start(){
zt_get $1
if [ "$name" = "" ]
then
echo "$1 not found"
else
pid=`ps axu | grep $name | grep -v grep `
if [ ! -n "$pid" ]; then
echo -e "$name Active(\033[31mdead\033[0m) , it's will be restart now".
/usr/bin/java -jar $jarpath -Xms512m -Xmx512m -Xmn256m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/log/$name-gc.log >> /data/log/zt-$name.log 2>&1 &
echo "/usr/bin/java -jar $jarpath -Xms512m -Xmx512m -Xmn256m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/log/$name-gc.log >> /data/log/zt-$name.log 2>&1 &"
echo -e "$name Active(\033[32mrunning\033[0m)"
else
echo -e "$name Active(\033[32mrunning\033[0m)"
fi
fi
}
zt_stop(){
zt_get $1
if [ "$name" != "" ]
then
echo "ps axu | grep $name | grep -v grep | awk '{print $2}' | xargs -i sudo kill -9 {}"
ps axu | grep $name | grep -v grep | awk '{print $2}' | xargs -i sudo kill -9 {}
echo -e "\033[32m{$name} was killed.\033[0m"
else
echo "$1 not found"
fi
}
zt_restart(){
zt_stop $1
zt_start $1
}
zt_get(){
for i in ${!modules[@]}
do
if [ "$i" = "$1" ]
then
name=${modules[$i]}
jarpath=${jarpaths[$i]}
break
fi
done
}
zt_status(){
for i in ${!modules[@]}
do
name=${modules[$i]}
jarpath=${jarpaths[$i]}
pid=`ps axu | grep $name | grep -v grep `
if [ ! -n "$pid" ]; then
echo -e "$i Active(\033[31mdead\033[0m)"
else
echo -e "$i Active(\033[32mrunning\033[0m)"
fi
done
echo " "
echo " "
}
zt_monitor(){
for i in ${!modules[@]}
do
name=${modules[$i]}
now=`date '+%Y-%m-%d %H:%M:%S'`
pid=`ps axu | grep $name | grep -v grep `
if [ ! -n "$pid" ]; then
echo -e "$now $name Active(\033[31mdead\033[0m) , it's will be restart now".
/usr/bin/java -jar /data/www/ztgl_server/$name.jar -Xms512m -Xmx512m -Xmn256m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/data/www/ztgl_server/logs/$name-gc.log >> /data/www/ztgl_server/logs/$name.log 2>&1 &
echo -e "$now $name it's worked."
else
echo -e "$now $name Active(\033[32mrunning\033[0m)"
fi
done
}
show_help()
{
printf "
Usage: $0 [MODULES] [OPTIONS]
MODULES: gateway | auth | site | system | chip | equipment
OPTIONS: start | stop | restart
example: $0 gateway restart
"
}
case $2 in
"start" )
zt_start $1
exit
;;
"stop" )
zt_stop $1
exit
;;
"restart" )
zt_restart $1
exit
;;
"monitor" )
zt_monitor
exit
;;
*)
show_help
zt_status
exit
;;
esac
标签:grep,name,modules,echo,zt,进程,033,守护
From: https://www.cnblogs.com/netstat/p/18075593