From a673c5bc37d0be8f4bd959253f7555a7423d784b Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Wed, 20 Jan 2016 21:57:20 -0800 Subject: [PATCH 1/2] Ticket #48144 - Add /usr/sbin/status-dirsrv script to get the status of the directory server instance. Description: Adding a script status-dirsrv to show the status of the Directory Server as well as its man page. --- Makefile.am | 3 ++ ldap/admin/src/scripts/status-dirsrv.in | 87 +++++++++++++++++++++++++++++++++ man/man8/status-dirsrv.8 | 55 +++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100755 ldap/admin/src/scripts/status-dirsrv.in create mode 100644 man/man8/status-dirsrv.8 diff --git a/Makefile.am b/Makefile.am index d90fb27..9b19bd4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -110,6 +110,7 @@ CLEANFILES = dberrstrs.h ns-slapd.properties \ ldap/admin/src/scripts/setup-ds.pl ldap/admin/src/scripts/setup-ds.res \ 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/status-dirsrv \ 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 \ @@ -577,6 +578,7 @@ sbin_SCRIPTS = ldap/admin/src/scripts/setup-ds.pl \ ldap/admin/src/scripts/start-dirsrv \ ldap/admin/src/scripts/stop-dirsrv \ ldap/admin/src/scripts/restart-dirsrv \ + ldap/admin/src/scripts/status-dirsrv \ ldap/admin/src/scripts/bak2db \ ldap/admin/src/scripts/db2bak \ ldap/admin/src/scripts/db2index \ @@ -744,6 +746,7 @@ dist_man_MANS = man/man1/dbscan.1 \ man/man8/setup-ds.pl.8 \ man/man8/start-dirsrv.8 \ man/man8/stop-dirsrv.8 \ + man/man8/status-dirsrv.8 \ man/man8/bak2db.8 man/man8/bak2db.pl.8 \ man/man8/db2bak.8 man/man8/db2bak.pl.8 \ man/man8/db2ldif.8 man/man8/db2ldif.pl.8 \ diff --git a/ldap/admin/src/scripts/status-dirsrv.in b/ldap/admin/src/scripts/status-dirsrv.in new file mode 100755 index 0000000..02fcc0d --- /dev/null +++ b/ldap/admin/src/scripts/status-dirsrv.in @@ -0,0 +1,87 @@ +#!/bin/sh + +# Script that reports the status of the ns-slapd server. + +. @datadir@/@package_name@/data/DSSharedLib + +# Get the status of a single instance +status_instance() { + # The first argument is the server ID. Anything + # after that is an argument to ns-slapd. + SERV_ID=$1 + shift + + initfile=`get_init_file $initconfig_dir $SERV_ID` || { echo Instance $SERV_ID not found. ; return -1 ; } + + # source env. for this instance + if [ -f $initfile ] ; then + . $initfile + else + echo Instance $SERV_ID not found. + return -1 + fi + + prefix="$DS_ROOT" + + libpath_add "$prefix$SERVER_DIR" + libpath_add "$prefix@nss_libdir@" + libpath_add "$prefix@libdir@" + libpath_add "@nss_libdir@" + libpath_add "$prefix@pcre_libdir@" + + export LD_LIBRARY_PATH + SHLIB_PATH=$LD_LIBRARY_PATH + export SHLIB_PATH + + # + # Use systemctl if available. + # + if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then + @bindir@/systemctl status @package_name@@$SERV_ID.service + rv=$? + if [ $rv -ne 0 ]; then + return $rv + fi + fi + return 0 +} + +# source env. for all instances +[ -f @initconfigdir@/@package_name@ ] && . @initconfigdir@/@package_name@ + +while getopts "d:" flag +do + case "$flag" in + d) initconfig_dir="$OPTARG";; + esac +done +shift $(($OPTIND-1)) + +if [ -z "$initconfig_dir" ]; then + initconfig_dir=@initconfigdir@ +fi + +found=0 +if [ $# -eq 0 ]; then + # We're reporting the status of all instances. + ret=-1 + @bindir@/systemctl status @package_name@.target + initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; } + for i in $initfiles; do + inst=`normalize_server_id $i` + echo Status of instance \"$inst\" + status_instance $inst + rv=$? + #if one of them is successful, return 0. + if [ $ret -gt -1 ]; then + ret=`expr $ret \& $rv` + else + ret=$rv + fi + done + exit $ret +else + # We're getting the status of a single instance. + status_instance $@ + exit $? +fi diff --git a/man/man8/status-dirsrv.8 b/man/man8/status-dirsrv.8 new file mode 100644 index 0000000..0198670 --- /dev/null +++ b/man/man8/status-dirsrv.8 @@ -0,0 +1,55 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH STATUS-DIRSRV 8 "Jan 20, 2016" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +status-dirsrv \- script for showing the status of Directory Server +.SH SYNOPSIS +.B status-dirsrv +.RI [\fI\fR] +.SH DESCRIPTION +status-dirsrv shows all the status of Directory Server instances on a system, or +of a single instance if specified +.PP +.\" TeX users may be more comfortable with the \fB\fP and +.\" \fI\fP escape sequences to invode bold face and italics, +.\" respectively. +.SH OPTIONS +.TP +.B +Specifies a single Directory Server instance to show the status +.br +.SH USAGE +Sample usage: +.TP +.B status-dirsrv example +.br +.SH EXIST STATUS +status-dirsrv returns 0 if all Directory Server instances are running. Otherwise, a non-zero failure code returned from systemctl is returned. + +If a single Directory Server instance is specified, 0 is returned if the instance is running; a non-zero failure code returned from systemctl is returned if the instance is not running; 255 is returned if the instance does not exist. +.br +.SH AUTHOR +status\-dirsrv was written by the 389 Project. +.SH "REPORTING BUGS" +Report bugs to https://fedorahosted.org/389/newticket. +.SH COPYRIGHT +Copyright \(co 2016 Red Hat, Inc. +.br +This is free software. You may redistribute copies of it under the terms of +the Directory Server license found in the LICENSE file of this +software distribution. This license is essentially the GNU General Public +License version 2 with an exception for plug-in distribution. -- 2.4.3