From 2e2ed5450bdd6db2aa156498ba606b630b08e365 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Sat, 25 Jul 2020 09:10:17 +0000 Subject: [PATCH] Keep track of ads instances and delete unused instance if class apacheds::del is instanciated --- manifests/apacheds.pp | 130 +++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 39 deletions(-) diff --git a/manifests/apacheds.pp b/manifests/apacheds.pp index 65e7591..2ef44bc 100644 --- a/manifests/apacheds.pp +++ b/manifests/apacheds.pp @@ -13,6 +13,11 @@ inherits ::plnxtools { $ads_home = "$opt_dir/$appname" + file {"opt_plnx_ads": + path => "$opt_dir/plnxtools/ads", + ensure => directory + } + package {"openldap-client": ensure => installed } @@ -35,6 +40,23 @@ inherits ::plnxtools } } +class plnxtools::apacheds::del( + $ensure = stopped +) +inherits plnxtools::apacheds +{ + $in = $facts['ads_instances'] + $in.each |$x| { + + if !defined(Plnxtools::Apacheds::Instance[$x]) { + plnxtools::apacheds::instance{$x: + partitionid => "$x", + partitionsuffix => "dc=$x,dc=org", + ensure => $ensure, + } + } + } +} define plnxtools::apacheds::instance( $ensure = running, @@ -45,48 +67,78 @@ define plnxtools::apacheds::instance( ) { $ads_instances = $plnxtools::apacheds::ads_instances - $log_file = "$plnxtools::apacheds::ads_logdir/$title.log" + if $ensure != purged { + $log_file = "$plnxtools::apacheds::ads_logdir/$title.log" - # - # Create a base 64 encoded ads-contextentry - # see: https://directory.apache.org/apacheds/basic-ug/1.4.3-adding-partition.html - # - $ads_contextentry0 = base64('encode',"dn: $partitionsuffix\ndc: uniadmin\nobjectclass: domain\nobjectclass: top\n\n") - $ads_contextentry = strip(regsubst($ads_contextentry0, '\n', "\n ")) + # + # Create a base 64 encoded ads-contextentry + # see: https://directory.apache.org/apacheds/basic-ug/1.4.3-adding-partition.html + # + $ads_contextentry0 = base64('encode',"dn: $partitionsuffix\ndc: $title\nobjectclass: domain\nobjectclass: top\n\n") + $ads_contextentry = strip(regsubst($ads_contextentry0, '\n', "\n ")) - file{"$ads_instances/$title": - ensure => directory - } -> - file{"$ads_instances/$title/conf": - ensure => directory - } -> - file{"$ads_instances/$title/log": - ensure => directory - } -> - file{"$ads_instances/$title/run": - ensure => directory - } -> - file{"$ads_instances/$title/conf/log4j.properties": - ensure => file, - content => template ("plnxtools/apacheds/log4j.properties.erb"), - }-> - file{"/tmp/ads-$title-config.ldif": - ensure => file, - content => template ("plnxtools/apacheds/config.ldif.erb"), - }-> - exec {"/bin/cp /tmp/ads-$title-config.ldif $ads_instances/$title/conf/config.ldif": - creates => "$ads_instances/$title/conf/config.ldif_migrated" + file{"$ads_instances/$title": + ensure => directory + } -> + file{"$ads_instances/$title/conf": + ensure => directory + } -> + file{"$ads_instances/$title/log": + ensure => directory + } -> + file{"$ads_instances/$title/run": + ensure => directory + } -> + file{"$ads_instances/$title/conf/log4j.properties": + ensure => file, + content => template ("plnxtools/apacheds/log4j.properties.erb"), + }-> + file{"/tmp/ads-$title-config.ldif": + ensure => file, + content => template ("plnxtools/apacheds/config.ldif.erb"), + }-> + exec {"/bin/cp /tmp/ads-$title-config.ldif $ads_instances/$title/conf/config.ldif": + creates => "$ads_instances/$title/conf/config.ldif_migrated" + } + + + $bin_dir = "${plnxtools::apacheds::opt_dir}/${plnxtools::apacheds::appname}/bin" + + file {"/opt/plnxtools/ads/$title": + ensure => file + }-> + service {"apacheds_${title}": + start => "$bin_dir/apacheds.sh $title start", + stop => "$bin_dir/apacheds.sh $title stop", + status => "$bin_dir/apacheds.sh $title status | grep 'is running'", + ensure => $ensure, + } + } + else{ + service {"apacheds_${title}": + start => "$bin_dir/apacheds.sh $title start", + stop => "$bin_dir/apacheds.sh $title stop", + status => "$bin_dir/apacheds.sh $title status | grep 'is running'", + ensure => stopped, + } -> + file {"/opt/plnxtools/ads/$title": + ensure => absent + } -> + file{"$ads_instances/$title": + ensure => absent, + force => true + } } - - - $bin_dir = "${plnxtools::apacheds::opt_dir}/${plnxtools::apacheds::appname}/bin" - - service {"apacheds_${title}": - start => "$bin_dir/apacheds.sh $title start", - stop => "$bin_dir/apacheds.sh $title stop", - status => "$bin_dir/apacheds.sh $title status | grep 'is running'", - ensure => running - } } + + +define plnxtools::apacheds::syncrepl( + $parition, + $consumer_id, +) +{ + +} +