Keep track of ads instances and delete unused instance if class apacheds::del is instanciated

This commit is contained in:
7u83 2020-07-25 09:10:17 +00:00
parent 6f6e465eac
commit 2e2ed5450b
1 changed files with 91 additions and 39 deletions

View File

@ -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,
)
{
}