ONgDB服务进程监控

 

Here’s the table of contents:

  1. 服务监控脚本DEMO
  2. 服务重启脚本
  3. monitor.sh
  4. server-monitor.sh

服务监控脚本DEMO

#!/bin/bash
PRG="$0"
currentpath=`dirname $(readlink -f $0)`
echo $currentpath
echo $(dirname $currentpath)
frontdir=$(dirname $currentpath)
javapid=$(ps -ef|grep java|grep -w $currentpath|awk '{print $2}')
echo $javapid
if [ -n "$javapid" ]
then
bash $currentpath/shutdown.sh
sleep 3s
fi
javapid=$(ps -ef|grep java|grep -w $currentpath|awk '{print $2}')
if [ -n "$javapid" ]
then
kill -9 $javapid
sleep 3s
fi
bash $currentpath/startup.sh

服务重启脚本

#!/bin/bash
# 切换用户
su - ongdb <<EOF
testlab%pro
# 检查服务,在目录下获取服务进程
currentpath='/home/ongdb/ongdb-enterprise-3.5.22'
echo 'ONgDB SERVER PATH:'+$currentpath
javapid=$(ps -ef|grep java|grep -w $currentpath|awk '{print $2}')
echo 'ONgDB PID:'+$javapid
# 不存在进程则重启服务
if [ -z "$javapid" ]
then
$currentpath/bin/neo4j restart
sleep 3s
fi
EOF

monitor.sh

#!/bin/bash
# 切换用户
su - ongdb <<EOF
testlab%pro
# 运行服务监控脚本
bash /home/ongdb/ongdb-enterprise-3.5.22/server-monitor.sh
EOF

server-monitor.sh

#!/bin/bash
# 检查服务,在目录下获取服务进程
currentpath='/home/ongdb/ongdb-enterprise-3.5.22'
echo 'ONgDB SERVER PATH:'+$currentpath
javapid=$(ps -ef|grep java|grep -w $currentpath|awk '{print $2}')
echo 'ONgDB PID:'+$javapid
# 不存在进程则重启服务
if [ -z "$javapid" ]
then
$currentpath/bin/neo4j restart
sleep 3s
fi