如何重写启动脚本
发表于:2025-02-01 作者:千家信息网编辑
千家信息网最后更新 2025年02月01日,这篇文章给大家分享的是重写启动脚本的方法,相信大部分人都还没学会这个技能,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。!/bin/bashuser=rootport=3306CmdP
千家信息网最后更新 2025年02月01日如何重写启动脚本
这篇文章给大家分享的是重写启动脚本的方法,相信大部分人都还没学会这个技能,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。
!/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}
以上就是重写启动脚本的方法,代码示例简单明了,如果在日常工作遇到此问题。通过这篇文章,希望你能有所收获,更多详情敬请关注行业资讯频道!
脚本
方法
篇文章
代码
内容
大部分
就是
技能
日常工作
明了
更多
看吧
示例
行业
详情
资讯
资讯频道
问题
频道
工作
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
oracle数据库 编码
关系型数据库鼻祖是谁
软件开发职业生涯规划前言
人武部学习网络安全
街道社区网络安全宣传信息简报
国产服务器大事件
小学生网络安全宣传小报怎么做
金牛区奇迹之光软件开发工作室
南京大数据服务器供应商家
应用服务器结构
央企网络安全专题峰会
远程集中服务器管理
江苏现代软件开发联系方式
南京云问网络技术有限公司好吗
商贸公司可以增加软件开发吗
买服务器一般指标有哪些
信赖的数据库复制
网络安全中混合加密的优缺点
正在与孤岛惊魂6服务器进行连接
服务器可以做硬盘吗
战争雷霆连接不上聊天服务器
魔域怎么查角色在哪个服务器
360网络安全学院负责人
简述智慧城市网络技术
C语言建立商品数据库
台式机插服务器内存条后不启动
数据库的分页显示
江苏浪潮服务器虚拟化多少钱
和平精英更新服务器的视频
软件开发人员个人简历模板