>From 3be10f2e37e8f2339031a8c710eb8e64e491e6b6 Mon Sep 17 00:00:00 2001 From: Nathan Kinder Date: Thu, 13 Aug 2009 16:27:49 -0700 Subject: [PATCH] Add centralized start/stop/restart scipts. This adds centralized start, stop, and restart scripts for ns-slapd. These scripts live in the sbin directory and will act upon all instances if an instance identifier is not specified (similar to the init script). The instance specific scripts have been modified to call the new centralized scripts. The instance specific parameters needed by the new scripts are located in the instance specific initconfig scripts, which are now created by setup-ds.pl with values mapped from the inf file. --- Makefile.am | 20 +++-- ldap/admin/src/initconfig.in | 9 +- ldap/admin/src/scripts/DSCreate.pm.in | 33 +++++++ ldap/admin/src/scripts/restart-dirsrv.in | 47 +++++++++ ldap/admin/src/scripts/start-dirsrv.in | 112 ++++++++++++++++++++++ ldap/admin/src/scripts/stop-dirsrv.in | 72 ++++++++++++++ ldap/admin/src/scripts/template-restart-slapd.in | 18 +--- ldap/admin/src/scripts/template-start-slapd.in | 75 +-------------- ldap/admin/src/scripts/template-stop-slapd.in | 36 +------- ldap/admin/src/template-initconfig.in | 18 ++++ 10 files changed, 305 insertions(+), 135 deletions(-) create mode 100644 ldap/admin/src/scripts/restart-dirsrv.in create mode 100755 ldap/admin/src/scripts/start-dirsrv.in create mode 100755 ldap/admin/src/scripts/stop-dirsrv.in create mode 100644 ldap/admin/src/template-initconfig.in diff --git a/Makefile.am b/Makefile.am index 6bfad08..ac7ab27 100644 --- a/Makefile.am +++ b/Makefile.am @@ -66,16 +66,18 @@ LIBCRUN=@LIBCRUN@ BUILT_SOURCES = dberrstrs.h CLEANFILES = dberrstrs.h ns-slapd.properties \ + ldap/admin/src/scripts/template-dbverify ldap/admin/src/template-initconfig \ ldap/admin/src/scripts/dscreate.map ldap/admin/src/scripts/remove-ds.pl \ ldap/admin/src/scripts/DSCreate.pm ldap/admin/src/scripts/DSMigration.pm \ ldap/admin/src/scripts/dsorgentries.map ldap/admin/src/scripts/migrate-ds.pl \ ldap/admin/src/scripts/Migration.pm ldap/admin/src/scripts/SetupDialogs.pm \ ldap/admin/src/scripts/setup-ds.pl ldap/admin/src/scripts/setup-ds.res \ - ldap/admin/src/scripts/Setup.pm ldap/admin/src/scripts/template-bak2db \ - ldap/admin/src/scripts/template-bak2db.pl ldap/admin/src/scripts/template-db2bak \ - ldap/admin/src/scripts/template-db2bak.pl ldap/admin/src/scripts/template-db2index \ - ldap/admin/src/scripts/template-db2index.pl ldap/admin/src/scripts/template-db2ldif \ - ldap/admin/src/scripts/template-db2ldif.pl ldap/admin/src/scripts/template-dbverify \ + ldap/admin/src/scripts/start-dirsrv ldap/admin/src/scripts/stop-dirsrv \ + ldap/admin/src/scripts/restart-dirsrv ldap/admin/src/scripts/Setup.pm \ + ldap/admin/src/scripts/template-bak2db ldap/admin/src/scripts/template-bak2db.pl \ + ldap/admin/src/scripts/template-db2bak ldap/admin/src/scripts/template-db2bak.pl \ + ldap/admin/src/scripts/template-db2index ldap/admin/src/scripts/template-db2index.pl \ + ldap/admin/src/scripts/template-db2ldif ldap/admin/src/scripts/template-db2ldif.pl \ ldap/admin/src/scripts/template-ldif2db ldap/admin/src/scripts/template-ldif2db.pl \ ldap/admin/src/scripts/template-ldif2ldap ldap/admin/src/scripts/template-monitor \ ldap/admin/src/scripts/template-ns-accountstatus.pl ldap/admin/src/scripts/template-ns-activate.pl \ @@ -169,7 +171,8 @@ noinst_LIBRARIES = libavl.a libldaputil.a # Installed Files #------------------------ config_DATA = $(srcdir)/lib/ldaputil/certmap.conf \ - $(srcdir)/ldap/schema/slapd-collations.conf + $(srcdir)/ldap/schema/slapd-collations.conf \ + ldap/admin/src/template-initconfig # the schema files in this list are either not # standard schema, not tested, or not compatible @@ -247,7 +250,10 @@ schema_DATA = $(srcdir)/ldap/schema/00core.ldif \ sbin_SCRIPTS = ldap/admin/src/scripts/setup-ds.pl \ ldap/admin/src/scripts/migrate-ds.pl \ - ldap/admin/src/scripts/remove-ds.pl + ldap/admin/src/scripts/remove-ds.pl \ + ldap/admin/src/scripts/start-dirsrv \ + ldap/admin/src/scripts/stop-dirsrv \ + ldap/admin/src/scripts/restart-dirsrv bin_SCRIPTS = ldap/servers/slapd/tools/rsearch/scripts/dbgen.pl \ wrappers/dbscan \ diff --git a/ldap/admin/src/initconfig.in b/ldap/admin/src/initconfig.in index 2bcc628..7f9dd8f 100644 --- a/ldap/admin/src/initconfig.in +++ b/ldap/admin/src/initconfig.in @@ -1,10 +1,9 @@ # This file is sourced by @package_name@ upon startup to set # the default environment for all directory server instances. -# To set instance specific defaults, make a copy of this -# file in the same directory called @package_name@-instance -# where "instance" is the name of your directory server -# instance e.g. @package_name@-localhost for the -# slapd-localhost instance +# To set instance specific defaults, use the file in the same +# directory called @package_name@-instance where "instance" +# is the name of your directory server instance e.g. +# @package_name@-localhost for the slapd-localhost instance. # In order to make more file descriptors available # to the directory server, first make sure the system diff --git a/ldap/admin/src/scripts/DSCreate.pm.in b/ldap/admin/src/scripts/DSCreate.pm.in index 66183e8..d33f13a 100644 --- a/ldap/admin/src/scripts/DSCreate.pm.in +++ b/ldap/admin/src/scripts/DSCreate.pm.in @@ -421,6 +421,16 @@ sub createConfigFile { sub makeOtherConfigFiles { my $inf = shift; my @errs; + my %maptable = ( + "DS-ROOT" => $inf->{General}->{prefix}, + "SERVER-DIR" => $inf->{General}->{ServerRoot}, + "CONFIG-DIR" => $inf->{slapd}->{config_dir}, + "INST-DIR" => $inf->{slapd}->{inst_dir}, + "RUN-DIR" => $inf->{slapd}->{run_dir}, + "PRODUCT-NAME" => "slapd", + "SERVERBIN-DIR" => $inf->{slapd}->{sbindir}, + ); + # install certmap.conf at my $src = "$inf->{General}->{prefix}@configdir@/certmap.conf"; my $dest = "$inf->{slapd}->{config_dir}/certmap.conf"; @@ -444,6 +454,29 @@ sub makeOtherConfigFiles { return @errs; } + # install instance specific initconfig script + $src = "$inf->{General}->{prefix}@configdir@/template-initconfig"; + $dest = "$inf->{General}->{prefix}@initconfigdir@/@package_name@-$inf->{slapd}->{ServerIdentifier}"; + $! = 0; # clear errno + + if (!open(SRC, "< $src")) { + return ("error_opening_scripttmpl", $src, $!); + } + if (!open(DEST, "> $dest")) { + return ("error_opening_scripttmpl", $dest, $!); + } + my $contents; # slurp entire file into memory + read SRC, $contents, int(-s $src); + close(SRC); + while (my ($key, $val) = each %maptable) { + $contents =~ s/\{\{$key\}\}/$val/g; + } + print DEST $contents; + close(DEST); + if (@errs = changeOwnerMode($inf, 4, $dest)) { + return @errs; + } + return (); } diff --git a/ldap/admin/src/scripts/restart-dirsrv.in b/ldap/admin/src/scripts/restart-dirsrv.in new file mode 100644 index 0000000..e3dc93c --- /dev/null +++ b/ldap/admin/src/scripts/restart-dirsrv.in @@ -0,0 +1,47 @@ +#!/bin/sh + +# Script that restarts the ns-slapd server. +# Exit status can be: +# 0: Server restarted successfully +# 1: Server could not be started +# 2: Server started successfully (was not running) +# 3: Server could not be stopped + +restart_instance() { + SERV_ID=$1 + + server_already_stopped=0 + @sbindir@/stop-dirsrv $SERV_ID + status=$? + if [ $status -eq 1 ] ; then + return 3; + else + if [ $status -eq 2 ] ; then + server_already_stopped=1 + fi + fi + @sbindir@/start-dirsrv $SERV_ID + status=$? + if [ $server_already_stopped -eq 1 ] && [ $status -eq 0 ] ; then + return 2; + fi + return $status +} + +if [ "$#" -eq 0 ]; then + # We're restarting all instances. + ret=0 + for i in /opt/dirsrv/etc/sysconfig/dirsrv-*; do + inst=`echo $i | sed -e 's,/opt/dirsrv/etc/sysconfig/dirsrv-,,g'` + echo Restarting instance \"$inst\" + restart_instance $inst + if [ "$?" -ne 0 ]; then + ret=$? + fi + done + exit $ret +else + # We're restarting a single instance. + restart_instance $* + exit $? +fi diff --git a/ldap/admin/src/scripts/start-dirsrv.in b/ldap/admin/src/scripts/start-dirsrv.in new file mode 100755 index 0000000..fb9bfdb --- /dev/null +++ b/ldap/admin/src/scripts/start-dirsrv.in @@ -0,0 +1,112 @@ +#!/bin/sh + +# Script that starts the ns-slapd server. +# Exit status can be: +# 0: Server started successfully +# 1: Server could not be started +# 2: Server already running + +# Starts a single instance +start_instance() { + # The first argument is the server ID. Anything + # after that is an argument to ns-slapd. + SERV_ID=$1 + shift + + # source env. for this instance + if [ -f @initconfigdir@/@package_name@-$SERV_ID ] ; then + . @initconfigdir@/@package_name@-$SERV_ID + else + echo Instance $SERV_ID not found. + return 1 + fi + + prefix="$DS_ROOT" + LD_LIBRARY_PATH=$prefix$SERVER_DIR:$prefix@nss_libdir@:$prefix@libdir@:@nss_libdir@ + export LD_LIBRARY_PATH + SHLIB_PATH=$prefix$SERVER_DIR:$prefix@nss_libdir@:$prefix@libdir@:@nss_libdir@ + export SHLIB_PATH + + DS_CONFIG_DIR=$CONFIG_DIR + export DS_CONFIG_DIR + PIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.pid + STARTPIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.startpid + if test -f $STARTPIDFILE ; then + PID=`cat $STARTPIDFILE` + if kill -0 $PID > /dev/null 2>&1 ; then + echo There is an ns-slapd process already running: $PID + return 2; + else + rm -f $STARTPIDFILE + fi + fi + if test -f $PIDFILE ; then + PID=`cat $PIDFILE` + if kill -0 $PID > /dev/null 2>&1 ; then + echo There is an ns-slapd running: $PID + return 2; + else + rm -f $PIDFILE + fi + fi + cd $SERVERBIN_DIR; ./ns-slapd -D $CONFIG_DIR -i $PIDFILE -w $STARTPIDFILE "$@" + if [ $? -ne 0 ]; then + return 1 + fi + + loop_counter=1 + # wait for 10 seconds for the start pid file to appear + max_count=${STARTPID_TIME:-10} + while test $loop_counter -le $max_count; do + loop_counter=`expr $loop_counter + 1` + if test ! -f $STARTPIDFILE ; then + sleep 1; + else + PID=`cat $STARTPIDFILE` + fi + done + if test ! -f $STARTPIDFILE ; then + echo Server failed to start !!! Please check errors log for problems + return 1 + fi + loop_counter=1 + # wait for 10 minutes (600 times 1 seconds) + max_count=${PID_TIME:-600} + while test $loop_counter -le $max_count; do + loop_counter=`expr $loop_counter + 1` + if test ! -f $PIDFILE ; then + if kill -0 $PID > /dev/null 2>&1 ; then + sleep 1 + else + echo Server failed to start !!! Please check errors log for problems + return 1 + fi + else + PID=`cat $PIDFILE` + return 0; + fi + done + echo Server not running!! Failed to start ns-slapd process. Please check the errors log for problems. + return 1 +} + +# source env. for all instances +[ -f @initconfigdir@/@package_name@ ] && . @initconfigdir@/@package_name@ + +if [ "$#" -eq 0 ]; then + # We're starting all instances. + ret=0 + for i in @initconfigdir@/@package_name@-*; do + inst=`echo $i | sed -e 's,@initconfigdir@/@package_name@-,,g'` + echo Starting instance \"$inst\" + start_instance $inst + if [ "$?" -ne 0 ]; then + ret=$? + fi + done + exit $ret +else + # We're starting a single instance. + start_instance $* + exit $? +fi diff --git a/ldap/admin/src/scripts/stop-dirsrv.in b/ldap/admin/src/scripts/stop-dirsrv.in new file mode 100755 index 0000000..5e8745d --- /dev/null +++ b/ldap/admin/src/scripts/stop-dirsrv.in @@ -0,0 +1,72 @@ +#!/bin/sh + +# Script that stops the ns-slapd server. +# Exit status can be: +# 0: Server stopped successfully +# 1: Server could not be stopped +# 2: Server was not running + +stop_instance() { + SERV_ID=$1 + + # source env. for this instance + if [ -f @initconfigdir@/@package_name@-$SERV_ID ]; then + . @initconfigdir@/@package_name@-$SERV_ID + else + echo Instance $SERV_ID not found. + return 1 + fi + + PIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.pid + if test ! -f $PIDFILE ; then + echo No ns-slapd PID file found. Server is probably not running + return 2 + fi + PID=`cat $PIDFILE` + # see if the server is already stopped + kill -0 $PID > /dev/null 2>&1 || { + echo Server not running + if test -f $PIDFILE ; then + rm -f $PIDFILE + fi + return 2 + } + # server is running - kill it + kill $PID + loop_counter=1 + # wait for 10 minutes (600 times 1 second) + max_count=600 + while test $loop_counter -le $max_count; do + loop_counter=`expr $loop_counter + 1` + if kill -0 $PID > /dev/null 2>&1 ; then + sleep 1; + else + if test -f $PIDFILE ; then + rm -f $PIDFILE + fi + return 0 + fi + done + if test -f $PIDFILE ; then + echo Server still running!! Failed to stop the ns-slapd process: $PID. Please check the errors log for problems. + fi + return 1 +} + +if [ "$#" -eq 0 ]; then + # We're stopping all instances. + ret=0 + for i in /opt/dirsrv/etc/sysconfig/dirsrv-*; do + inst=`echo $i | sed -e 's,/opt/dirsrv/etc/sysconfig/dirsrv-,,g'` + echo Stopping instance \"$inst\" + stop_instance $inst + if [ "$?" -ne 0 ]; then + ret=$? + fi + done + exit $ret +else + # We're stopping a single instance. + stop_instance $* + exit $? +fi diff --git a/ldap/admin/src/scripts/template-restart-slapd.in b/ldap/admin/src/scripts/template-restart-slapd.in index 6f5c0c8..19e2414 100644 --- a/ldap/admin/src/scripts/template-restart-slapd.in +++ b/ldap/admin/src/scripts/template-restart-slapd.in @@ -7,19 +7,5 @@ # 2: Server started successfully (was not running) # 3: Server could not be stopped -server_already_stopped=0 -{{INST-DIR}}/stop-slapd -status=$? -if [ $status -eq 1 ] ; then - exit 3; -else - if [ $status -eq 2 ] ; then - server_already_stopped=1 - fi -fi -{{INST-DIR}}/start-slapd -status=$? -if [ $server_already_stopped -eq 1 ] && [ $status -eq 0 ] ; then - exit 2; -fi -exit $status +@sbindir@/restart-dirsrv {{SERV-ID}} "$@" +exit $? diff --git a/ldap/admin/src/scripts/template-start-slapd.in b/ldap/admin/src/scripts/template-start-slapd.in index 223d6ed..7608d37 100755 --- a/ldap/admin/src/scripts/template-start-slapd.in +++ b/ldap/admin/src/scripts/template-start-slapd.in @@ -1,81 +1,10 @@ #!/bin/sh -prefix="{{DS-ROOT}}" -LD_LIBRARY_PATH=$prefix{{SERVER-DIR}}:$prefix@nss_libdir@:$prefix@libdir@:@nss_libdir@ -export LD_LIBRARY_PATH -SHLIB_PATH=$prefix{{SERVER-DIR}}:$prefix@nss_libdir@:$prefix@libdir@:@nss_libdir@ -export SHLIB_PATH - -# source env. for all instances -[ -f @initconfigdir@/@package_name@ ] && . @initconfigdir@/@package_name@ - -# source env. for this instance -[ -f @initconfigdir@/@package_name@-{{SERV-ID}} ] && . @initconfigdir@/@package_name@-{{SERV-ID}} - # Script that starts the ns-slapd server. # Exit status can be: # 0: Server started successfully # 1: Server could not be started # 2: Server already running -DS_CONFIG_DIR={{CONFIG-DIR}} -export DS_CONFIG_DIR -PIDFILE={{RUN-DIR}}/{{PRODUCT-NAME}}-{{SERV-ID}}.pid -STARTPIDFILE={{RUN-DIR}}/{{PRODUCT-NAME}}-{{SERV-ID}}.startpid -if test -f $STARTPIDFILE ; then - PID=`cat $STARTPIDFILE` - if kill -0 $PID > /dev/null 2>&1 ; then - echo There is an ns-slapd process already running: $PID - exit 2; - else - rm -f $STARTPIDFILE - fi -fi -if test -f $PIDFILE ; then - PID=`cat $PIDFILE` - if kill -0 $PID > /dev/null 2>&1 ; then - echo There is an ns-slapd running: $PID - exit 2; - else - rm -f $PIDFILE - fi -fi -cd {{SERVERBIN-DIR}}; ./ns-slapd -D {{CONFIG-DIR}} -i $PIDFILE -w $STARTPIDFILE "$@" -if [ $? -ne 0 ]; then - exit 1 -fi - -loop_counter=1 -# wait for 10 seconds for the start pid file to appear -max_count=${STARTPID_TIME:-10} -while test $loop_counter -le $max_count; do - loop_counter=`expr $loop_counter + 1` - if test ! -f $STARTPIDFILE ; then - sleep 1; - else - PID=`cat $STARTPIDFILE` - fi -done -if test ! -f $STARTPIDFILE ; then - echo Server failed to start !!! Please check errors log for problems - exit 1 -fi -loop_counter=1 -# wait for 10 minutes (600 times 1 seconds) -max_count=${PID_TIME:-600} -while test $loop_counter -le $max_count; do - loop_counter=`expr $loop_counter + 1` - if test ! -f $PIDFILE ; then - if kill -0 $PID > /dev/null 2>&1 ; then - sleep 1 - else - echo Server failed to start !!! Please check errors log for problems - exit 1 - fi - else - PID=`cat $PIDFILE` - exit 0; - fi -done -echo Server not running!! Failed to start ns-slapd process. Please check the errors log for problems. -exit 1 +@sbindir@/start-dirsrv {{SERV-ID}} "$@" +exit $? diff --git a/ldap/admin/src/scripts/template-stop-slapd.in b/ldap/admin/src/scripts/template-stop-slapd.in index cc9f968..3531464 100755 --- a/ldap/admin/src/scripts/template-stop-slapd.in +++ b/ldap/admin/src/scripts/template-stop-slapd.in @@ -6,37 +6,5 @@ # 1: Server could not be stopped # 2: Server was not running -PIDFILE={{RUN-DIR}}/{{PRODUCT-NAME}}-{{SERV-ID}}.pid -if test ! -f $PIDFILE ; then - echo No ns-slapd PID file found. Server is probably not running - exit 2 -fi -PID=`cat $PIDFILE` -# see if the server is already stopped -kill -0 $PID > /dev/null 2>&1 || { - echo Server not running - if test -f $PIDFILE ; then - rm -f $PIDFILE - fi - exit 2 -} -# server is running - kill it -kill $PID -loop_counter=1 -# wait for 10 minutes (600 times 1 second) -max_count=600 -while test $loop_counter -le $max_count; do - loop_counter=`expr $loop_counter + 1` - if kill -0 $PID > /dev/null 2>&1 ; then - sleep 1; - else - if test -f $PIDFILE ; then - rm -f $PIDFILE - fi - exit 0 - fi -done -if test -f $PIDFILE ; then - echo Server still running!! Failed to stop the ns-slapd process: $PID. Please check the errors log for problems. -fi -exit 1 +@sbindir@/stop-dirsrv {{SERV-ID}} "$@" +exit $? diff --git a/ldap/admin/src/template-initconfig.in b/ldap/admin/src/template-initconfig.in new file mode 100644 index 0000000..4945885 --- /dev/null +++ b/ldap/admin/src/template-initconfig.in @@ -0,0 +1,18 @@ +# This file is sourced by @package_name@ upon startup to set +# the default environment for a single specific directory +# server instances. To set defaults for all instances, edit +# the file in the same directory called @package_name@. + +# These settings are used by the start-dirsrv and +# start-slapd scripts (as well as their associates stop +# and restart scripts). Do not edit them unless you know +# what you are doing. +SERVER_DIR={{SERVER-DIR}} ; export SERVER_DIR +SERVERBIN_DIR={{SERVERBIN-DIR}} ; export SERVERBIN_DIR +CONFIG_DIR={{CONFIG-DIR}} ; export CONFIG_DIR +INST_DIR={{INST-DIR}} ; export INST_DIR +RUN_DIR={{RUN-DIR}} ; export RUN_DIR +DS_ROOT={{DS-ROOT}} ; export DS_ROOT +PRODUCT_NAME={{PRODUCT-NAME}} ; export PRODUCT_NAME + +# Put custom instance specific settings below here. -- 1.6.2.5