diff --git a/Makefile.in b/Makefile.in index 2700a78..108bfe8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -53,7 +53,7 @@ $(info Building against PostgreSQL $(MAJORVERSION)) REPMGR_CLIENT_OBJS = repmgr-client.o \ repmgr-action-primary.o repmgr-action-standby.o repmgr-action-witness.o \ - repmgr-action-bdr.o repmgr-action-cluster.o repmgr-action-node.o repmgr-action-service.o \ + repmgr-action-bdr.o repmgr-action-cluster.o repmgr-action-node.o repmgr-action-service.o repmgr-action-daemon.o \ configfile.o configfile-scan.o log.o strutil.o controldata.o dirutil.o compat.o dbutils.o sysutils.o REPMGRD_OBJS = repmgrd.o repmgrd-physical.o repmgrd-bdr.o configfile.o configfile-scan.o log.o dbutils.o strutil.o controldata.o compat.o sysutils.o DATE=$(shell date "+%Y-%m-%d") diff --git a/doc/appendix-release-notes.xml b/doc/appendix-release-notes.xml index 93e5a8c..e5fe4e0 100644 --- a/doc/appendix-release-notes.xml +++ b/doc/appendix-release-notes.xml @@ -24,12 +24,9 @@ Compatibility changes - The repmgr daemon ... commands have been renamed to - repmgr service .... - - - The repmgr daemon ... form will still be accepted - for backwards compatibility. + Some repmgr daemon ... commands have been renamed to + repmgr service ... as they have a cluster-wide effect + and to avoid giving the impression they affect only the local &repmgr; daemon. Following commands are affected: @@ -57,22 +54,13 @@ - - - repmgr daemon start - (now repmgr service start) - - - - - - repmgr daemon stop - (now repmgr service stop) - - - + + The repmgr daemon ... form will still be accepted + for backwards compatibility. + + The following command line options, which have been deprecated since &repmgr; 3.3 @@ -497,8 +485,8 @@ REPMGRD_OPTS="--daemonize=false" - New commands repmgr daemon start and - repmgr daemon stop: + New commands repmgr daemon start and + repmgr daemon stop: these provide a standardized way of starting and stopping &repmgrd;. GitHub #528. diff --git a/doc/filelist.xml b/doc/filelist.xml index e59e35d..b2bb157 100644 --- a/doc/filelist.xml +++ b/doc/filelist.xml @@ -55,10 +55,10 @@ - - + + diff --git a/doc/repmgr-daemon-start.xml b/doc/repmgr-daemon-start.xml index ae5e21f..fb0eb6d 100644 --- a/doc/repmgr-daemon-start.xml +++ b/doc/repmgr-daemon-start.xml @@ -1,6 +1,6 @@ - + - repmgr service start + repmgr daemon start @@ -9,11 +9,11 @@ - repmgr service start + repmgr daemon start - repmgr service start + repmgr daemon start Start the &repmgrd; service @@ -32,8 +32,8 @@ The repmgr.conf parameter repmgrd_service_start_command - must be set for repmgr service start to work; see section - for details. + must be set for repmgr daemon start to work; see section + for details. @@ -89,11 +89,11 @@ - + Configuration file settings The following parameter in repmgr.conf is relevant - to repmgr service start: + to repmgr daemon start: @@ -104,11 +104,11 @@ repmgrd_service_start_command - with "repmgr service start" + with "repmgr daemon start" - repmgr service start will execute the command defined by the + repmgr daemon start will execute the command defined by the repmgrd_service_start_command parameter in repmgr.conf. This must be set to a shell command which will start &repmgrd;; if &repmgr; was installed from a package, this will be the service command defined by the @@ -132,7 +132,7 @@ Exit codes - One of the following exit codes will be emitted by repmgr service start: + One of the following exit codes will be emitted by repmgr daemon start: @@ -197,7 +197,7 @@ See also - , , + , , diff --git a/doc/repmgr-daemon-stop.xml b/doc/repmgr-daemon-stop.xml index dc93856..2304201 100644 --- a/doc/repmgr-daemon-stop.xml +++ b/doc/repmgr-daemon-stop.xml @@ -1,4 +1,4 @@ - + repmgr daemon stop @@ -40,7 +40,7 @@ The repmgr.conf parameter repmgrd_service_stop_command must be set for repmgr daemon stop to work; see section - for details. + for details. @@ -114,7 +114,7 @@ - + Configuration file settings The following parameter in repmgr.conf is relevant @@ -194,7 +194,7 @@ See also - , , + , , diff --git a/doc/repmgr.xml b/doc/repmgr.xml index d3dc3b7..5de1178 100644 --- a/doc/repmgr.xml +++ b/doc/repmgr.xml @@ -117,10 +117,10 @@ &repmgr-cluster-event; &repmgr-cluster-cleanup; &repmgr-service-status; - &repmgr-service-start; - &repmgr-service-stop; &repmgr-service-pause; &repmgr-service-unpause; + &repmgr-daemon-start; + &repmgr-daemon-stop; &appendix-release-notes; diff --git a/doc/repmgrd-configuration.xml b/doc/repmgrd-configuration.xml index d674e4e..dd28650 100644 --- a/doc/repmgrd-configuration.xml +++ b/doc/repmgrd-configuration.xml @@ -518,10 +518,8 @@ repmgrd service configuration - If you are intending to use the repmgr service start - and repmgr service stop - (&repmgr; 4.2 - 4.4: repmgr daemon start - and repmgr daemon stop) + If you are intending to use the repmgr daemon start + and repmgr daemon stop commands, the following parameters must be set in repmgr.conf: @@ -861,14 +859,14 @@ repmgrd_service_stop_command='sudo systemctl repmgr11 stop' for different distributions. - The commands repmgr service start and - repmgr service stop can be used + The commands repmgr daemon start and + repmgr daemon stop can be used as convenience wrappers to start and stop &repmgrd; on the local node. - repmgr daemon start and - repmgr daemon stop require + repmgr daemon start and + repmgr daemon stop require that the appropriate start/stop commands are configured as repmgrd_service_start_command and repmgrd_service_stop_command in repmgr.conf. diff --git a/repmgr-action-service.c b/repmgr-action-service.c index 74941be..2e29e30 100644 --- a/repmgr-action-service.c +++ b/repmgr-action-service.c @@ -26,9 +26,6 @@ #include "repmgr-client-global.h" #include "repmgr-action-service.h" -#define REPMGR_SERVICE_STOP_START_WAIT 15 -#define REPMGR_SERVICE_STATUS_START_HINT _("use \"repmgr service status\" to confirm that repmgrd was successfully started") -#define REPMGR_SERVICE_STATUS_STOP_HINT _("use \"repmgr service status\" to confirm that repmgrd was successfully stopped") /* * Possibly also show: @@ -499,284 +496,6 @@ fetch_node_records(PGconn *conn, NodeInfoList *node_list) } -void -do_service_start(void) -{ - PGconn *conn = NULL; - PQExpBufferData repmgrd_command; - PQExpBufferData output_buf; - bool success; - - if (config_file_options.repmgrd_service_start_command[0] == '\0') - { - log_error(_("\"repmgrd_service_start_command\" is not set")); - log_hint(_("set \"repmgrd_service_start_command\" in \"repmgr.conf\"")); - exit(ERR_BAD_CONFIG); - } - - log_verbose(LOG_INFO, _("connecting to local node")); - - conn = establish_db_connection(config_file_options.conninfo, false); - - if (PQstatus(conn) != CONNECTION_OK) - { - /* TODO: if PostgreSQL is not available, have repmgrd loop and retry connection */ - log_error(_("unable to connect to local node")); - log_detail(_("PostgreSQL must be running before \"repmgrd\" can be started")); - exit(ERR_DB_CONN); - } - - /* - * if local connection available, check if repmgr.so is installed, and - * whether repmgrd is running - */ - check_shared_library(conn); - - if (is_repmgrd_running(conn) == true) - { - pid_t pid = UNKNOWN_PID; - - log_error(_("repmgrd appears to be running already")); - - pid = repmgrd_get_pid(conn); - - if (pid != UNKNOWN_PID) - log_detail(_("repmgrd PID is %i"), pid); - else - log_warning(_("unable to determine repmgrd PID")); - - PQfinish(conn); - exit(ERR_REPMGRD_SERVICE); - } - - PQfinish(conn); - - - initPQExpBuffer(&repmgrd_command); - appendPQExpBufferStr(&repmgrd_command, - config_file_options.repmgrd_service_start_command); - - if (runtime_options.dry_run == true) - { - log_info(_("prerequisites for starting repmgrd met")); - log_detail("following command would be executed:\n %s", repmgrd_command.data); - exit(SUCCESS); - } - - log_notice(_("executing: \"%s\""), repmgrd_command.data); - - initPQExpBuffer(&output_buf); - - success = local_command(repmgrd_command.data, &output_buf); - termPQExpBuffer(&repmgrd_command); - - if (success == false) - { - log_error(_("unable to start repmgrd")); - if (output_buf.data[0] != '\0') - log_detail("%s", output_buf.data); - termPQExpBuffer(&output_buf); - exit(ERR_REPMGRD_SERVICE); - } - - termPQExpBuffer(&output_buf); - - if (runtime_options.no_wait == true || runtime_options.wait == 0) - { - log_hint(REPMGR_SERVICE_STATUS_START_HINT); - } - else - { - int i = 0; - int timeout = REPMGR_SERVICE_STOP_START_WAIT; - - if (runtime_options.wait_provided) - timeout = runtime_options.wait; - - conn = establish_db_connection(config_file_options.conninfo, false); - - if (PQstatus(conn) != CONNECTION_OK) - { - log_notice(_("unable to connect to local node")); - log_hint(REPMGR_SERVICE_STATUS_START_HINT); - exit(ERR_DB_CONN); - } - - for (;;) - { - if (is_repmgrd_running(conn) == true) - { - log_notice(_("repmgrd was successfully started")); - PQfinish(conn); - break; - } - - if (i == timeout) - { - PQfinish(conn); - log_error(_("repmgrd does not appear to have started after %i seconds"), - timeout); - log_hint(REPMGR_SERVICE_STATUS_START_HINT); - exit(ERR_REPMGRD_SERVICE); - } - - log_debug("sleeping 1 second; %i of %i attempts to determine if repmgrd is running", - i, runtime_options.wait); - sleep(1); - i++; - } - } -} - - -void do_service_stop(void) -{ - PGconn *conn = NULL; - PQExpBufferData repmgrd_command; - PQExpBufferData output_buf; - bool success; - bool have_db_connection = true; - pid_t pid = UNKNOWN_PID; - - if (config_file_options.repmgrd_service_stop_command[0] == '\0') - { - log_error(_("\"repmgrd_service_stop_command\" is not set")); - log_hint(_("set \"repmgrd_service_stop_command\" in \"repmgr.conf\"")); - exit(ERR_BAD_CONFIG); - } - - /* - * if local connection available, check if repmgr.so is installed, and - * whether repmgrd is running - */ - log_verbose(LOG_INFO, _("connecting to local node")); - - conn = establish_db_connection(config_file_options.conninfo, false); - - if (PQstatus(conn) != CONNECTION_OK) - { - /* - * a PostgreSQL connection is not required to stop repmgrd, - */ - log_warning(_("unable to connect to local node")); - have_db_connection = false; - } - else - { - check_shared_library(conn); - - if (is_repmgrd_running(conn) == false) - { - log_error(_("repmgrd appears to be stopped already")); - PQfinish(conn); - exit(ERR_REPMGRD_SERVICE); - } - - /* Attempt to fetch the PID, in case we need it later */ - pid = repmgrd_get_pid(conn); - log_debug("retrieved pid is %i", pid); - } - - PQfinish(conn); - - initPQExpBuffer(&repmgrd_command); - - appendPQExpBufferStr(&repmgrd_command, - config_file_options.repmgrd_service_stop_command); - - if (runtime_options.dry_run == true) - { - log_info(_("prerequisites for stopping repmgrd met")); - log_detail("following command would be executed:\n %s", repmgrd_command.data); - exit(SUCCESS); - } - - log_notice(_("executing: \"%s\""), repmgrd_command.data); - - initPQExpBuffer(&output_buf); - - success = local_command(repmgrd_command.data, &output_buf); - termPQExpBuffer(&repmgrd_command); - - if (success == false) - { - log_error(_("unable to stop repmgrd")); - if (output_buf.data[0] != '\0') - log_detail("%s", output_buf.data); - termPQExpBuffer(&output_buf); - exit(ERR_REPMGRD_SERVICE); - } - - termPQExpBuffer(&output_buf); - - if (runtime_options.no_wait == true || runtime_options.wait == 0) - { - if (have_db_connection == true) - log_hint(REPMGR_SERVICE_STATUS_STOP_HINT); - } - else - { - int i = 0; - int timeout = REPMGR_SERVICE_STOP_START_WAIT; - /* - * - */ - if (pid == UNKNOWN_PID) - { - /* - * XXX attempt to get pidfile from config - * and get contents - * ( see check_and_create_pid_file() ) - * if PID still unknown, exit here - */ - log_warning(_("unable to determine repmgrd PID")); - - if (have_db_connection == true) - log_hint(REPMGR_SERVICE_STATUS_STOP_HINT); - - exit(ERR_REPMGRD_SERVICE); - } - - if (runtime_options.wait_provided) - timeout = runtime_options.wait; - - for (;;) - { - if (kill(pid, 0) == -1) - { - if (errno == ESRCH) - { - log_notice(_("repmgrd was successfully stopped")); - exit(SUCCESS); - } - else - { - log_error(_("unable to determine status of process with PID %i"), pid); - log_detail("%s", strerror(errno)); - exit(ERR_REPMGRD_SERVICE); - } - } - - - if (i == timeout) - { - log_error(_("repmgrd does not appear to have stopped after %i seconds"), - timeout); - - if (have_db_connection == true) - log_hint(REPMGR_SERVICE_STATUS_START_HINT); - - exit(ERR_REPMGRD_SERVICE); - } - - log_debug("sleeping 1 second; %i of %i attempts to determine if repmgrd with PID %i is running", - i, timeout, pid); - sleep(1); - i++; - } - } -} - void do_service_help(void) { @@ -786,8 +505,7 @@ void do_service_help(void) printf(_(" %s [OPTIONS] service status\n"), progname()); printf(_(" %s [OPTIONS] service pause\n"), progname()); printf(_(" %s [OPTIONS] service unpause\n"), progname()); - printf(_(" %s [OPTIONS] service start\n"), progname()); - printf(_(" %s [OPTIONS] service stop\n"), progname()); + puts(""); printf(_("SERVICE STATUS\n")); @@ -799,24 +517,6 @@ void do_service_help(void) printf(_(" --verbose show text of database connection error messages\n")); puts(""); - printf(_("SERVICE START\n")); - puts(""); - printf(_(" \"service start\" attempts to start repmgrd\n")); - puts(""); - printf(_(" --dry-run check prerequisites but don't start repmgrd\n")); - printf(_(" -w/--wait wait for repmgrd to start (default: %i seconds)\n"), REPMGR_SERVICE_STOP_START_WAIT); - printf(_(" --no-wait don't wait for repmgrd to start\n")); - puts(""); - - printf(_("SERVICE STOP\n")); - puts(""); - printf(_(" \"service stop\" attempts to stop repmgrd\n")); - puts(""); - printf(_(" --dry-run check prerequisites but don't stop repmgrd\n")); - printf(_(" -w/--wait wait for repmgrd to stop (default: %i seconds)\n"), REPMGR_SERVICE_STOP_START_WAIT); - printf(_(" --no-wait don't wait for repmgrd to stop\n")); - puts(""); - printf(_("SERVICE PAUSE\n")); puts(""); printf(_(" \"service pause\" instructs repmgrd on each node to pause failover detection\n")); diff --git a/repmgr-action-service.h b/repmgr-action-service.h index a62ce75..e22c059 100644 --- a/repmgr-action-service.h +++ b/repmgr-action-service.h @@ -23,8 +23,6 @@ extern void do_service_status(void); extern void do_service_pause(void); extern void do_service_unpause(void); -extern void do_service_start(void); -extern void do_service_stop(void); extern void do_service_help(void); #endif diff --git a/repmgr-client.c b/repmgr-client.c index ee7315c..c0e6263 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -36,8 +36,9 @@ * SERVICE STATUS * SERVICE PAUSE * SERVICE UNPAUSE - * SERVICE START - * SERVICE STOP + * + * DAEMON START + * DAEMON STOP * * 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 @@ -70,6 +71,7 @@ #include "repmgr-action-node.h" #include "repmgr-action-cluster.h" #include "repmgr-action-service.h" +#include "repmgr-action-daemon.h" #include /* for PG_TEMP_FILE_PREFIX */ @@ -952,8 +954,7 @@ main(int argc, char **argv) else if (strcasecmp(repmgr_action, "CLEANUP") == 0) action = CLUSTER_CLEANUP; } - /* allow "daemon" as an alias for "service" for repmgr 4.x compatibility */ - else if (strcasecmp(repmgr_command, "SERVICE") == 0 || strcasecmp(repmgr_command, "DAEMON") == 0) + else if (strcasecmp(repmgr_command, "SERVICE") == 0) { if (help_option == true) { @@ -967,10 +968,28 @@ main(int argc, char **argv) action = SERVICE_PAUSE; else if (strcasecmp(repmgr_action, "UNPAUSE") == 0) action = SERVICE_UNPAUSE; - else if (strcasecmp(repmgr_action, "START") == 0) - action = SERVICE_START; + + } + else if (strcasecmp(repmgr_command, "DAEMON") == 0) + { + if (help_option == true) + { + do_daemon_help(); + exit(SUCCESS); + } + + if (strcasecmp(repmgr_action, "START") == 0) + action = DAEMON_START; else if (strcasecmp(repmgr_action, "STOP") == 0) - action = SERVICE_STOP; + action = DAEMON_STOP; + + /* allow "daemon" as an alias for "service" for repmgr 4.x compatibility */ + if (strcasecmp(repmgr_action, "STATUS") == 0) + action = SERVICE_STATUS; + else if (strcasecmp(repmgr_action, "PAUSE") == 0) + action = SERVICE_PAUSE; + else if (strcasecmp(repmgr_action, "UNPAUSE") == 0) + action = SERVICE_UNPAUSE; } else { @@ -1383,11 +1402,13 @@ main(int argc, char **argv) case SERVICE_UNPAUSE: do_service_unpause(); break; - case SERVICE_START: - do_service_start(); + + /* DAEMON */ + case DAEMON_START: + do_daemon_start(); break; - case SERVICE_STOP: - do_service_stop(); + case DAEMON_STOP: + do_daemon_stop(); break; default: @@ -1755,8 +1776,8 @@ check_cli_parameters(const int action) { switch (action) { - case SERVICE_START: - case SERVICE_STOP: + case DAEMON_START: + case DAEMON_STOP: case STANDBY_FOLLOW: break; default: @@ -1769,8 +1790,8 @@ check_cli_parameters(const int action) { switch (action) { - case SERVICE_START: - case SERVICE_STOP: + case DAEMON_START: + case DAEMON_STOP: case NODE_REJOIN: break; default: @@ -1895,8 +1916,8 @@ check_cli_parameters(const int action) case NODE_SERVICE: case SERVICE_PAUSE: case SERVICE_UNPAUSE: - case SERVICE_START: - case SERVICE_STOP: + case DAEMON_START: + case DAEMON_STOP: break; default: item_list_append_format(&cli_warnings, @@ -2469,10 +2490,11 @@ action_name(const int action) return "SERVICE PAUSE"; case SERVICE_UNPAUSE: return "SERVICE UNPAUSE"; - case SERVICE_START: - return "SERVICE START"; - case SERVICE_STOP: - return "SERVICE STOP"; + + case DAEMON_START: + return "DAEMON START"; + case DAEMON_STOP: + return "DAEMON STOP"; } return "UNKNOWN ACTION"; @@ -2583,7 +2605,8 @@ do_help(void) printf(_(" %s [OPTIONS] node {status|check|rejoin|service}\n"), progname()); printf(_(" %s [OPTIONS] cluster {show|event|matrix|crosscheck|cleanup}\n"), progname()); printf(_(" %s [OPTIONS] witness {register|unregister}\n"), progname()); - printf(_(" %s [OPTIONS] service {status|pause|unpause|start|stop}\n"), progname()); + printf(_(" %s [OPTIONS] service {status|pause|unpause}\n"), progname()); + printf(_(" %s [OPTIONS] daemon {start|stop}\n"), progname()); puts(""); diff --git a/repmgr-client.h b/repmgr-client.h index 679aa38..9620849 100644 --- a/repmgr-client.h +++ b/repmgr-client.h @@ -49,8 +49,8 @@ #define SERVICE_STATUS 23 #define SERVICE_PAUSE 24 #define SERVICE_UNPAUSE 25 -#define SERVICE_START 26 -#define SERVICE_STOP 27 +#define DAEMON_START 26 +#define DAEMON_STOP 27 /* command line options without short versions */ #define OPT_HELP 1001