mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
Vagrant: Install Icinga command proxy which routes commands to both instances
refs #4549
This commit is contained in:
parent
e0f1d7dc37
commit
c7e8add75a
71
.vagrant-puppet/files/etc/init.d/icinga_command_proxy
Normal file
71
.vagrant-puppet/files/etc/init.d/icinga_command_proxy
Normal file
@ -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
|
||||
|
42
.vagrant-puppet/files/usr/local/bin/icinga_command_proxy
Normal file
42
.vagrant-puppet/files/usr/local/bin/icinga_command_proxy
Normal file
@ -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
|
@ -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'] ]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user