Blob Blame History Raw
From d88650af2dc614519bdb138b162d3c6e3b5ae9c5 Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Tue, 18 Aug 2015 13:43:55 -0700
Subject: [PATCH 47/47] Ticket #48243 - replica upgrade failed in starting
 dirsrv service due to upgrade scripts did not run

Description: In the upgrade process, there is a combination of requirements:
 . the server is running.
 . the server instance service is disabled.
 . upgrade scripts are expected to run against the instance.
 . the server is restarted once the upgrade is done.
 . the server instance service remains disabled.
To fulfill the requirements,
 . spec file is modified to enumerate slapd dir (except .remove) in the
   /etc/dirsrv for getting the server instance.
 . Start/Update perl scripts are modified not to create a symlink in
   /etc/systemd/system/dirsrv.target.wants for the upgrade case, which
   means the service remains disabled.

https://fedorahosted.org/389/ticket/48243

Reviewed by mreynolds@redhat.com (Thank you, Mark!!)

(cherry picked from commit 29c09a5bcc7d54be1aa6880b4f2a423edd3dc463)
(cherry picked from commit 2c5e0d5692bcabe16a7e3b8e0d24eb3a88913155)
---
 ldap/admin/src/scripts/DSCreate.pm.in    |  7 ++++---
 ldap/admin/src/scripts/DSMigration.pm.in |  2 +-
 ldap/admin/src/scripts/DSUpdate.pm.in    |  2 +-
 rpm/389-ds-base.spec.in                  | 20 +++++++++++++-------
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/ldap/admin/src/scripts/DSCreate.pm.in b/ldap/admin/src/scripts/DSCreate.pm.in
index e4a4ed0..cdde339 100644
--- a/ldap/admin/src/scripts/DSCreate.pm.in
+++ b/ldap/admin/src/scripts/DSCreate.pm.in
@@ -1098,6 +1098,7 @@ sub updateTmpfilesDotD {
 }
 
 sub updateSystemD {
+    my $noservicelink = shift;
     my $inf = shift;
     my $unitdir = "@systemdsystemunitdir@";
     my $confbasedir = "@systemdsystemconfdir@";
@@ -1129,7 +1130,7 @@ sub updateSystemD {
             next;
         } else {
             my $servicelink = "$confdir/$pkgname\@$inst.service";
-            if (! -l $servicelink) {
+            if (! -l $servicelink && ! $noservicelink) {
                 if (!symlink($servicefile, $servicelink)) {
                     debug(1, "error updating link $servicelink to $servicefile - $!\n");
                     push @errs, [ 'error_linking_file', $servicefile, $servicelink, $! ];
@@ -1216,7 +1217,7 @@ sub createDSInstance {
         return @errs;
     }
 
-    if (@errs = updateSystemD($inf)) {
+    if (@errs = updateSystemD(0, $inf)) {
         return @errs;
     }
 
@@ -1452,7 +1453,7 @@ sub removeDSInstance {
     }
 
     # update systemd files
-    push @errs, updateSystemD();
+    push @errs, updateSystemD(0);
     
     # if we got here, report success
     if (@errs) {
diff --git a/ldap/admin/src/scripts/DSMigration.pm.in b/ldap/admin/src/scripts/DSMigration.pm.in
index e59e667..630ab43 100644
--- a/ldap/admin/src/scripts/DSMigration.pm.in
+++ b/ldap/admin/src/scripts/DSMigration.pm.in
@@ -1132,7 +1132,7 @@ sub migrateDS {
         }
 
 	# do the systemd stuff
-        @errs = DSCreate::updateSystemD($inf);
+        @errs = DSCreate::updateSystemD(0, $inf);
         if (@errs) {
             $mig->msg(@errs);
             goto cleanup;
diff --git a/ldap/admin/src/scripts/DSUpdate.pm.in b/ldap/admin/src/scripts/DSUpdate.pm.in
index 1809ad9..be1e67c 100644
--- a/ldap/admin/src/scripts/DSUpdate.pm.in
+++ b/ldap/admin/src/scripts/DSUpdate.pm.in
@@ -408,7 +408,7 @@ sub updateDSInstance {
 
     push @errs, updateTmpfilesDotD($inf);
 
-    push @errs, updateSystemD($inf);
+    push @errs, updateSystemD(1, $inf);
 
     return @errs;
 }
diff --git a/rpm/389-ds-base.spec.in b/rpm/389-ds-base.spec.in
index d0bbb7a..b7556e1 100644
--- a/rpm/389-ds-base.spec.in
+++ b/rpm/389-ds-base.spec.in
@@ -248,6 +248,7 @@ rm -rf $RPM_BUILD_ROOT
 
 %post
 output=/dev/null
+output2=/dev/null
 %systemd_post %{pkgname}-snmp.service
 # reload to pick up any changes to systemd files
 /bin/systemctl daemon-reload >$output 2>&1 || :
@@ -260,12 +261,17 @@ instances="" # instances that require a restart after upgrade
 ninst=0 # number of instances found in total
 if [ -n "$DEBUGPOSTTRANS" ] ; then
    output=$DEBUGPOSTTRANS
+   output2=${DEBUGPOSTTRANS}.upgrade
 fi
-echo looking for services in %{_sysconfdir}/systemd/system/%{groupname}.wants/* >> $output 2>&1 || :
-for service in %{_sysconfdir}/systemd/system/%{groupname}.wants/* ; do
-    if [ ! -f "$service" ] ; then continue ; fi # in case nothing matches
-    inst=`echo $service | sed -e 's,%{_sysconfdir}/systemd/system/%{groupname}.wants/,,'`
-    echo found instance $inst - getting status >> $output 2>&1 || :
+echo looking for instances in %{_sysconfdir}/%{pkgname} > $output 2>&1 || :
+instbase="%{_sysconfdir}/%{pkgname}"
+for dir in $instbase/slapd-* ; do
+    echo dir = $dir >> $output 2>&1 || :
+    if [ ! -d "$dir" ] ; then continue ; fi
+    case "$dir" in *.removed) continue ;; esac
+    basename=`basename $dir`
+    inst="%{pkgname}@`echo $basename | sed -e 's/slapd-//g'`"
+    echo found instance $inst - getting status  >> $output 2>&1 || :
     if /bin/systemctl -q is-active $inst ; then
        echo instance $inst is running >> $output 2>&1 || :
        instances="$instances $inst"
@@ -290,9 +296,9 @@ echo remove pid files . . . >> $output 2>&1 || :
 echo upgrading instances . . . >> $output 2>&1 || :
 DEBUGPOSTSETUPOPT=`/usr/bin/echo $DEBUGPOSTSETUP | /usr/bin/sed -e "s/[^d]//g"`
 if [ -n "$DEBUGPOSTSETUPOPT" ] ; then
-    %{_sbindir}/setup-ds.pl -l $output -$DEBUGPOSTSETUPOPT -u -s General.UpdateMode=offline >> $output 2>&1 || :
+    %{_sbindir}/setup-ds.pl -l $output2 -$DEBUGPOSTSETUPOPT -u -s General.UpdateMode=offline >> $output 2>&1 || :
 else
-    %{_sbindir}/setup-ds.pl -l $output -u -s General.UpdateMode=offline >> $output 2>&1 || :
+    %{_sbindir}/setup-ds.pl -l $output2 -u -s General.UpdateMode=offline >> $output 2>&1 || :
 fi
 
 # restart instances that require it
-- 
1.9.3