[icinga-checkins] icinga.org: icinga2/feature/memory-usage: Change migrate-hosts to remove repository.d/hosts/fqdn

git at icinga.org git at icinga.org
Fri Nov 7 10:46:47 CET 2014


Module: icinga2
Branch: feature/memory-usage
Commit: 9c60a82c877a91d81085a203e2ece249ce6a3ada
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=9c60a82c877a91d81085a203e2ece249ce6a3ada

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri Nov  7 01:01:12 2014 +0100

Change migrate-hosts to remove repository.d/hosts/fqdn

Create a backup, and drop that later.

refs #7398

---

 tools/migrate-hosts.cmake |   84 +++++++++------------------------------------
 1 file changed, 16 insertions(+), 68 deletions(-)

diff --git a/tools/migrate-hosts.cmake b/tools/migrate-hosts.cmake
index abe2925..5e2d17e 100644
--- a/tools/migrate-hosts.cmake
+++ b/tools/migrate-hosts.cmake
@@ -1,83 +1,31 @@
 #!/bin/sh
-# Moves configuration files from /etc/icinga2/conf.d/hosts
-# to /etc/icinga2/repository.d
+# Moves configuration files from /etc/icinga2/conf.d/hosts/<fqdn>
+# as backup files. TODO: Remove script before 2.2 release.
 
 icinga2bin=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2
 sysconfdir=`$icinga2bin variable get --current SysconfDir`
 
 if [ -z "$sysconfdir" ]; then
-    echo "Could not determine SysconfDir"
-    exit 1
+    	echo "Could not determine SysconfDir"
+    	exit 1
 fi
 
-if [ ! -d $sysconfdir/icinga2/conf.d/hosts ]; then
-    exit 0
+target="`hostname -f`"
+if [ ! -e $sysconfdir/icinga2/repository.d/hosts/$target.conf ]; then
+    	exit 0
 fi
 
-mkdir -p $sysconfdir/icinga2/repository.d/hosts
+mv $sysconfdir/icinga2/repository.d/hosts/$target.conf $sysconfdir/icinga2/repository.d/hosts/$target.conf.bak
 
-host_count=0
-service_count=0
-
-for hostFile in $sysconfdir/icinga2/conf.d/hosts/*.conf; do
-    if [ ! -e $hostFile ]; then
-        continue
-    fi
-
-    host_count=$(($host_count + 1))
-
-    host=`basename $hostFile .conf`
-
-    if [ "x$host" = "xlocalhost" ]; then
-        target="`hostname -f`"
-    else
-        target=$host
-    fi
-
-    if [ ! -e $sysconfdir/icinga2/repository.d/hosts/$target.conf ]; then
-        mv $sysconfdir/icinga2/conf.d/hosts/$host.conf $sysconfdir/icinga2/repository.d/hosts/$target.conf
-        sed "s/localhost/$target/g" $sysconfdir/icinga2/repository.d/hosts/$target.conf > $sysconfdir/icinga2/repository.d/hosts/$target.conf.tmp
-        mv $sysconfdir/icinga2/repository.d/hosts/$target.conf.tmp $sysconfdir/icinga2/repository.d/hosts/$target.conf
-    else
-        rm -f $sysconfdir/icinga2/conf.d/hosts/$host.conf
-    fi
-
-    if [ -d $sysconfdir/icinga2/conf.d/hosts/$host ]; then
-        service_count=$(($service_count + 1))
-
-        if [ ! -e $sysconfdir/icinga2/repository.d/hosts/$target ]; then
-            mv $sysconfdir/icinga2/conf.d/hosts/$host $sysconfdir/icinga2/repository.d/hosts/$target
-            for file in $sysconfdir/icinga2/repository.d/hosts/$target/*.conf; do
-                if [ ! -e $file ]; then
-                    break
+if [ -d $sysconfdir/icinga2/repository.d/hosts/$target ]; then
+	for file in $sysconfdir/icinga2/repository.d/hosts/$target/*.conf; do
+        	if [ ! -e $file ]; then
+           		break
                 fi
 
-                sed "s/localhost/$target/g" $file > $file.tmp
-                mv $file.tmp $file
-            done
-        else
-            rm -rf $sysconfdir/icinga2/conf.d/hosts/$host
-        fi
-    fi
-done
-
-cat >$sysconfdir/icinga2/conf.d/hosts/README <<TEXT
-What happened to my configuration files?
-========================================
-
-Your host and service configuration files were moved to the $sysconfdir/icinga2/repository.d directory.
-
-This allows you to manipulate those files using the "icinga2 repository" CLI commands.
-
-Here are a few commands you might want to try:
-
-# icinga2 repository host list
-
-# icinga2 repository service list
-
-# icinga2 repository --help
-TEXT
-
-echo "Migrated $host_count host(s) and $service_count service(s)."
+		mv $file $file.bak
+	done
+fi
 
+echo "Moved repository FQDN host in $sysconfdir/icinga2/repository.d/hosts/$target as backup. Please migrate your changes to all new conf.d/{hosts,services.conf}"
 exit 0



More information about the icinga-checkins mailing list