简单shell脚本监测mysql运行情况_MySQL
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了简单shell脚本监测mysql运行情况_MySQL,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2211字,纯文字阅读大概需要4分钟。
内容图文
![简单shell脚本监测mysql运行情况_MySQL](/upload/InfoBanner/zyjiaocheng/579/097c0435765c4b2590d0c5af1e5bf4ea.jpg)
Monitor Shell
#!/bin/bash#Supported by Letianwhile [ "1"="1" ]dostill_running=$(ps -ef |grep 'mysql' |grep -v 'grep')if [ "still_runnig" ];then:elseservice nginx restartservice php5-fpm restartservice mysql restartfisleep 60done
加入系统服务
还需要把脚本添加为系统服务,让脚本开机自启动。本方法采用适用于linux-ubuntu与Debian系统中的update-rc.d(创建/注册系统服务) 。
编写服务脚本放在/etc/init.d下。
在/etc/rc*.d中制作相关的link。K开头是kill, S开头是start, 数字顺序代表启动的顺序。可以采用update-rc.d 简化过程。
这样建立了/etc/rc*.d中各种系统级别到脚本的软链接。然后执行命令
update-rc.d mysql-daemon start 90 1 2 3 4 5 . stop 52 0 6 .
start 90 1 2 3 4 5 . : 表示在1、2、3、4、5这五个运行级别中,按先后顺序,由小到大,第90个开始运行这个脚本。
stop 52 0 6 . :表示在0、6这两个运行级别中,按照先后顺序,由小到大,第52个停止这个脚本的运行。
关于update-rc.d
update-rc.d updates the System V style init script links /etc/rcrunlevel.d/NNname whose target is the script /etc/init.d/name. These links are run by init when it changes runlevels; they are generally used to start and stop system services such as daemons. runlevel is one of the runlevels supported by init, namely, 0123456789S, and NN is the two-digit sequence number that determines where in the sequence init will run the scripts.
update-rc.d命令,用来自动升级System V类型初始化脚本。简单的讲就是,哪些东西是你想要系统在引导初始化的时候运行的,哪些是希望在关机或重启时停止的,可以用它来帮你设置。这些脚本的连接位于/etc/rc*.d/LnName,对应脚本位于/etc/init.d/Script-name。
ubuntu与Debian 的update-rc.d与RH的chkconfig工具相类似。然而chkconfig是一个二进制程序,而update-rc.d是一个Perl脚本。这些工具有不同的命令行选项,但是却执行类似的功能。[1]
设置完这些,用service –status-all命令可以查看mysql-daemon是否存在系统服务中。
Reference
[1].http://blog.csdn.net/aa2650/article/details/6304049
[2].http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html
[3].http://xiaoxia.org/2011/11/15/create-a-simple-linux-daemon/
内容总结
以上是互联网集市为您收集整理的简单shell脚本监测mysql运行情况_MySQL全部内容,希望文章能够帮你解决简单shell脚本监测mysql运行情况_MySQL所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。