]> granicus.if.org Git - icinga2/commitdiff
Migrate config files from conf.d/hosts to repository.d/hosts
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 28 Oct 2014 12:03:13 +0000 (13:03 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 28 Oct 2014 12:16:48 +0000 (13:16 +0100)
fixes #7398

debian/icinga2-common.install
debian/icinga2-common.postinst
icinga2.spec
tools/CMakeLists.txt
tools/migrate-hosts [new file with mode: 0644]

index 3badcf22190edd892cb1a66449dc937c27fb1bf9..22e356951062cc58c199e8e49251e8c3702d0e9c 100644 (file)
@@ -4,3 +4,4 @@ debian/tmp/etc/logrotate.d
 debian/tmp/etc/bash_completion.d
 tools/syntax/*                       usr/share/icinga2-common/syntax
 usr/share/icinga2
+usr/lib/icinga2/bin
index e1c6b49fdff30260535833cc769f7dd8a799770c..4b56639d8083b616d45d25cf31c560685a09c2f5 100644 (file)
@@ -64,6 +64,8 @@ case "$1" in
 
         # enable default features
         enable_default_features $@
+
+        /usr/share/icinga2/migrate-hosts
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
index 87782d0768a08bf8522268f8410b9b52f3747cda..fffd49e1805a12b89f9e8e946139b0c374276db2 100644 (file)
@@ -262,6 +262,8 @@ exit 0
 %endif
 %endif
 
+%post common
+/usr/share/icinga2/migrate-hosts
 
 # all restart/feature actions belong to icinga2-bin
 %post bin
index 1755fc3da052e57ef7f607af32204840fa4088fa..215ecd2e1f179d76a2e9abe1d4bc8387531269bd 100644 (file)
@@ -18,3 +18,9 @@
 add_subdirectory(mkclass)
 add_subdirectory(mkembedconfig)
 add_subdirectory(mkunity)
+
+install(
+  FILES ${CMAKE_CURRENT_SOURCE_DIR}/migrate-hosts
+  DESTINATION ${CMAKE_INSTALL_DATADIR}/icinga2
+  PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
+)
diff --git a/tools/migrate-hosts b/tools/migrate-hosts
new file mode 100644 (file)
index 0000000..d253b7a
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Moves configuration files from /etc/icinga2/conf.d/hosts
+# to /etc/icinga2/repository.d
+
+sysconfdir=`icinga2 variable get --current SysconfDir`
+
+if [ -z "$sysconfdir" ]; then
+    echo "Could not determine SysconfDir"
+    exit 1
+fi
+
+if [ ! -d $sysconfdir/icinga2/conf.d/hosts ]; then
+    exit 0
+fi
+
+mkdir -p $sysconfdir/icinga2/repository.d/hosts
+
+for hostFile in $sysconfdir/icinga2/conf.d/hosts/*.conf; do
+    host=`basename $hostFile .conf`
+
+    if [ "x$host" = "xlocalhost" ]; then
+        target="`hostname --fqdn`"
+    else
+        target=$host
+    fi
+
+    mv $sysconfdir/icinga2/conf.d/hosts/$host.conf $sysconfdir/icinga2/repository.d/hosts/$target.conf
+    sed -i "s/localhost/$target/g" $sysconfdir/icinga2/repository.d/hosts/$target.conf
+
+    if [ -d $sysconfdir/icinga2/conf.d/hosts/$host ]; then
+      mv $sysconfdir/icinga2/conf.d/hosts/$host $sysconfdir/icinga2/repository.d/hosts/$target
+      sed -i "s/localhost/$target/g" $sysconfdir/icinga2/repository.d/hosts/$target/*.conf
+    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
+
+exit 0