As installing finishes icinga, icinga-web, and pnp4nagios, it's necessary to setup init scripts to run and stop daemon. Of course, each of the source files includes ones, but I prefer a typical format based on RPM package to the ones in the source file. So I modified the init scripts based on RPM packages.
I am going to introduce of each of the init scripts and verification about how they work.
They are open to the public in my github.
icinga
- create init script based on nagios RPM package
The patch file is stored here.
# yumdownloader --enablerepo=rpmforge icinga
# mkdir work
# cd work
# rpm2cpio ../ nagios-3.2.3-3.el5.rf.x86_64.rpm | cpid -id ./etc/rc.d/init.d/nagios
# cp etc/rc.d/init.d/nagios ./icinga
# cp icinga{,_diff}
...
# diff -c icinga icinga_diff > icinga.patch
# patch -p0 < icinga.patch
# cp icinga /etc/init.d/icinga
# /etc/init.d/icinga start
Starting icinga: [ OK ]
# /etc/init.d/icinga stop
Stopping icinga: [ OK ]
# /etc/init.d/icinga restart
Stopping icinga: [ OK ]
Starting icinga: [ OK ]
# /etc/init.d/icinga condrestart
Stopping icinga: [ OK ]
Starting icinga: [ OK ]
# /etc/init.d/icinga reload
icinga (pid 17359) is running...
Reloading icinga: [ OK ]
- check if daemon is running
# /etc/init.d/icinga status
icinga (pid 17359) is running...
- difference between nagios(rpmpackage) and icinga
# diff -u nagios icinga_diff
--- nagios 2012-05-01 23:34:15.000000000 +0900
+++ icinga_diff 2012-05-03 20:52:17.000000000 +0900
@@ -1,36 +1,38 @@
#!/bin/sh
# $Id$
-# Nagios Startup script for the Nagios monitoring daemon
+# Icinga Startup script for the Nagios monitoring daemon
#
# chkconfig: - 85 15
-# description: Nagios is a service monitoring system
-# processname: nagios
-# config: /etc/nagios/nagios.cfg
-# pidfile: /var/nagios/nagios.pid
+# description: Icinga is a service monitoring system
+# processname: icinga
+# config: /usr/local/icinga/etc/icinga.cfg
+# pidfile: /var/run/icinga.pid
#
### BEGIN INIT INFO
-# Provides: nagios
+# Provides: icinga
# Required-Start: $local_fs $syslog $network
# Required-Stop: $local_fs $syslog $network
-# Short-Description: start and stop Nagios monitoring server
-# Description: Nagios is is a service monitoring system
+# Short-Description: start and stop Icinga monitoring server
+# Description: Icinga is is a service monitoring system
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
-prefix="/usr"
-exec_prefix="/usr"
-exec="/usr/bin/nagios"
-prog="nagios"
-config="/etc/nagios/nagios.cfg"
-pidfile="/var/nagios/nagios.pid"
-user="nagios"
+user="icinga"
+prog="icinga"
+prefix="/usr/local/$prog"
+exec_prefix="${prefix}"
+exec="${prefix}/bin/$prog"
+config="${prefix}/etc/$prog.cfg"
+piddir="/var/run"
+lockdir="/var/lock/subsys"
+pidfile="$piddir/$prog.pid"
+lockfile="${lockdir}/$prog"
+[ -d "$piddir" ] || mkdir -p piddir && chown $prog:$prog $piddir
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
-lockfile=/var/lock/subsys/$prog
-
start() {
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
@@ -47,7 +49,7 @@
killproc -d 10 $exec
retval=$?
echo
- [ $retval -eq 0 ] && rm -f $lockfile
+ [ $retval -eq 0 ] && rm -f $lockfile $pidfile
return $retval
}
@@ -60,7 +62,7 @@
reload() {
echo -n $"Reloading $prog: "
killproc $exec -HUP
- RETVAL=$?
+ retval=$?
echo
}
@@ -70,8 +72,8 @@
check_config() {
$nice runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -v $config > /dev/null 2>&1"
- RETVAL=$?
- if [ $RETVAL -ne 0 ] ; then
+ retval=$?
+ if [ $retval -ne 0 ] ; then
echo -n $"Configuration validation failed"
failure
echo
- about the pidfile and the lockfile path
Icinga.cfg(also nagios.cfg) defines lockfile as pidfile.
I'm not sure why they're defined as so, but I think they should be separated.
I defined he path of pidfile and lockfile in the init script and icinga.cfg
# grep '^lock_file'icinga.cfg
lock_file=/var/run/icinga.pid
# egrep '^(pid|lock)' /etc/init.d/icinga
piddir="/var/run"
lockdir="/var/lock/subsys"
pidfile="$piddir/$prog.pid"
lockfile="${lockdir}/$prog"
ido2db
- create init script for ndoutils based on ndo2utils RPM packageThe patch file is stored here.
# yumdownloader --enablerepo=rpmforge ndo2utils
# mkdir work
# cd work
# rpm2cpio ../ndoutils-1.4-0.beta7.3.el5.rf.x86_64.rpm | cpio -id ./etc/init.d/ndoutils
# cp etc/init.d/ndoutils ./ido2db
# cp ido2db{,_diff}
# vi ido2db_diff
...
# diff -c ido2db ido2db_diff > ido2db.patch
# patch -p0 < ido2db.patch
# cp ido2db /etc/init.d/ido2db
# /etc/init.d/ido2db start
Starting ido2db: [ OK ]
# /etc/init.d/ido2db stop
Stopping ido2db: [ OK ]
# /etc/init.d/ido2db restart
Stopping ido2db: [ OK ]
Starting ido2db: [ OK ]
# /etc/init.d/ido2db condrestart
Stopping ido2db: [ OK ]
Starting ido2db: [ OK ]
- difference between ndo2utils(rpmpackage) and ido2db
# diff ndoutils ndoutils_diff
@@ -1,37 +1,42 @@
#!/bin/sh
-# Startup script for ndo-daemon
+# Startup script for ido2db-daemon
#
# chkconfig: 2345 95 05
-# description: Nagios Database Objects daemon
+# description: Icinga Database Objects daemon
# Source function library.
. /etc/rc.d/init.d/functions
-
-BINARY=ndo2db-3x
-DAEMON=/usr/sbin/$BINARY
-CONFIG=/etc/nagios/ndo2db.cfg
-
-[ -f $DAEMON ] || exit 0
-
-prog="ndo2db"
+prog=ido2db
+user=icinga
+prefix=/usr/local/icinga
+exec=$prefix/bin/$prog
+config=$prefix/etc/ido2db.cfg
+piddir="/var/run"
+lockdir="/var/lock/subsys"
+pidfile="$piddir/$prog.pid"
+lockfile="${lockdir}/$prog"
start() {
+ [ -x $exec ] || exit 5
+ [ -f $config ] || exit 6
echo -n $"Starting $prog: "
- daemon --user nagios $DAEMON -c $CONFIG
- RETVAL=$?
+ daemon --user $user $exec -c $config
+ retval=$?
+ [ $retval -eq 0 ] && touch $lockfile
echo
- return $RETVAL
+ return $retval
}
stop() {
- if test "x`pidof $BINARY`" != x; then
+ if test "x`pidof $prog`" != x; then
echo -n $"Stopping $prog: "
- killproc ndo2db-3x
+ killproc $prog
echo
fi
- RETVAL=$?
- return $RETVAL
+ retval=$?
+ [ $retval -eq 0 ] && rm -f $lockfile $pidfile
+ return $retval
}
case "$1" in
@@ -44,14 +49,14 @@
;;
status)
- status $BINARY
+ status $prog
;;
restart)
stop
start
;;
condrestart)
- if test "x`pidof $BINARY`" != x; then
+ if test "x`pidof $prog`" != x; then
stop
start
fi
@@ -63,5 +68,5 @@
esac
-exit $RETVAL
+exit $retval
- about the pidfile and the lockfile path
Icinga.cfg(also nagios.cfg) defines lockfile as pidfile.
I'm not sure why they're defined as so, but I think they should be separated.
I defined he path of pidfile and lockfile in the init script and icinga.cfg
# grep '^lock_file'ido2db.cfg
lock_file=/var/run/ido2db.pid
# egrep '^(pid|lock)' /etc/init.d/icinga
piddir="/var/run"
lockdir="/var/lock/subsys"
pidfile="$piddir/$prog.pid"
lockfile="${lockdir}/$prog"
npcd
- create init script for npcd based on nagios RPM packageThe patch file is stored here.
# yumdownloader --enablerepo=rpmforge icinga
# mkdir work
# cd work
# rpm2cpio ../ nagios-3.2.3-3.el5.rf.x86_64.rpm | cpid -id ./etc/rc.d/init.d/nagios
# cp etc/rc.d/init.d/nagios ./npcd
# cp npcd{,_diff}
...
# diff -c npcd npcd_diff > npcd.patch
# patch -p0 < npcd.patch
# cp npcd /etc/init.d/npcd
# /etc/init.d/npcd start
npcd is stopped
Starting npcd: [ OK ]
# /etc/init.d/npcd stop
npcd (pid 14128) is running...
Stopping npcd: [ OK ]
# /etc/init.d/npcd restart
Starting npcd: [ OK ]
Starting npcd: [ OK ]
# /etc/init.d/npcd condrestart
npcd (pid 14216) is running...
Stopping npcd: [ OK ]
Starting npcd: [ OK ]
# /etc/init.d/npcd reload
npcd (pid 14233) is running...
Reloading npcd: [ OK ]
- check if daemon is running
# /etc/init.d/npcd status
npcd (pid 14233) is running...
- difference between nagios(rpmpackage) and npcd
# diff -u npcd npcd_diff
--- npcd 2012-05-04 10:47:11.000000000 +0900
+++ npcd_diff 2012-05-03 22:45:28.000000000 +0900
@@ -1,41 +1,40 @@
#!/bin/sh
-# $Id$
-# Nagios Startup script for the Nagios monitoring daemon
-#
-# chkconfig: - 85 15
-# description: Nagios is a service monitoring system
-# processname: nagios
-# config: /etc/nagios/nagios.cfg
-# pidfile: /var/nagios/nagios.pid
#
### BEGIN INIT INFO
-# Provides: nagios
-# Required-Start: $local_fs $syslog $network
-# Required-Stop: $local_fs $syslog $network
-# Short-Description: start and stop Nagios monitoring server
-# Description: Nagios is is a service monitoring system
+# Short-Description: pnp4nagios NPCD Daemon Version 0.6.16
+# Description: Nagios Performance Data C Daemon
+# chkconfig: 345 99 01
+# processname: npcd
+# config: /usr/local/pnp4nagios/etc/npcd.cfg
+# pidfile: /var/run/npcd.pid
+# Provides: npcd
+# Required-Start:
+# Required-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
-prefix="/usr"
-exec_prefix="/usr"
-exec="/usr/bin/nagios"
-prog="nagios"
-config="/etc/nagios/nagios.cfg"
-pidfile="/var/nagios/nagios.pid"
-user="nagios"
+user="icinga"
+prog="npcd"
+prefix="/usr/local/pnp4nagios"
+exec_prefix="${prefix}"
+exec="${prefix}/bin/$prog"
+config="${prefix}/etc/$prog.cfg"
+piddir="/var/run"
+lockdir="/var/lock/subsys"
+pidfile="/var/run/$prog.pid"
+lockfile="${lockdir}/$prog"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
-lockfile=/var/lock/subsys/$prog
-
start() {
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
echo -n $"Starting $prog: "
- daemon --user=$user $exec -d $config
+ daemon --user=$user $exec -d -f $config
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
@@ -47,7 +46,7 @@
killproc -d 10 $exec
retval=$?
echo
- [ $retval -eq 0 ] && rm -f $lockfile
+ [ $retval -eq 0 ] && rm -f $lockfile $pidfile
return $retval
}
@@ -60,31 +59,14 @@
reload() {
echo -n $"Reloading $prog: "
killproc $exec -HUP
- RETVAL=$?
+ retval=$?
echo
}
-force_reload() {
- restart
-}
-
-check_config() {
- $nice runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -v $config > /dev/null 2>&1"
- RETVAL=$?
- if [ $RETVAL -ne 0 ] ; then
- echo -n $"Configuration validation failed"
- failure
- echo
- exit 1
-
- fi
-}
-
case "$1" in
start)
status $prog && exit 0
- check_config
$1
;;
stop)
@@ -92,33 +74,21 @@
$1
;;
restart)
- check_config
$1
;;
reload)
status $prog || exit 7
- check_config
$1
;;
- force-reload)
- check_config
- force_reload
- ;;
status)
status $prog
;;
- condrestart|try-restart)
+ condrestart)
status $prog|| exit 0
- check_config
restart
;;
- configtest)
- echo -n $"Checking config for $prog: "
- check_config && success
- echo
- ;;
*)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
exit 2
esac
exit $?
I will list the other configurations for icinga, idoutils, and pnp4nagios next time.
No comments:
Post a Comment