Less verbose start output using the initscript

All output is dumped to startup.log and only shown in case of
'checkconfig' as parameter, but not during a reload/restart.

Furtermore some additional formatting to make it fit line by line.

fixes #5822
This commit is contained in:
Michael Friedrich 2014-06-12 16:05:45 +02:00
parent d9289add62
commit 6bebdddf98
2 changed files with 36 additions and 15 deletions

View File

@ -22,6 +22,7 @@ DAEMON_USER=nagios
DAEMON_GROUP=nagios DAEMON_GROUP=nagios
DAEMON_CMDGROUP=www-data DAEMON_CMDGROUP=www-data
DAEMON_ARGS="-e /var/log/icinga2/icinga2.err" DAEMON_ARGS="-e /var/log/icinga2/icinga2.err"
STARTUP_LOG="/var/log/icinga2/startup.log"
PIDFILE=/var/run/icinga2/$NAME.pid PIDFILE=/var/run/icinga2/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME SCRIPTNAME=/etc/init.d/$NAME
@ -128,10 +129,10 @@ do_reload() {
do_check_config () { do_check_config () {
DOEXITONOK="$1" DOEXITONOK="$1"
log_begin_msg "checking Icinga2 configuration" log_begin_msg "checking Icinga2 configuration"
if ! check_config >/dev/null 2>&1; then if ! check_config >$STARTUP_LOG 2>&1; then
echo echo
check_config [ -n "$DOEXITONOK" ] && cat $STARTUP_LOG
log_failure_msg "checking Icinga2 configuration" log_failure_msg "checking Icinga2 configuration. Check '$STARTUP_LOG' for details."
exit 1 exit 1
else else
log_end_msg 0 log_end_msg 0

View File

@ -20,6 +20,7 @@ ICINGA2_CONFIG_FILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf
ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@ ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@
ICINGA2_PID_FILE=$ICINGA2_STATE_DIR/run/icinga2/icinga2.pid ICINGA2_PID_FILE=$ICINGA2_STATE_DIR/run/icinga2/icinga2.pid
ICINGA2_ERROR_LOG=$ICINGA2_STATE_DIR/log/icinga2/error.log ICINGA2_ERROR_LOG=$ICINGA2_STATE_DIR/log/icinga2/error.log
ICINGA2_STARTUP_LOG=$ICINGA2_STATE_DIR/log/icinga2/startup.log
ICINGA2_LOG=$ICINGA2_STATE_DIR/log/icinga2/icinga2.log ICINGA2_LOG=$ICINGA2_STATE_DIR/log/icinga2/icinga2.log
ICINGA2_USER=@ICINGA2_USER@ ICINGA2_USER=@ICINGA2_USER@
ICINGA2_GROUP=@ICINGA2_GROUP@ ICINGA2_GROUP=@ICINGA2_GROUP@
@ -48,24 +49,34 @@ if [ -f /etc/default/icinga ]; then
. /etc/default/icinga . /etc/default/icinga
fi fi
# Start Icinga 2 check_run() {
start() {
mkdir -p $(dirname -- $ICINGA2_PID_FILE) mkdir -p $(dirname -- $ICINGA2_PID_FILE)
chown $ICINGA2_USER:$ICINGA2_GROUP $(dirname -- $ICINGA2_PID_FILE) chown $ICINGA2_USER:$ICINGA2_GROUP $(dirname -- $ICINGA2_PID_FILE)
if [ -f $ICINGA2_PID_FILE ]; then
chown $ICINGA2_USER:$ICINGA2_GROUP $ICINGA2_PID_FILE chown $ICINGA2_USER:$ICINGA2_GROUP $ICINGA2_PID_FILE
fi
mkdir -p $(dirname -- $ICINGA2_ERROR_LOG) mkdir -p $(dirname -- $ICINGA2_ERROR_LOG)
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $(dirname -- $ICINGA2_ERROR_LOG) chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $(dirname -- $ICINGA2_ERROR_LOG)
chmod 750 $(dirname -- $ICINGA2_ERROR_LOG) chmod 750 $(dirname -- $ICINGA2_ERROR_LOG)
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_ERROR_LOG $ICINGA2_LOG if [ -f $ICINGA2_ERROR_LOG ]; then
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_ERROR_LOG
fi
if [ -f $ICINGA2_LOG ]; then
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_LOG
fi
mkdir -p $ICINGA2_STATE_DIR/run/icinga2/cmd mkdir -p $ICINGA2_STATE_DIR/run/icinga2/cmd
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_STATE_DIR/run/icinga2/cmd chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_STATE_DIR/run/icinga2/cmd
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd
}
echo "Starting Icinga 2: " # Start Icinga 2
if ! $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP; then start() {
echo "Error starting Icinga." printf "Starting Icinga 2: "
if ! $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP > $ICINGA2_STARTUP_LOG 2>&1; then
echo "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details."
exit 1 exit 1
else else
echo "Done" echo "Done"
@ -75,6 +86,7 @@ start() {
# Restart Icinga 2 # Restart Icinga 2
stop() { stop() {
printf "Stopping Icinga 2: " printf "Stopping Icinga 2: "
if [ ! -e $ICINGA2_PID_FILE ]; then if [ ! -e $ICINGA2_PID_FILE ]; then
echo "The PID file '$ICINGA2_PID_FILE' does not exist." echo "The PID file '$ICINGA2_PID_FILE' does not exist."
if [ "x$1" = "xnofail" ]; then if [ "x$1" = "xnofail" ]; then
@ -122,18 +134,24 @@ reload() {
checkconfig() { checkconfig() {
printf "Checking configuration: " printf "Checking configuration: "
echo "Validating the configuration file:" if ! $DAEMON -c $ICINGA2_CONFIG_FILE -C -u $ICINGA2_USER -g $ICINGA2_GROUP > $ICINGA2_STARTUP_LOG 2>&1; then
if ! $DAEMON -c $ICINGA2_CONFIG_FILE -C -u $ICINGA2_USER -g $ICINGA2_GROUP; then
if [ "x$1" = "x" ]; then if [ "x$1" = "x" ]; then
echo "Icinga 2 detected configuration errors." cat $ICINGA2_STARTUP_LOG
echo "Icinga 2 detected configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
exit 1 exit 1
else else
echo "Not "$1"ing Icinga 2 due to configuration errors." echo "Not "$1"ing Icinga 2 due to configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
if [ "x$2" = "xfail" ]; then if [ "x$2" = "xfail" ]; then
exit 1 exit 1
fi fi
fi fi
fi fi
echo "Done"
# no arguments requires full output
if [ "x$1" = "x" ]; then
cat $ICINGA2_STARTUP_LOG
fi
} }
# Print status for Icinga 2 # Print status for Icinga 2
@ -149,6 +167,8 @@ status() {
fi fi
} }
check_run
### main logic ### ### main logic ###
case "$1" in case "$1" in
start) start)