Migrate config files from conf.d/hosts to repository.d/hosts

fixes #7398
This commit is contained in:
Gunnar Beutner 2014-10-28 13:03:13 +01:00
parent 76444027e9
commit 876099fa0a
5 changed files with 64 additions and 0 deletions

View 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

View 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)

View 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

View 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
)

53
tools/migrate-hosts Normal file
View File

@ -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