您好,登錄后才能下訂單哦!
在做Nagios實驗中,需要反復(fù)通過命令重啟Nagios服務(wù)和Ndo2db服務(wù),非常麻煩。所以寫了個Ndo2db啟動腳本,供參考!
#!/bin/bash # Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # 調(diào)用functions,操作系統(tǒng)是Gentoo,functions在/etc/init.d目錄 if [ -f /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions elif [ -f /etc/init.d/functions ]; then . /etc/init.d/functions fi # 定義變量,一般情況下只需要修改prefix&&Ndo2dbBin就可以使用 prefix="/var/www/localhost/htdocs/nagios" Ndo2dbBin=${prefix}/bin/ndo2db-3x Ndo2dbCfgFile=${prefix}/etc/ndo2db.cfg Ndo2dbVarDir=${prefix}/var Ndo2dbRunFile=${prefix}/var/ndo2db.lock Ndo2dbCGIDir=${prefix}/sbin Ndo2dbUser=nagios Ndo2dbGroup=nagios # 判斷ndo2db是否啟動,如果啟動讀取進程號賦予Ndo2dbPID pid_ndo2db () { if [ ! -f $Ndo2dbRunFile ]; then echo "Ndo2db is already stoped." exit 1 else Ndo2dbPID=`head -n 1 $Ndo2dbRunFile` fi } # 沒什么好說的,殺死Ndo2db進程 killproc_ndo2db () { kill $Ndo2dbPID } # 根據(jù)var/ndo2db.lock來判斷ndo2db服務(wù)狀態(tài) printstatus_ndo2db () { if [ ! -f $Ndo2dbRunFile ]; then echo "ndo2db is not running" else echo "ndo2db (pid $Ndo2dbPID) is running..." fi } # 確認存在ndo2dbbin文件,否則非法退出。 if [ ! -f $Ndo2dbBin ]; then echo "executable file $Ndo2dbBin not found. Exiting." exit 1 fi # 確認存在ndo2db配置文件,否則非法退出。 if [ ! -f $Ndo2dbCfgFile ]; then echo "Configuration file $Ndo2dbCfgFile not found. Exiting." exit 1 fi # start開啟服務(wù),stop停止服務(wù),status查看服務(wù)狀態(tài),restart重啟服務(wù) case "$1" in start) echo -n "starting ndo2db:" $Ndo2dbBin -c $Ndo2dbCfgFile echo " done." ;; stop) echo -n "stoping ndo2db:" pid_ndo2db killproc_ndo2db killall -q ndo2db-3x echo " done." ;; status) pid_ndo2db printstatus_ndo2db ;; restart) $0 stop $0 start ;; *) echo "Usage: ndo2db {start|stop|restart|status}" exit 1 ;; esac # 實際操作 # 1、拷貝腳本到/etc/init.d下,vi ndo2db # 2、添加腳本執(zhí)行權(quán)限chmod +x ndo2db # 3、啟動服務(wù)/etc/init.d/ndo2db start,停止服務(wù)/etc/init.d/ndo2db stop,查看服務(wù)/etc/init.d/ndo2db status,重啟服務(wù)/etc/init.d/ndo2db restart. # 初次寫模塊化腳本,如果有問題,請指正,謝謝!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。