[Fedora-directory-commits] adminserver/admserv/newinst/src remove-ds-admin.pl.in, NONE, 1.1 AdminServer.pm.in, 1.15, 1.16 AdminUtil.pm.in, 1.20, 1.21 setup-ds-admin.pl.in, 1.13, 1.14 setup-ds-admin.res.in, 1.10, 1.11

Richard Allen Megginson rmeggins at fedoraproject.org
Fri Feb 27 14:33:29 UTC 2009


Author: rmeggins

Update of /cvs/dirsec/adminserver/admserv/newinst/src
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv21602/adminserver/admserv/newinst/src

Modified Files:
	AdminServer.pm.in AdminUtil.pm.in setup-ds-admin.pl.in 
	setup-ds-admin.res.in 
Added Files:
	remove-ds-admin.pl.in 
Log Message:
Resolves: bug 480869
Bug Description: DS console: Can not delete DS instance
Reviewed by: nkinder (Thanks!)
Fix Description: As it turns out, my assumption that ds_remove in CGI mode also did the unregistration was false.  It is the console that does the unregistration, only after the ds_remove CGI returns success.  So, ds_remove needs to run with AdminSDK off, just like the other "special" CGI programs.  In addition, ds_remove needs to be more robust - if there is an error during ds_remove, you should be allowed to try again after fixing something.  However, the way the error handling worked did not differentiate between fatal errors and errors that could be ignored.  In order to do this properly, we need to propagate the errors back up to the top level (oh how I wish perl had real exception handling . . .).  The main type of error we need to ignore is file not found or process not found.  If we attempted to remove before and that attempt failed for some reason, and left a partial instance, we need to be able to run the remove command again, skipping over the things we shutdown or
  removed already, and clean up the stuff we need to remove.  This can also happen if you use the console to create a ds instance, and remove-ds.pl to remove the instance.  The instance will still show up in the console.  We need to be able to use the Remove Server in the console to remove the instance from the console, even through there is no physical instance on disk any more.  Since the console will only do the unregistration if the CGI returns success, we need to make sure the CGI returns success even though there is no instance on disk.  When ds_remove is run via ds_removal, it will do the unregistration.
I also took this opportunity to refactor the remove code, creating a removeDSInstance method in DSCreate.pm, and moving some of the other removal helper functions to Util.pm.  That simplified the code in both ds_remove and remove-ds.pl.
I added a remove-ds-admin.pl script - one of the problems that users have is that they run setup-ds-admin.pl, then hit some error (e.g. bad DNS setup), then find that they cannot restore the system to the state before they ran setup-ds-admin.pl.  remove-ds-admin.pl does this.
Finally, I added some man pages to the admin package for those commonly used commands.
Platforms tested: RHEL4
Flag Day: no
Doc impact: no 



--- NEW FILE remove-ds-admin.pl.in ---
#!@perlexec@
# BEGIN COPYRIGHT BLOCK
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
# 
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# 
# Copyright (C) 2007 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK
#

use lib qw(@perlpath@);

use strict;

use File::Basename;
use File::Path;
use Util;
use Resource;
use DSCreate qw(removeDSInstance);
use AdminServer qw(removeAdminServer);

sub usage {
        print(STDERR "Usage: $0 [-f] [-d -d ...]\n\n");
        print(STDERR " Opts: -f            - force removal\n");
        print(STDERR "       -d            - turn on debugging output\n");
        print(STDERR "       -y            - actually do the removal\n");
        print(STDERR "WARNING: This command is extremely destructive!\n");
        print(STDERR "         It will remove all of the data and configuration\n");
        print(STDERR "         of all directory servers and admin servers, with\n");
        print(STDERR "         no chance of recovery.  Therefore, in order to actually\n");
        print(STDERR "         do this, you must give the -y option.\n");
}

my $res = new Resource("@propertydir@/setup-ds.res",
                       "@propertydir@/setup-ds-admin.res");

my $i = 0;
my $force = "";

# load args from the command line
while ($i <= $#ARGV) {
    if ( "$ARGV[$i]" eq "-f" ) { 
        $force = 1;
    } elsif ("$ARGV[$i]" eq "-d") {
        $Util::debuglevel++;
    } else {
        &usage; exit(1);
    }
    $i++;
}

my $baseconfigdir = $ENV{DS_CONFIG_DIR} || "@instconfigdir@";
my @instances = ();
my @errs;

if ( ! -d $baseconfigdir )
{
    print STDERR "Error: $baseconfigdir does not exist\n";
    exit 1;
}

# get all of our directory server instances
for my $dir (glob("$baseconfigdir/slapd-*")) {
    next if ($dir =~ /\.removed/);
    if (-d $dir) {
        $dir =~ s,$baseconfigdir/,,; # strip off dir part
        $dir =~ s/slapd-//; # strip off slapd part
        push @instances, $dir;
    }
}

# remove all of the directory servers
for my $inst (@instances) {
    my $configdir = "$baseconfigdir/slapd-$inst";
    if ( ! -d $configdir )
    {
        print STDERR "Error: $configdir does not exist\n";
        if (!$force) {
            exit 1;
        }
    }
    @errs = removeDSInstance($inst, $force);
    if (@errs) {
        print STDERR "The following errors occurred during removal of $inst:\n";
        for (@errs) {
            print STDERR $res->getText($_);
        }
        print STDERR "Error: could not remove directory server $inst\n";
        if (!$force) {
            exit 1;
        }
    }
}

# remove the admin server
if (@errs = removeAdminServer($baseconfigdir, $force)) {
    print STDERR "The following errors occurred during removal of the admin server:\n";
    for (@errs) {
        print STDERR $res->getText($_);
    }
    print STDERR "Error: could not remove admin server\n";
    if (!$force) {
        exit 1;
    }
}

# if we got here, report success
print "Removed admin server and all directory server instances\n";
exit 0;

# emacs settings
# Local Variables:
# mode:perl
# indent-tabs-mode: nil
# tab-width: 4
# End:


Index: AdminServer.pm.in
===================================================================
RCS file: /cvs/dirsec/adminserver/admserv/newinst/src/AdminServer.pm.in,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- AdminServer.pm.in	28 Jan 2009 21:25:58 -0000	1.15
+++ AdminServer.pm.in	27 Feb 2009 14:33:27 -0000	1.16
@@ -21,10 +21,10 @@
 @ISA       = qw(Exporter);
 @EXPORT    = qw(createAdminServer reconfigAdminServer
                 createASFilesAndDirs setFileOwnerPerms updateHttpConfFiles
-                startAdminServer);
+                startAdminServer removeAdminServer);
 @EXPORT_OK = qw(createAdminServer reconfigAdminServer
                 createASFilesAndDirs setFileOwnerPerms updateHttpConfFiles
-                startAdminServer);
+                startAdminServer removeAdminServer);
 
 use File::Path;
 # tempfiles
@@ -502,6 +502,91 @@
     return createAdminServer($setup, 1);
 }
 
+sub stopAdminServer {
+    my $prog = "@sbindir@/stop-ds-admin";
+    if (-x $prog) {
+        $? = 0;
+        # run the stop command
+        my $output = `$prog 2>&1`;
+        my $status = $?;
+        debug(3, "stopping admin server returns status $status: output $output\n");
+        if ($status) {
+            # Ignore the stop failure
+            debug(1,"Warning: Could not stop admin server: status $status: output $output\n");
+            return 1;
+        }
+    } else {
+        debug(1, "stopping admin server: no such program $prog: cannot stop server\n");
+        return;
+    }
+
+    debug(1, "Successfully stopped admin server\n");
+    return 1;
+}
+
+sub removeAdminServer {
+    my $baseconfigdir = shift;
+    my $force = shift;
+    if (!stopAdminServer()) {
+        if ($force) {
+            debug(1, "Warning: Could not stop admin server - forcing continue\n");
+        } else {
+            debug(1, "Error: Could not stop admin server - aborting - use -f flag to force removal\n");
+            return ( [ 'error_stopping_adminserver', $! ] );
+        }
+    }
+
+    my $configdir = $ENV{ADMSERV_CONF_DIR} || $baseconfigdir . "/admin-serv";
+
+    my $securitydir = $configdir;
+
+    my $logdir = $ENV{ADMSERV_LOG_DIR} || "@logdir@";
+
+    my $rundir = $ENV{ADMSERV_PID_DIR} || "@piddir@";
+
+    # remove admin server files in $rundir
+    my $file;
+    for $file (glob("$rundir/admin-serv.*")) {
+        unlink($file);
+    }
+
+    # remove admin server log dir
+    if ($logdir =~ /admin-serv/) { # make sure directory has admin-serv in it somewhere
+        if (!rmtree($logdir)) {
+            debug(1, "Warning: Could not remove directory $logdir: $!\n");
+            if (!$force) {
+                return ( [ 'error_removing_path', $logdir, $! ] );
+            }
+        }
+    }
+
+    # remove config files
+    my @savefiles = qw(admserv.conf httpd.conf nss.conf console.conf cert8.db key3.db secmod.db);
+    if (opendir(CONFDIR, $configdir)) {
+        while ($file = readdir(CONFDIR)) {
+            next if ($file eq '.' || $file eq '..');
+            if (-d "$configdir/$file") {
+                debug(1, "Skipping directory $configdir/$file - remove manually\n");
+                next;
+            }
+            if (grep /^$file$/, @savefiles) {
+                debug(1, "saving file $configdir/$file\n");
+            } else {
+                debug(1, "removing file $configdir/$file\n");
+                unlink("$configdir/$file");
+            }
+        }
+        closedir(CONFDIR);
+    } else {
+        debug(1, "Error: could not read config files in $configdir: $!");
+        if (!$force) {
+            return ( [ 'error_removing_path', $configdir, $! ] );
+        }
+    }
+
+    return;
+}
+
 1;
 
 # emacs settings


Index: AdminUtil.pm.in
===================================================================
RCS file: /cvs/dirsec/adminserver/admserv/newinst/src/AdminUtil.pm.in,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- AdminUtil.pm.in	24 Feb 2009 14:25:42 -0000	1.20
+++ AdminUtil.pm.in	27 Feb 2009 14:33:27 -0000	1.21
@@ -816,7 +816,7 @@
 
     my $instinf;
     # setup will usually supply everything, but ds_create will not
-    if (!$inf->{slapd}->{RootDNPwd}) {
+    if ($isRegister && !$inf->{slapd}->{RootDNPwd}) {
         $instinf = createInfFromConfig("$configdir/$inst", $inst, $errs);
         if (!$instinf or @{$errs}) {
             if ($needclose) {


Index: setup-ds-admin.pl.in
===================================================================
RCS file: /cvs/dirsec/adminserver/admserv/newinst/src/setup-ds-admin.pl.in,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- setup-ds-admin.pl.in	17 Dec 2008 17:26:11 -0000	1.13
+++ setup-ds-admin.pl.in	27 Feb 2009 14:33:27 -0000	1.14
@@ -263,3 +263,10 @@
         }
     }
 }
+
+# emacs settings
+# Local Variables:
+# mode:perl
+# indent-tabs-mode: nil
+# tab-width: 4
+# End:


Index: setup-ds-admin.res.in
===================================================================
RCS file: /cvs/dirsec/adminserver/admserv/newinst/src/setup-ds-admin.res.in,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- setup-ds-admin.res.in	14 Jul 2008 18:43:02 -0000	1.10
+++ setup-ds-admin.res.in	27 Feb 2009 14:33:27 -0000	1.11
@@ -106,6 +106,7 @@
 error_creating_adminserver_maptbl = Could not create the map table for registering the Admin Server with the configuration directory server.\n
 error_updating_localconf = Could not update the local admin server configuration file '%s'.  Error: %s\n
 error_starting_adminserver = Could not start the admin server.  Error: %s\n
+error_stopping_adminserver = Could not stop the admin server.  Error: %s\n
 registering_adminserver = Registering admin server with the configuration directory server . . .\n
 error_adding_adminserver_config_entry = Could not add the admin server configuration entry '%s'.\nCheck the configuration directory server access and error log for more details.\n
 error_updating_localconf_entry = Could not update the local admin server configuration file for the configuration entry '%s'.\n




More information about the Fedora-directory-commits mailing list