create a skeleton init script for monitor-nagios. not sure if this really
authorStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 18 Jun 2010 22:57:02 +0000 (22:57 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 18 Jun 2010 22:57:02 +0000 (22:57 +0000)
needs to run every time, since setup only needs to happen once.

Monitor.spec
nagios/monitor-nagios.init [new file with mode: 0644]

index e3f70cb..ac97879 100644 (file)
@@ -156,8 +156,7 @@ install -d $RPM_BUILD_ROOT/%{python_sitearch}/monitor
 install -D -m 644 monitor.functions $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/monitor.functions
 install -D -m 755 monitor-server.init $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/monitor
 install -D -m 755 zabbix/monitor-zabbix.init $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/zabbix
-# TODO: update with a real init file
-install -D -m 755 monitor-server.init $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/monitor-nagios
+install -D -m 755 nagios/monitor-nagios.init $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/monitor-nagios
 
 # cron job for automated polling
 install -D -m 644 monitor-server.cron $RPM_BUILD_ROOT/%{_sysconfdir}/cron.d/monitor-server.cron
@@ -204,7 +203,6 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(-,root,root)
 %{_sysconfdir}/plc.d/monitor-nagios
 /usr/share/%{name}/nagios 
-# TODO: not sure how this will impact the server files
 
 %files server
 %defattr(-,root,root)
@@ -316,6 +314,9 @@ fi
 
 %post nagios
 # TODO: do as much as possible to get the host setup and running.
+chkconfig --add monitor-nagios
+chkconfig monitor-nagios on
+chkconfig mysqld on
 
 %post server
 # TODO: this will be nice when we have a web-based service running., such as
diff --git a/nagios/monitor-nagios.init b/nagios/monitor-nagios.init
new file mode 100644 (file)
index 0000000..1b390fd
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/bash
+# 
+# chkconfig: - 65 35
+#
+# Provides: monitor-nagios
+# Required-Start: mysqld sendmail
+# Defalt-Start: 3 4 5
+# Default-Stop: 0 1 2 6
+# Description: Setup requirements for monitor to work with nagios
+# 
+# Stephen Soltesz <soltesz@cs.princeton.edu>
+# Copyright (C) 2010 The Trustees of Princeton University
+#
+# $Id$
+#
+
+. /etc/plc.d/functions
+. /etc/plc.d/monitor.functions
+. /etc/planetlab/plc_config
+
+# NOTE: expect that mysqld is already started.
+
+start () {
+
+       # if it's a fresh install, there is no root passwd.
+       if $( mysqladmin -u root create nagios ) ; then
+               cat <<EOF > /tmp/nagios.priv
+   GRANT ALL PRIVILEGES ON nagios.* TO ndouser@localhost IDENTIFIED BY 'ndopassword';
+EOF
+               cat /tmp/nagios.priv | mysql -u root
+
+               cd /usr/share/doc/ndoutils-mysql-*/db
+               perl ./installdb -u ndouser -p ndopassword -d nagios
+       fi
+
+       if ! $( grep -q /usr/lib/nagios/brokers/ndomod.so  /etc/nagios/nagios.cfg ) ; then 
+               echo "broker_module=/usr/lib/nagios/brokers/ndomod.so config_file=/etc/nagios/ndomod.cfg" >> /etc/nagios/nagios.cfg
+               echo "foo"
+       fi
+
+       /sbin/chkconfig ndo2db on
+       #/sbin/service ndo2db start
+       #/sbin/service nagios restart
+
+       ## set passwd for /etc/nagios/passwd
+       htpasswd -b -c /etc/nagios/passwd nagiosadmin nagiospassword
+
+       # disable /etc/httpd/conf.d/nagios.conf restriction to only 127.0.0.1
+       if $( grep -q -E "^   deny from all" /etc/httpd/conf.d/nagios.conf ) ; then
+               sed -i -e 's/   deny from all/   allow from all/g' /etc/httpd/conf.d/nagios.conf 
+               sed -i -e 's/   order deny,allow/   order allow,deny/g' /etc/httpd/conf.d/nagios.conf 
+               sed -i -e 's/   allow from 127.0.0.1/   /g' /etc/httpd/conf.d/nagios.conf 
+       fi
+
+       touch /etc/nagios/objects/plc.cfg
+       touch /etc/nagios/objects/plcusers.cfg
+       echo "cfg_file=/etc/nagios/objects/plc.cfg" >> /etc/nagios/nagios.cfg
+       echo "cfg_file=/etc/nagios/objects/plcusers.cfg" >> /etc/nagios/nagios.cfg
+
+       /sbin/chkconfig sendmail on
+       /sbin/service sendmail start
+
+       # change /etc/nagios/objects/contacts.cfg to some real email addr
+       # change /etc/nagios/nagios.cfg admin_email to some real email addr
+
+}
+
+
+# See how we were called.
+case "$1" in
+  start)
+    start
+    ;;
+  stop)
+    echo "not implemented"
+    ;;
+  status)
+    echo "not implemented"
+    ;;
+  restart)
+    echo "not implemented"
+    ;;
+  *)
+    echo $"Usage: $0 {start|stop|status|condrestart|restart}"
+    exit 1
+esac
+
+exit $?