linux开机启动脚本示例
作者 佚名技术
来源 Linux系统
浏览
发布时间 2012-04-04
脚本放置在下面的目录 /etc/rc.d/init.d/ 例如脚本名称为nagios_httpd #!/bin/bash # nagios_httpd a server monitor service. # chkconfig: 345 35 75 # description: a web server case "$1" in start) /usr/local/apache2_nagios/bin/apachectl start ;; restart) /usr/local/apache2_nagios/bin/apachectl restart ;; stop) /usr/local/apache2_nagios/bin/apachectl stop ;; esac exit 0 chkconfig --list|grep nagios_httpd chkconfig --add nagios_httpd chkconfig --levels 235 nagios_httpd on chkconfig --del nagios_httpd ================================================================================================= Nrpe 服务脚本(Nagios客户端服务脚本) #!/bin/bash # nrpe a nagios monitor client service. # chkconfig: 345 35 75 # description: a monitor server case "$1" in start) /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d echo "nrpe start" ;; restart) kill -9 $(ps -ef | grep ''/usr/local/nagios/bin/nrpe'' | grep -v grep | awk ''{printf $2}'') echo "nrpe stop" sleep 2 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d echo "nrpe start" ;; stop) kill -9 $(ps -ef | grep ''/usr/local/nagios/bin/nrpe'' | grep -v grep | awk ''{printf $2}'') echo "nrpe stop" ;; esac exit 0 chkconfig --list|grep nrpe chkconfig --add nrpe chkconfig --levels 235 nrpe on chkconfig --del nrpe ================================================================================================= 例如脚本名称为httpd #!/bin/bash # httpd a server WWW service. # chkconfig: 345 35 75 # description: a web server case "$1" in start) /usr/local/apache2/bin/apachectl start ;; restart) /usr/local/apache2/bin/apachectl restart ;; stop) /usr/local/apache2/bin/apachectl stop ;; esac exit 0 chkconfig --list|grep httpd chkconfig --add httpd chkconfig --levels 235 httpd on chkconfig --del httpd ================================================================================================= 例如脚本名称为lighttpd #!/bin/bash # lighttpd service. # chkconfig: 345 35 75 # description: a web server case "$1" in start) /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf echo "lighttpd start ok" ;; restart) ps aux |grep ''/usr/local/lighttpd/sbin/lighttpd''|grep -v grep|awk ''{print $2}''|awk ''{printf("%s ",$1)}''|xargs kill -9 /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf echo "lighttpd restart ok" ;; stop) ps aux |grep ''/usr/local/lighttpd/sbin/lighttpd''|grep -v grep|awk ''{print $2}''|awk ''{printf("%s ",$1)}''|xargs kill -9 echo "lighttpd stop ok" ;; esac exit 0 chkconfig --list|grep lighttpd chkconfig --add lighttpd chkconfig --levels 235 lighttpd on chkconfig --del lighttpd ================================================================================================= 例如脚本名称为nginx #!/bin/bash # nginx service. # chkconfig: 345 35 75 # description: a web server case "$1" in start) /usr/local/nginx/sbin/nginx echo "nginx start ok" ;; restart) ps aux |grep nginx:|grep -v grep|awk ''{print $2}''|awk ''{printf("%s ",$1)}''|xargs kill -9 /usr/local/nginx/sbin/nginx echo "nginx restart ok" ;; stop) ps aux |grep nginx:|grep -v grep|awk ''{print $2}''|awk ''{printf("%s ",$1)}''|xargs kill -9 echo "nginx stop ok" ;; esac exit 0 chkconfig --list|grep nginx chkconfig --add nginx chkconfig --levels 235 nginx on chkconfig --del nginx ================================================================================================= 例如脚本名称为rsync #!/bin/bash # rsync service. # chkconfig: 345 35 75 # description: a backup server case "$1" in start) /usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/etc/rsyncd.conf echo "rsync start ok" ;; restart) ps aux |grep /usr/local/rsync/etc/rsyncd.conf|grep -v grep|awk ''{print $2}''|awk ''{printf("%s ",$1)}''|xargs kill -9 rm -rf /usr/local/rsync/run/rsyncd.pid /usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/etc/rsyncd.conf echo "rsync restart ok" ;; stop) ps aux |grep /usr/local/rsync/etc/rsyncd.conf|grep -v grep|awk ''{print $2}''|awk ''{printf("%s ",$1)}''|xargs kill -9 rm -rf /usr/local/rsync/run/rsyncd.pid echo "rsync stop ok" ;; esac exit 0 chkconfig --list|grep rsyncd chkconfig --add rsyncd chkconfig --levels 235 rsyncd on chkconfig --del rsyncd
|
||
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: Linux CLI下一篇: RHEL5.4和CENTOS的YUM升级
关于linux开机启动脚本示例的所有评论