From c6054d12856c8789a778bde19b7e31e7e84e531b Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Mar 01 2019 20:46:17 +0000 Subject: Issue 50246 - Fix the regression in old control tools Bug Description: The old control tools - status-dirsrv, start-dirsrv, stop-dirsrv, restart-dirsrv stopped working properly after the /etc/sysconfig/dirsrv removal. Fix Description: Make them the direct systemctl command wrappers and don't look for instances in /etc/sysconfig/dirsrv. Fix UI. Make it use the new dsctl tools. Extend dsctl status (add JSON). Also, remove the dragon warning because it breaks the QE test reports when we run all the tests (we don't use DEBUGGING mode there because it doesn't remove the instances). The deprication warning should be enough for now. https://pagure.io/389-ds-base/issue/50246 Reviewed by: wibrown, vashirov, mhonek, mreynolds (Thanks!) --- diff --git a/ldap/admin/src/scripts/restart-dirsrv.in b/ldap/admin/src/scripts/restart-dirsrv.in index e86a24c..dfc0898 100644 --- a/ldap/admin/src/scripts/restart-dirsrv.in +++ b/ldap/admin/src/scripts/restart-dirsrv.in @@ -45,16 +45,27 @@ fi if [ "$#" -eq 0 ]; then # We're restarting all instances. ret=0 - 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 Restarting instance \"$inst\" - restart_instance $inst - rv=$? - if [ "$rv" -ne 0 ]; then - ret=$rv + # + # Use systemctl if available and running as root, + # + if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then + @bindir@/systemctl restart @package_name@@*.service -l + ret=$? + if [ $? -ne 0 ]; then + return 1 fi - done + else + 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 Restarting instance \"$inst\" + restart_instance $inst + rv=$? + if [ "$rv" -ne 0 ]; then + ret=$rv + fi + done + fi exit $ret else # We're restarting a single instance. diff --git a/ldap/admin/src/scripts/start-dirsrv.in b/ldap/admin/src/scripts/start-dirsrv.in index e3c46e3..4b9674b 100755 --- a/ldap/admin/src/scripts/start-dirsrv.in +++ b/ldap/admin/src/scripts/start-dirsrv.in @@ -15,16 +15,6 @@ start_instance() { 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" @@ -39,27 +29,36 @@ start_instance() { DS_CONFIG_DIR=$CONFIG_DIR export DS_CONFIG_DIR - PIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.pid - - if test -f $PIDFILE ; then - PID=`cat $PIDFILE` - if kill -s 0 $PID > /dev/null 2>&1 ; then - echo There is an ns-slapd running: $PID - return 2; - else - rm -f $PIDFILE - fi - fi # # Use systemctl if available and running as root, # otherwise start the instance the old way. # if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then - @bindir@/systemctl start @package_name@@$SERV_ID.service + @bindir@/systemctl start @package_name@@$SERV_ID.service -l if [ $? -ne 0 ]; then return 1 fi else + 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 + PIDFILE=$RUN_DIR/$PRODUCT_NAME-$SERV_ID.pid + + if test -f $PIDFILE ; then + PID=`cat $PIDFILE` + if kill -s 0 $PID > /dev/null 2>&1 ; then + echo There is an ns-slapd running: $PID + return 2; + else + rm -f $PIDFILE + fi + fi if test 1 -eq @enable_asan@; then echo "NOTICE: Starting instance ${SERV_ID} with ASAN options." echo "This is probably not what you want. Please contact support." @@ -72,27 +71,27 @@ start_instance() { if [ $? -ne 0 ]; then return 1 fi - 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 - PID=`cat $PIDFILE` - # if kill -s 0 $PID > /dev/null 2>&1 ; then - if kill -s 0 $PID ; then - return 0; + 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 + PID=`cat $PIDFILE` + # if kill -s 0 $PID > /dev/null 2>&1 ; then + if kill -s 0 $PID ; then + return 0; + else + echo Server failed to start !!! Please check errors log for problems + return 1 + fi else - echo Server failed to start !!! Please check errors log for problems - return 1 + sleep 1 fi - else - sleep 1 - fi - done - echo Server not running!! Failed to start ns-slapd process. Please check the errors log for problems. - return 1 + done + echo Server not running!! Failed to start ns-slapd process. Please check the errors log for problems. + return 1 + fi } # source env. for all instances @@ -114,16 +113,27 @@ found=0 if [ $# -eq 0 ]; then # We're starting all instances. ret=0 - 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 Starting instance \"$inst\" - start_instance $inst - rv=$? - if [ $rv -ne 0 ]; then - ret=$rv + # + # Use systemctl if available and running as root, + # + if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then + @bindir@/systemctl start @package_name@@*.service -l + ret=$? + if [ $? -ne 0 ]; then + return 1 fi - done + else + 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 Starting instance \"$inst\" + start_instance $inst + rv=$? + if [ $rv -ne 0 ]; then + ret=$rv + fi + done + fi exit $ret else # We're starting a single instance. diff --git a/ldap/admin/src/scripts/status-dirsrv.in b/ldap/admin/src/scripts/status-dirsrv.in index 8e492c1..86b7d4a 100755 --- a/ldap/admin/src/scripts/status-dirsrv.in +++ b/ldap/admin/src/scripts/status-dirsrv.in @@ -11,16 +11,6 @@ status_instance() { SERV_ID=$1 shift - initfile=`get_init_file $initconfig_dir $SERV_ID` || { echo Instance $SERV_ID not found. ; return 255 ; } - - # source env. for this instance - if [ -f $initfile ] ; then - . $initfile - else - echo Instance $SERV_ID not found. - return 255 - fi - prefix="$DS_ROOT" libpath_add "$prefix$SERVER_DIR" @@ -37,11 +27,21 @@ status_instance() { # Use systemctl if available. # if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then - @bindir@/systemctl status @package_name@@$SERV_ID.service -l + @bindir@/systemctl status @package_name@@$SERV_ID.service -l --no-pager rv=$? if [ $rv -ne 0 ]; then return 1 fi + else + initfile=`get_init_file $initconfig_dir $SERV_ID` || { echo Instance $SERV_ID not found. ; return 255 ; } + + # source env. for this instance + if [ -f $initfile ] ; then + . $initfile + else + echo Instance $SERV_ID not found. + return 255 + fi fi return 0 } @@ -65,18 +65,28 @@ found=0 if [ $# -eq 0 ]; then # We're reporting the status of all instances. ret=0 - @bindir@/systemctl status @package_name@.target -l - 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 [ $rv -ne 0 ]; then - ret=`expr $ret + 1` + # + # Use systemctl if available and running as root, + # + if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then + @bindir@/systemctl status @package_name@@*.service -l --no-pager + ret=$? + if [ $? -ne 0 ]; then + return 1 fi - done + else + 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 [ $rv -ne 0 ]; then + ret=`expr $ret + 1` + fi + done + fi exit $ret else # We're getting the status of a single instance. diff --git a/ldap/admin/src/scripts/stop-dirsrv.in b/ldap/admin/src/scripts/stop-dirsrv.in index 72e2b85..354ff0c 100755 --- a/ldap/admin/src/scripts/stop-dirsrv.in +++ b/ldap/admin/src/scripts/stop-dirsrv.in @@ -11,31 +11,6 @@ stop_instance() { SERV_ID=$1 - 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 - - 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 -s 0 $PID > /dev/null 2>&1 || { - echo Server not running - if test -f $PIDFILE ; then - rm -f $PIDFILE - fi - return 2 - } - # # use systemctl if running as root # @@ -48,7 +23,7 @@ stop_instance() { # # systemctl sees the running process, so stop it correctly # - @bindir@/systemctl stop @package_name@@$SERV_ID.service + @bindir@/systemctl stop @package_name@@$SERV_ID.service -l else # # Have to kill it since systemctl doesn't think it's running @@ -56,6 +31,30 @@ stop_instance() { kill $PID fi else + 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 + + 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 -s 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 fi @@ -95,20 +94,31 @@ fi if [ $# -eq 0 ]; then # We're stopping all instances. ret=0 - initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; } - for i in $initfiles; do - if [ ! -f "$i" ] ; then - echo No instances found in $initconfig_dir - exit 1 - fi - inst=`normalize_server_id $i` - echo Stopping instance \"$inst\" - stop_instance $inst - rv=$? - if [ $rv -ne 0 ]; then - ret=$rv + # + # Use systemctl if available and running as root, + # + if [ -d "@systemdsystemunitdir@" ] && [ $(id -u) -eq 0 ];then + @bindir@/systemctl stop @package_name@@*.service -l + ret=$? + if [ $? -ne 0 ]; then + return 1 fi - done + else + initfiles=`get_initconfig_files $initconfig_dir` || { echo No instances found in $initconfig_dir ; exit 1 ; } + for i in $initfiles; do + if [ ! -f "$i" ] ; then + echo No instances found in $initconfig_dir + exit 1 + fi + inst=`normalize_server_id $i` + echo Stopping instance \"$inst\" + stop_instance $inst + rv=$? + if [ $rv -ne 0 ]; then + ret=$rv + fi + done + fi exit $ret else # We're stopping a single instance. diff --git a/src/cockpit/389-console/src/ds.js b/src/cockpit/389-console/src/ds.js index d309845..953a450 100644 --- a/src/cockpit/389-console/src/ds.js +++ b/src/cockpit/389-console/src/ds.js @@ -162,22 +162,31 @@ function check_inst_alive (connect_err) { if (connect_err === undefined) { connect_err = 0; } - cmd = ['status-dirsrv', server_inst]; - cockpit.spawn(cmd, { superuser: true }).done(function () { - if (connect_err) { - $("#ds-navigation").hide(); - $(".all-pages").hide(); - $("#no-connect").show(); - } else { - // if nav page was hidden reset everything - if ($("#ds-navigation").is(":hidden") ){ + cmd = [DSCTL, '-j', server_inst, 'status']; + cockpit.spawn(cmd, { superuser: true}). + done(function(status_data) { + var status_json = JSON.parse(status_data); + if (status_json.running == true) { + if (connect_err) { + $("#ds-navigation").hide(); $(".all-pages").hide(); - $("#ds-navigation").show(); - $("#server-content").show(); - $("#server-config").show(); + $("#no-connect").show(); + } else { + // if nav page was hidden reset everything + if ($("#ds-navigation").is(":hidden") ){ + $(".all-pages").hide(); + $("#ds-navigation").show(); + $("#server-content").show(); + $("#server-config").show(); + } + $("#not-running").hide(); + $("#no-connect").hide(); } - $("#not-running").hide(); - $("#no-connect").hide(); + } else { + $("#loading-page").hide(); + $("#ds-navigation").hide(); + $(".all-pages").hide(); + $("#not-running").show(); } }).fail(function(data) { $("#loading-page").hide(); diff --git a/src/cockpit/389-console/src/servers.js b/src/cockpit/389-console/src/servers.js index 4d1865c..13e343f 100644 --- a/src/cockpit/389-console/src/servers.js +++ b/src/cockpit/389-console/src/servers.js @@ -410,36 +410,41 @@ function save_config() { } function do_backup(server_inst, backup_name) { - var cmd = ['status-dirsrv', server_inst]; + var cmd = [DSCTL, '-j', server_inst, 'status']; $("#backup-spinner").show(); cockpit.spawn(cmd, { superuser: true}). - done(function() { - var cmd = [DSCONF, server_inst, 'backup', 'create', backup_name]; - log_cmd('#ds-backup-btn (click)', 'Backup server instance', cmd); - cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). - done(function(data) { - $("#backup-spinner").hide(); - popup_success("Backup has been created"); - $("#backup-form").modal('toggle'); - }). - fail(function(data) { - $("#backup-spinner").hide(); - popup_err("Failed to backup the server", data.message); - }) + done(function(status_data) { + var status_json = JSON.parse(status_data); + if (status_json.running == true) { + var cmd = [DSCONF, server_inst, 'backup', 'create', backup_name]; + log_cmd('#ds-backup-btn (click)', 'Backup server instance', cmd); + cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). + done(function(data) { + $("#backup-spinner").hide(); + popup_success("Backup has been created"); + $("#backup-form").modal('toggle'); + }). + fail(function(data) { + $("#backup-spinner").hide(); + popup_err("Failed to backup the server", data.message); + }) + } else { + var cmd = [DSCTL, server_inst, 'db2bak', backup_name]; + log_cmd('#ds-backup-btn (click)', 'Backup server instance (offline)', cmd); + cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). + done(function(data) { + $("#backup-spinner").hide(); + popup_success("Backup has been created"); + $("#backup-form").modal('toggle'); + }). + fail(function(data) { + $("#backup-spinner").hide(); + popup_err("Failed to backup the server", data.message); + }); + } }). fail(function() { - var cmd = [DSCTL, server_inst, 'db2bak', backup_name]; - log_cmd('#ds-backup-btn (click)', 'Backup server instance (offline)', cmd); - cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). - done(function(data) { - $("#backup-spinner").hide(); - popup_success("Backup has been created"); - $("#backup-form").modal('toggle'); - }). - fail(function(data) { - $("#backup-spinner").hide(); - popup_err("Failed to backup the server", data.message); - }); + popup_err("Failed to check the server status", data.message); }); } @@ -509,7 +514,7 @@ $(document).ready( function() { document.getElementById("remove-server-btn").addEventListener("click", function() { popup_confirm("Are you sure you want to this remove instance: " + server_id + "", "Confirmation", function (yes) { if (yes) { - var cmd = [DSCTL, server_id, "remove", "--do-it"]; + var cmd = [DSCTL, server_inst, "remove", "--do-it"]; $("#ds-remove-inst").html(" Removing instance " + server_id + "..."); $("#remove-instance-form").modal('toggle'); log_cmd('#remove-server-btn (click)', 'Remove instance', cmd); @@ -1312,8 +1317,8 @@ $(document).ready( function() { } // First check if backup name is already used - var check_cmd = [DSCTL, '-j', server_id, 'backups']; - log_cmd('#ds-backup-btn (click)', 'Check backup name', check_cmd); + var check_cmd = [DSCTL, '-j', server_inst, 'backups']; + log_cmd('#restore-server-btn (click)', 'Restore server instance', check_cmd); cockpit.spawn(check_cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(data) { var obj = JSON.parse(data); var found_backup = false; @@ -1343,7 +1348,7 @@ $(document).ready( function() { /* Restore. load restore table with current backups */ $("#restore-server-btn").on('click', function () { - var cmd = [DSCTL, '-j', server_id, 'backups']; + var cmd = [DSCTL, '-j', server_inst, 'backups']; log_cmd('#restore-server-btn (click)', 'Restore server instance', cmd); cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}).done(function(data) { var backup_btn = ""; @@ -1368,36 +1373,41 @@ $(document).ready( function() { var restore_name = data[0]; popup_confirm("Are you sure you want to restore this backup: " + restore_name + "", "Confirmation", function (yes) { if (yes) { - var cmd = ['status-dirsrv', server_inst]; + var cmd = [DSCTL, '-j', server_inst, 'status']; $("#restore-spinner").show(); cockpit.spawn(cmd, { superuser: true}). - done(function() { - var cmd = [DSCONF, server_inst, 'backup', 'restore', restore_name]; - log_cmd('.restore-btn (click)', 'Restore server instance(online)', cmd); - cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). - done(function(data) { - $("#restore-spinner").hide(); - popup_success("The backup has been restored"); - $("#restore-form").modal('toggle'); - }). - fail(function(data) { - $("#restore-spinner").hide(); - popup_err("Failed to restore from the backup", data.message); - }); + done(function(status_data) { + var status_json = JSON.parse(status_data); + if (status_json.running == true) { + var cmd = [DSCONF, server_inst, 'backup', 'restore', restore_name]; + log_cmd('.restore-btn (click)', 'Restore server instance(online)', cmd); + cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). + done(function(data) { + $("#restore-spinner").hide(); + popup_success("The backup has been restored"); + $("#restore-form").modal('toggle'); + }). + fail(function(data) { + $("#restore-spinner").hide(); + popup_err("Failed to restore from the backup", data.message); + }); + } else { + var cmd = [DSCTL, server_inst, 'bak2db', restore_name]; + log_cmd('.restore-btn (click)', 'Restore server instance(offline)', cmd); + cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). + done(function(data) { + $("#restore-spinner").hide(); + popup_success("The backup has been restored"); + $("#restore-form").modal('toggle'); + }). + fail(function(data) { + $("#restore-spinner").hide(); + popup_err("Failed to restore from the backup", data.message); + }); + } }). fail(function() { - var cmd = [DSCTL, server_inst, 'bak2db', restore_name]; - log_cmd('.restore-btn (click)', 'Restore server instance(offline)', cmd); - cockpit.spawn(cmd, { superuser: true, "err": "message", "environ": [ENV]}). - done(function(data) { - $("#restore-spinner").hide(); - popup_success("The backup has been restored"); - $("#restore-form").modal('toggle'); - }). - fail(function(data) { - $("#restore-spinner").hide(); - popup_err("Failed to restore from the backup", data.message); - }); + popup_err("Failed to check the server status", data.message); }); } }); @@ -1430,9 +1440,9 @@ $(document).ready( function() { $("#schema-reload-btn").on("click", function () { var schema_dir = $("#reload-dir").val(); if (schema_dir != ""){ - var cmd = [DSCONF, server_id, 'schema', 'reload', '--schemadir', schema_dir, '--wait']; + var cmd = [DSCONF, server_inst, 'schema', 'reload', '--schemadir', schema_dir, '--wait']; } else { - var cmd = [DSCONF, server_id, 'schema', 'reload', '--wait']; + var cmd = [DSCONF, server_inst, 'schema', 'reload', '--wait']; } $("#reload-spinner").show(); log_cmd('#schema-reload-btn (click)', 'Reload schema files', cmd); diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py index 36b4c12..7151497 100644 --- a/src/lib389/lib389/__init__.py +++ b/src/lib389/lib389/__init__.py @@ -154,37 +154,8 @@ def wrapper(f, name): c_stack = inspect.stack() frame = c_stack[1] - - warnings.warn(DeprecationWarning("Use of raw ldap function %s. This will removed in a future release. Found in: %s:%s" % (name, frame.filename, frame.lineno))) - if not DEBUGGING: - sys.stderr.write(""" -________________________________________ -/ YOU ARE USING A DEPRECATED AND INVALID \\ -| LIB389 API. YOU PROBABLY WANT A | -| DSLDAPOBJECT INSTEAD! | -| | -| IN THE FUTURE THIS WILL CRASH YOUR | -| APPLICATION | -| | -\\ %s found at %s:%s / - ---------------------------------------- - \\ / \ //\\ - \\ |\\___/| / \\// \\\\ - /0 0 \\__ / // | \\ \\ - / / \\/_/ // | \\ \\ - @_^_@'/ \\/_ // | \\ \\ - //_^_/ \\/_ // | \\ \\ - ( //) | \\/// | \\ \\ - ( / /) _|_ / ) // | \\ _\\ - ( // /) '/,_ _ _/ ( ; -. | _ _\\.-~ .-~~~^-. - (( / / )) ,-{ _ `-.|.-~-. .~ `. - (( // / )) '/\\ / ~-. _ .-~ .-~^-. \\ - (( /// )) `. { } / \\ \\ - (( / )) .----~-.\\ \\-' .~ \\ `. \\^-. - ///.----..> \\ _ -~ `. ^-` ^-_ - ///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~ - /.-~ - """ % (name, frame.filename, frame.lineno)) + warnings.warn(DeprecationWarning("Use of raw ldap function %s. This will be removed in a future release. " + "Found in: %s:%s" % (name, frame.filename, frame.lineno))) # Later, we will add a sleep here to make it even more painful. # Finally, it will raise an exception. elif 'escapehatch' in kwargs: diff --git a/src/lib389/lib389/cli_ctl/instance.py b/src/lib389/lib389/cli_ctl/instance.py index 735de0f..95958e1 100644 --- a/src/lib389/lib389/cli_ctl/instance.py +++ b/src/lib389/lib389/cli_ctl/instance.py @@ -1,22 +1,22 @@ # --- BEGIN COPYRIGHT BLOCK --- -# Copyright (C) 2018 Red Hat, Inc. +# Copyright (C) 2019 Red Hat, Inc. # All rights reserved. # # License: GPL (version 3 or any later version). # See LICENSE for details. # --- END COPYRIGHT BLOCK --- -from lib389._constants import * - +import os +import json +import time +import sys +from getpass import getpass from lib389 import DirSrv from lib389.tools import DirSrvTools from lib389.instance.setup import SetupDs from lib389.utils import get_instance_list from lib389.instance.remove import remove_ds_instance -from getpass import getpass -import os -import time -import sys +from lib389._constants import CONF_SERVER_ID from lib389.instance.options import General2Base, Slapd2Base, Backend2Base @@ -51,6 +51,10 @@ def instance_stop(inst, log, args): def instance_status(inst, log, args): + if args.json: + print(json.dumps({"type": "result", "running": inst.status()})) + return + if inst.status() is True: log.info('Instance "{}" is running'.format(inst.serverid)) else: