美文网首页
小而美的脚本-普通服务的重启脚本(Redis、Minio)

小而美的脚本-普通服务的重启脚本(Redis、Minio)

作者: CoderInsight | 来源:发表于2022-08-29 13:30 被阅读0次

Redis服务重启

通过netstate命令管理指定服务的重启;

vi redisRestart.sh

# 追加如下内容
#!/bin/sh
# flush Profile
source /etc/profile
case $1 in 
"start"){
nohup /home/install/redis-3.2.8/src/redis-server /home/install/redis-3.2.8/redis.conf > /dev/null 2>&1 &
echo "=============================================Starting Redis============================================="
};;
"stop"){
redisPid=$(netstat -nltp | grep 6379 |  awk '{print $7}' | awk -F/ '{print $1}')
if [ -z "$redisPid" ]; then
  echo "No redis server to stop"
else 
  kill -s TERM $redisPid
fi
echo "=============================================Stoped Redis============================================="
};;
esac

Minio服务重启

通过ps命令管理指定服务的重启;

vi minioRestart.sh

# 追加如下内容
#!/bin/sh
# flush Profile
source /etc/profile
APP_NAME=minio
#检查程序是否在运行
is_exist() {
    pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}' `
    #如果不存在返回1,存在返回0
    if [ -z "${pid}" ]; then
      return 1
    else
      return 0
    fi
}

#输出运行状态
status() {
   is_exist
   if [ $? -eq "0" ]; then
     echo "${APP_NAME} is running. Pid is ${pid}"
   else
     echo "${APP_NAME} is not running."
   fi
}



case $1 in 
"start"){
nohup /home/install/minioSoft/minio server /home/install/minioSoft/data > /home/install/minioSoft/minio.log 2>&1 &
echo "=============================================Starting Minio============================================="
};;
"stop"){
minioPIDS=$(ps ax | grep -i 'minio' | grep -v grep | awk '{print $1}')

for pid in $minioPIDS
do
if [ -z "$pid" ]; then
  echo "No Minio server to stop"
 
else 
  kill -s TERM $pid
fi
        
done

echo "=============================================Stoped ${APP_NAME}============================================="
};;
"status"){
status
};;
esac

相关文章

网友评论

      本文标题:小而美的脚本-普通服务的重启脚本(Redis、Minio)

      本文链接:https://www.haomeiwen.com/subject/zknhnrtx.html