linux開機啓動腳本示例

 腳本放置在下面的目錄

/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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章