iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >重写启动脚本
  • 107
分享到

重写启动脚本

2024-04-02 19:04:59 107人浏览 独家记忆
摘要

!/bin/bash user=rootport=3306CmdPath=/opt/Mysql/binpassWord=xxxxxxxxxx base_dir=/opt/mysqlinst_dir=/dat

!/bin/bash

user=root
port=3306
CmdPath=/opt/Mysql/bin
passWord=xxxxxxxxxx

base_dir=/opt/mysql
inst_dir=/data/3306
alive="00"
sMysqld=0
sMysqldSafe=0
fSock=0
fPID=0

check_alive()
{
echo "running check_alive..."
if [ ps -ef | grep $port | grep -v grep | grep 'mysqld ' |awk '{print $2}' ];then
echo "Process mysqld is running!"
sMysqld=1
else
echo "Process mysqld is not running!"
sMysqld=0
fi

     if [  `ps -ef | grep 3306 | grep -v grep | grep 'mysqld_safe' |awk '{print $2}'` ];then 
        echo "Process mysqld_safe is running!"
        sMysqldSafe=1
 else 
    echo "Process mysqld_safe is not running!"
    sMysqldSafe=0
     fi

     if [ -e  ${inst_dir}/mysql.sock ];then
        echo "socked file exists!"
        fSock=1
 else 
    echo "socked file not exists!"
    fSock=0
     fi

     if [ -e  ${inst_dir}/mysql.pid ];then
        echo "pid file exists!"
        fPID=1
 else 
    echo "pid file  not exists!"
    fPID=0
     fi

     if [ $sMysqld -eq 1 ];then
        if [ $fPID -eq 0 ];then
            echo "PID is missing, tring to recreate..."
            ps -ef | grep $port | grep -v grep | grep 'mysqld ' |awk '{print $2}' > ${inst_dir}/mysql.pid
            if [ -e ${inst_dir}/mysql.pid ]; then
                echo "pid file is created!"
            else
                echo "can not create PID file, please have a check!"
            fi
        fi
        if [ $sMysqldSafe -eq 0 ];then
            echo "Process mysqld_safe is missing, please have a check! May cause mysqld crash!"
        fi
        if [ $fSock -eq 1 ];then
            echo "MySQL running fine!!!"
            alive="11"
        else
            echo "Socket file is missing, you may have to login without socket!"
            alive="10"          
        fi                          
     else
        echo "process mysqld is missing, mysql is stopped!"
        if [ $fSock -eq 1 ] | [ $fPID -eq 1 ];then
            echo "mysql was stopped abnORMality!"
            echo "cleaning socket file and pid file"
            alive="01"
        else
            alive="00"
    fi

     fi

}

start_mysql()
{
check_alive
printf "MySQL is starting ... \n"
if [ $alive == "00" ]; then
${CmdPath}/mysqld_safe --defaults-file=${inst_dir}/my.cnf --user=${user} 2>&1 >/dev/null &
else
if [ $alive == "11" ]; then
echo "MySQL is runnig!"
else
if [ $alive == "01" ]; then
echo "MySQL was stopped but pid or sock file still exits!"
echo "Cleanning pid or sock files!"
if [ $fSock -eq 1 ];then
rm -f ${inst_dir}/mysql.sock
fi
if [ $fPID -eq 1 ];then
rm -f ${inst_dir}/mysql.pid
fi
echo "Tring to start MySQL again!!!"
${CmdPath}/mysqld_safe --defaults-file=${inst_dir}/my.cnf --user=${user} 2>&1 >/dev/null &
fi
fi
fi
}

stop_mysql()
{
check_alive
printf "MySQL is Stopping...\n"
if [ $alive == "11" ]; then
${CmdPath}/mysqladmin -u root -p${password} -S ${inst_dir}/mysql.sock shutdown 2>&1 >/dev/null &
else
if [ $alive == "10" ]; then
${CmdPath}/mysqladmin -u root -p${password} -h $HOSTNAME -P $port --protocol tcp shutdown 2>&1 >/dev/null &
else
echo "MySQL is not running, no need stop!"
fi
fi
}

restart_mysql()
{
stop_mysql
sleep 5
if [ $? == 0 ];then
start_mysql
else
echo "stop mysql failed!"
fi
}

case $1 in

start)
start_mysql
;;
stop)
stop_mysql
;;
restart)
restart_mysql
;;
status)
status_mysql
;;
alive)
check_alive
;;
*)
printf "Please in put start|stop|restart|status as input"
;;
esac

您可能感兴趣的文档:

--结束END--

本文标题: 重写启动脚本

本文链接: https://www.lsjlt.com/news/51412.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 重写启动脚本
    !/bin/bash user=rootport=3306CmdPath=/opt/mysql/binpassword=xxxxxxxxxx base_dir=/opt/mysqlinst_dir=/dat...
    99+
    2022-10-18
  • 如何重写启动脚本
    这篇文章给大家分享的是重写启动脚本的方法,相信大部分人都还没学会这个技能,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。!/bin/bashuser=rootport=3306CmdPath...
    99+
    2022-10-18
  • 如何编写linux自动重启tomcat脚本
    这篇文章主要介绍“如何编写linux自动重启tomcat脚本”,在日常操作中,相信很多人在如何编写linux自动重启tomcat脚本问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何编写linux自动重启to...
    99+
    2023-06-09
  • Spring Boot 启动、停止、重启、状态脚本
    此脚本用来管理 SpringBoot 项目的进程状态。 有提示功能。 把脚本丢到项目文件夹, 添加执行权限即可。 如果 jenkins 使用这个脚本, 需要在 java -jar 命...
    99+
    2022-11-12
  • linux自动重启tomcat脚本分享
    #!/bin/bash##chkconfig: 35 88 14#description: tomcat auto start script#script by okhelpercase "$1" inst...
    99+
    2022-06-04
    脚本 自动重启 linux
  • 自动重启挂掉的python脚本
    跑程序,因为内存问题或者其它blabla问题(总之不是代码问题),程序可能会偶尔挂掉,我们又不能整天盯着程序,怎么办呢?写个脚本来检查程序是否挂掉,如果挂掉就重启,这是一个不错的想法,具体做法依操作系统而不同。 方法1 在lin...
    99+
    2023-01-31
    脚本 自动重启 python
  • redis启动管理脚本怎么写
    这篇文章主要介绍redis启动管理脚本怎么写,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!我是源码安装的redis-3.0.5安装路径/usr/local/redis编辑创建脚本文件...
    99+
    2022-10-19
  • Linux开机自动启动的脚本怎么写
    这篇文章的内容主要围绕Linux开机自动启动的脚本怎么写进行讲述,文章内容清晰易懂,条理清晰,非常适合新手学习,值得大家去阅读。感兴趣的朋友可以跟随小编一起阅读吧。希望大家通过这篇文章有所收获!一、在/etc/rc.local中添加 如果不...
    99+
    2023-06-28
  • Linux中python自启动和定时启动脚本怎么写
    这篇“Linux中python自启动和定时启动脚本怎么写”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Linux中pytho...
    99+
    2023-06-28
  • oracle启动脚本
    在linux下配置oracle自动启动脚本:[root@test ~]# vim /etc/init.d/oracle#!/bin/bash #chkconfig:35&nbs...
    99+
    2022-10-18
  • MongoDB启动脚本
    今天研究mongodb,搭建时候发现源码包没提供启动脚本,便顺手写了一个方便使用。[root@controller mongodb]# cat /etc/init.d/mong...
    99+
    2022-10-18
  • 自动重启服务的shell脚本代码
    #!/bin/bash if [ ! -f /tmp/down_count ];then echo "0" > /tmp/down_count fi curl -I tomcat-host -...
    99+
    2022-06-04
    脚本 自动重启 代码
  • 如何编写shell脚本实现tomcat定时重启
    小编给大家分享一下如何编写shell脚本实现tomcat定时重启,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!于是我上网找了一些教程编写了一个简单的每天定时启动 ...
    99+
    2023-06-09
  • CentOS Tomcat的启动服务脚本怎么写
    CentOS Tomcat的启动服务脚本怎么写,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。 tomcat 自带的 jsvc, 这个工具会启动2个线程,如果应用...
    99+
    2023-06-10
  • linux bash脚本监控启动停止weblogic服务的脚本写法
    有时,linux系统需要做HA或者类似的功能,需要配置weblogic脚本来启动,停止,查看状态,可以如下方式写 命令形式:Weblogic server start|stop|restart|status...
    99+
    2022-06-04
    脚本 写法 linux
  • Windows编写jar启动脚本和关闭脚本的操作方法
    目录前言启动脚本编写关闭脚本restart.bat 重启脚本前言 假设项目打包后,项目结构为: 此时如果需要再windows环境中进行项目的启动或关闭,需要频繁的手敲命令,很不方便...
    99+
    2022-12-29
    Windows编写jar启动脚本 Windows jar关闭脚本 Windows jar脚本
  • Nginx和PHP-FPM的启动、重启、停止脚本分享
    服务器上的Nginx和PHP都是源码编译安装的,不像ubuntu一样有自带service启动脚本,所以不支持类似以前的nginx (start|restart|stop|reload)了。自己动手丰衣足食。...
    99+
    2022-06-04
    重启 脚本 Nginx
  • shell脚本启动、关闭、重启以及查看状态
    我使用的语句是case 语句 case     变量值     in   ...
    99+
    2022-10-18
  • MongoDB 自动启动脚本
    安装好mongodb之后,一直是如下启动,指定dbpath,logpath,验证auth等./mongod --dbpath=/usr/bin/mongodb/mongodb/data ...
    99+
    2022-10-18
  • 编写shell脚本实现tomcat定时重启的方法
    最近我在学生价买的低配服务器上部署了一个很吃内存的网页,导致 tomcat 内存经常溢出而崩溃。 于是我上网找了一些教程编写了一个简单的每天定时启动 tomcat 的脚本,特此记录一下 我的环境是 centos 7 ...
    99+
    2022-06-04
    shell tomcat定时重启 shell 定时重启
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作