温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nagios下ndo2db服务启动脚本

发布时间:2020-09-16 12:56:02 来源:网络 阅读:1593 作者:chengchow 栏目:移动开发

在做Nagios实验中,需要反复通过命令重启Nagios服务和Ndo2db服务,非常麻烦。所以写了个Ndo2db启动脚本,供参考!

#!/bin/bash
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# 调用functions,操作系统是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
}
# 根据var/ndo2db.lock来判断ndo2db服务状态
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开启服务,stop停止服务,status查看服务状态,restart重启服务
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、添加脚本执行权限chmod +x ndo2db
# 3、启动服务/etc/init.d/ndo2db start,停止服务/etc/init.d/ndo2db stop,查看服务/etc/init.d/ndo2db status,重启服务/etc/init.d/ndo2db restart.
# 初次写模块化脚本,如果有问题,请指正,谢谢!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI