From ba00d4885b93f8cc8d6eb1460bd0b5019e4d2fc2 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Sep 04 2013 18:24:38 +0000 Subject: Ticket 47500 - start-dirsrv/restart-dirsrv/stop-disrv do not register with systemd correctly Description: If "systemctl" is available on the system, and the user is root, then use systemctl to start & stop the server. https://fedorahosted.org/389/ticket/47500 Reviewed by: richm(Thanks!) --- diff --git a/ldap/admin/src/scripts/start-dirsrv.in b/ldap/admin/src/scripts/start-dirsrv.in index a163cef..481797d 100755 --- a/ldap/admin/src/scripts/start-dirsrv.in +++ b/ldap/admin/src/scripts/start-dirsrv.in @@ -60,11 +60,21 @@ start_instance() { rm -f $PIDFILE fi fi - cd $SERVERBIN_DIR; ./ns-slapd -D $CONFIG_DIR -i $PIDFILE -w $STARTPIDFILE "$@" - if [ $? -ne 0 ]; then - return 1 + # + # Use systemctl if available and running as root, + # otherwise start the instance the old way. + # + if [ -d "@systemdsystemunitdir@" ] && [ "$(id -u)" == "0" ];then + @bindir@/systemctl start @package_name@@$SERV_ID.service + if [ $? -ne 0 ]; then + return 1 + fi + else + cd $SERVERBIN_DIR; ./ns-slapd -D $CONFIG_DIR -i $PIDFILE -w $STARTPIDFILE "$@" + if [ $? -ne 0 ]; then + return 1 + fi fi - loop_counter=1 # wait for 10 seconds for the start pid file to appear max_count=${STARTPID_TIME:-10} diff --git a/ldap/admin/src/scripts/stop-dirsrv.in b/ldap/admin/src/scripts/stop-dirsrv.in index bc38134..3f02e78 100755 --- a/ldap/admin/src/scripts/stop-dirsrv.in +++ b/ldap/admin/src/scripts/stop-dirsrv.in @@ -35,10 +35,33 @@ stop_instance() { fi return 2 } - # server is running - kill it - kill $PID - loop_counter=1 + + # + # use systemctl if running as root + # + if [ -d "@systemdsystemunitdir@" ] && [ "$(id -u)" == "0" ];then + # + # Now, check if systemctl is aware of this running instance + # + @bindir@/systemctl is-active @package_name@@$SERV_ID.service > /dev/null 2>&1 + if [ $? -eq 0 ]; then + # + # systemctl sees the running process, so stop it correctly + # + @bindir@/systemctl stop @package_name@@$SERV_ID.service + else + # + # Have to kill it since systemctl doesn't think it's running + # + kill $PID + fi + else + # server is running - kill it + kill $PID + fi + # wait for 10 minutes (600 times 1 second) + loop_counter=1 max_count=600 while test $loop_counter -le $max_count; do loop_counter=`expr $loop_counter + 1`