From c7e8add75a7a5294a9d401fd874fd5cc0d2ac25a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 15 Aug 2013 11:55:20 +0200 Subject: [PATCH] Vagrant: Install Icinga command proxy which routes commands to both instances refs #4549 --- .../files/etc/init.d/icinga_command_proxy | 71 +++++++++++++++++++ .../files/usr/local/bin/icinga_command_proxy | 42 +++++++++++ .vagrant-puppet/manifests/default.pp | 34 ++++++++- 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 .vagrant-puppet/files/etc/init.d/icinga_command_proxy create mode 100644 .vagrant-puppet/files/usr/local/bin/icinga_command_proxy diff --git a/.vagrant-puppet/files/etc/init.d/icinga_command_proxy b/.vagrant-puppet/files/etc/init.d/icinga_command_proxy new file mode 100644 index 000000000..68553b94a --- /dev/null +++ b/.vagrant-puppet/files/etc/init.d/icinga_command_proxy @@ -0,0 +1,71 @@ +#!/bin/bash +# +# chkconfig: 345 99 01 +# +### BEGIN INIT INFO +# Provides: icinga_command_proxy +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Should-Start: icinga +# Should-Stop: icinga +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +PROG="icinga_command_proxy" +BIN="/usr/local/bin/icinga_command_proxy" + +if [[ -f /etc/sysconfig/$PROG ]]; then + . /etc/sysconfig/$PROG +fi + +ICINGA_CMD=${ICINGA_CMD:-"/usr/local/icinga/var/rw/icinga.cmd"} +ICINGA_MYSQL_CMD=${ICINGA_MYSQL_CMD:-"/usr/local/icinga-mysql/var/rw/icinga.cmd"} +ICINGA_PGSQL_CMD=${ICINGA_PGSQL_CMD:-"/usr/local/icinga-pgsql/var/rw/icinga.cmd"} + +LOCKFILE=${LOCKFILE:-/var/lock/subsys/$PROG} +PIDFILE=${PIDFILE:-/var/lock/subsys/$PROG/$PROD.pid} + +RETVAL=0 + +start() { + echo -n $"Starting $PROG: " + daemon --pidfile="$PIDFILE" "nohup \"$BIN\" \"$ICINGA_CMD\" \"$ICINGA_MYSQL_CMD\" \"$ICINGA_PGSQL_CMD\" >/dev/null 2>&1 &" + RETVAL=$? + echo + [ $RETVAL = 0 ] && touch "$LOCKFILE" + return $RETVAL +} + +stop() { + echo -n $"Stopping $PROG: " + killproc -p "$PIDFILE" "$BIN" + RETVAL=$? + echo + [ $RETVAL = 0 ] && rm -f "$LOCKFILE" "$PIDFILE" +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status -p "$PIDFILE" "$BIN" + RETVAL=$? + ;; + restart) + stop + start + ;; + *) + echo $"Usage: $PROG {start|stop|restart|status}" + RETVAL=2 +esac + +exit $RETVAL + diff --git a/.vagrant-puppet/files/usr/local/bin/icinga_command_proxy b/.vagrant-puppet/files/usr/local/bin/icinga_command_proxy new file mode 100644 index 000000000..de7cb157c --- /dev/null +++ b/.vagrant-puppet/files/usr/local/bin/icinga_command_proxy @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Redirect commands from pipe A to pipe B and C +# + +set -e +set -u + +ICINGA_CMD=${1:-"/usr/local/icinga/var/rw/icinga.cmd"} +ICINGA_MYSQL_CMD=${2:-"/usr/local/icinga-mysql/var/rw/icinga.cmd"} +ICINGA_PGSQL_CMD=${3:-"/usr/local/icinga-pgsql/var/rw/icinga.cmd"} + +trap 'rm -f "$ICINGA_CMD"; exit' EXIT SIGKILL + +if [[ -p "$ICINGA_CMD" ]]; then + rm -f "$ICINGA_CMD" +fi + +mkfifo -m 660 "$ICINGA_CMD" +chown icinga.icinga-cmd "$ICINGA_CMD" + +while true +do + if read COMMAND + then + if [[ -p "$ICINGA_MYSQL_CMD" ]]; then + echo "$COMMAND" > "$ICINGA_MYSQL_CMD" + else + logger -p local0.err Can\'t distribute command to the Icinga MySQL instance since its command pipe doesn\'t exist + fi + if [[ -p "$ICINGA_PGSQL_CMD" ]]; then + echo "$COMMAND" > "$ICINGA_PGSQL_CMD" + else + logger -p local0.err Can\'t distribute command to the Icinga PostgreSQL instance since its command pipe doesn\'t exist + fi + fi +done < "$ICINGA_CMD" 3> "$ICINGA_CMD" + +# Reset all traps +trap - EXIT SIGKILL + +exit 0 diff --git a/.vagrant-puppet/manifests/default.pp b/.vagrant-puppet/manifests/default.pp index 876a75fc2..5789c4f71 100644 --- a/.vagrant-puppet/manifests/default.pp +++ b/.vagrant-puppet/manifests/default.pp @@ -448,7 +448,6 @@ populate_monitoring_test_config_plugins{ ['test_hostcheck.pl', 'test_servicechec Cmmi['icinga-pgsql'] ] } - # # Following section creates and populates MySQL and PostgreSQL Icinga 2 Web databases # @@ -460,7 +459,7 @@ exec { 'create-mysql-icingaweb-db': require => Service['mysqld'] } -exec{ 'create-pgsql-icingaweb-db': +exec { 'create-pgsql-icingaweb-db': unless => 'sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname=\'icingaweb\'" | grep -q 1', command => 'sudo -u postgres psql -c "CREATE ROLE icingaweb WITH LOGIN PASSWORD \'icinga\';" && \ sudo -u postgres createdb -O icingaweb -E UTF8 icingaweb && \ @@ -479,3 +478,34 @@ exec { 'populate-icingweba-pgsql-db': command => 'sudo -u postgres psql -U icingaweb -d icingaweb -f /vagrant/etc/schema/users.pgsql.sql', require => [ Exec['create-pgsql-icingaweb-db'] ] } + +# +# Following section creates the Icinga command proxy to /usr/local/icinga-mysql/var/rw/icinga.cmd (which is the +# config's default path for the Icinga command pipe) in order to send commands to both the MySQL and PostgreSQL instance +# +file { [ '/usr/local/icinga/', '/usr/local/icinga/var/', '/usr/local/icinga/var/rw/' ]: + ensure => directory, + owner => icinga, + group => icinga, + require => User['icinga'] +} + +file { '/usr/local/bin/icinga_command_proxy': + source => 'puppet:////vagrant/.vagrant-puppet/files/usr/local/bin/icinga_command_proxy', + owner => root, + group => root, + mode => 755 +} + +file { '/etc/init.d/icinga_command_proxy': + source => 'puppet:////vagrant/.vagrant-puppet/files/etc/init.d/icinga_command_proxy', + owner => root, + group => root, + mode => 755, + require => File['/usr/local/bin/icinga_command_proxy'] +} + +service { 'icinga_command_proxy': + ensure => running, + require => [ File['/etc/init.d/icinga_command_proxy'], Service['icinga-mysql'], Service['icinga-pgsql'] ] +}