diff --git a/config.c b/config.c index a116cd1d..205aadca 100644 --- a/config.c +++ b/config.c @@ -631,6 +631,7 @@ reload_config(t_configuration_options *orig_options) } +/* TODO: don't emit warnings if --terse and no errors */ static void exit_with_errors(ItemList *config_errors, ItemList *config_warnings) { diff --git a/repmgr-client.c b/repmgr-client.c index 3b6e8563..11fcb7b0 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -60,7 +60,7 @@ main(int argc, char **argv) logger_output_mode = OM_COMMAND_LINE; - while ((c = getopt_long(argc, argv, "?Vf:Fb:S:D:L:vt", long_options, + while ((c = getopt_long(argc, argv, "?Vf:Fb:S:L:vtD:", long_options, &optindex)) != -1) { /* @@ -114,11 +114,41 @@ main(int argc, char **argv) strncpy(runtime_options.superuser, optarg, MAXLEN); break; + /* node options * + * ------------ */ + + /* -D/--pgdata/--data-dir */ case 'D': strncpy(runtime_options.data_dir, optarg, MAXPGPATH); break; - /* logging options + /* --node-id */ + case OPT_NODE_ID: + runtime_options.node_id = repmgr_atoi(optarg, "--node-id", &cli_errors, false); + break; + + /* --node-name */ + case OPT_NODE_NAME: + strncpy(runtime_options.node_name, optarg, MAXLEN); + break; + + /* event options * + * ------------- */ + + case OPT_EVENT: + strncpy(runtime_options.event, optarg, MAXLEN); + break; + + case OPT_LIMIT: + runtime_options.limit = repmgr_atoi(optarg, "--limit", &cli_errors, false); + runtime_options.limit_provided = true; + break; + + case OPT_ALL: + runtime_options.all = true; + break; + + /* logging options * * --------------- */ /* -L/--log-level */ @@ -267,6 +297,8 @@ main(int argc, char **argv) check_cli_parameters(action); + // check runtime_options.node_id/node_name, if still set + /* * Sanity checks for command line parameters completed by now; * any further errors will be runtime ones @@ -462,7 +494,97 @@ check_cli_parameters(const int action) } } + /* + * --node-id + * + * NOTE: overrides --node-name, if present + */ + if (runtime_options.node_id != UNKNOWN_NODE_ID) + { + switch (action) + { + case STANDBY_UNREGISTER: + case WITNESS_UNREGISTER: + break; + default: + item_list_append_format(&cli_warnings, + _("--node-id not required when executing %s"), + action_name(action)); + runtime_options.node_id = UNKNOWN_NODE_ID; + } + } + if (runtime_options.node_name[0]) + { + switch (action) + { + case STANDBY_UNREGISTER: + case WITNESS_UNREGISTER: + if (runtime_options.node_id != UNKNOWN_NODE_ID) + { + item_list_append(&cli_warnings, + _("--node-id provided, ignoring --node-name")); + memset(runtime_options.node_name, 0, sizeof(runtime_options.node_name)); + } + break; + default: + item_list_append_format(&cli_warnings, + _("--node-name not required when executing %s"), + action_name(action)); + memset(runtime_options.node_name, 0, sizeof(runtime_options.node_name)); + } + } + + if (runtime_options.event[0]) + { + switch (action) + { + case CLUSTER_EVENT: + break; + default: + item_list_append_format(&cli_warnings, + _("--event not required when executing %s"), + action_name(action)); + } + } + + if (runtime_options.limit_provided) + { + switch (action) + { + case CLUSTER_EVENT: + if (runtime_options.limit < 1) + { + item_list_append_format(&cli_errors, + _("value for --limit must be 1 or greater (provided: %i)"), + runtime_options.limit); + } + break; + default: + item_list_append_format(&cli_warnings, + _("--limit not required when executing %s"), + action_name(action)); + } + } + + if (runtime_options.all) + { + switch (action) + { + case CLUSTER_EVENT: + if (runtime_options.limit_provided == true) + { + runtime_options.all = false; + item_list_append(&cli_warnings, + _("--limit provided, ignoring --all")); + } + break; + default: + item_list_append_format(&cli_warnings, + _("--all not required when executing %s"), + action_name(action)); + } + } } @@ -475,6 +597,12 @@ action_name(const int action) return "MASTER REGISTER"; case STANDBY_CLONE: return "STANDBY CLONE"; + case STANDBY_REGISTER: + return "STANDBY REGISTER"; + case STANDBY_UNREGISTER: + return "STANDBY UNREGISTER"; + case WITNESS_UNREGISTER: + return "WITNESS UNREGISTER"; case CLUSTER_EVENT: return "CLUSTER EVENT"; } diff --git a/repmgr-client.h b/repmgr-client.h index b32655e9..5aadc00b 100644 --- a/repmgr-client.h +++ b/repmgr-client.h @@ -51,14 +51,21 @@ #define OPT_PWPROMPT 7 #define OPT_CSV 8 #define OPT_NODE 9 -#define OPT_WITHOUT_BARMAN 10 -#define OPT_NO_UPSTREAM_CONNECTION 11 -#define OPT_REGISTER_WAIT 12 -#define OPT_CLUSTER 13 -#define OPT_LOG_TO_FILE 14 -#define OPT_UPSTREAM_CONNINFO 15 -#define OPT_NO_CONNINFO_PASSWORD 16 -#define OPT_REPLICATION_USER 17 +#define OPT_NODE_ID 10 +#define OPT_NODE_NAME 11 +#define OPT_WITHOUT_BARMAN 12 +#define OPT_NO_UPSTREAM_CONNECTION 13 +#define OPT_REGISTER_WAIT 14 +#define OPT_CLUSTER 15 +#define OPT_LOG_TO_FILE 16 +#define OPT_UPSTREAM_CONNINFO 17 +/* XXX deprecate, replace with --use-conninfo-password */ +#define OPT_NO_CONNINFO_PASSWORD 18 +#define OPT_REPLICATION_USER 19 +#define OPT_EVENT 20 +#define OPT_LIMIT 21 +#define OPT_ALL 22 + static struct option long_options[] = { @@ -83,6 +90,11 @@ static struct option long_options[] = {"terse", required_argument, NULL, 't'}, {"verbose", no_argument, NULL, 'v'}, +/* event options */ + {"event", required_argument, NULL, OPT_EVENT }, + {"limit", required_argument, NULL, OPT_LIMIT }, + {"all", no_argument, NULL, OPT_ALL }, + /* not yet handled */ {"dbname", required_argument, NULL, 'd'}, {"host", required_argument, NULL, 'h'}, @@ -122,6 +134,7 @@ typedef struct bool conninfo_provided; bool connection_param_provided; bool host_param_provided; + bool limit_provided; /* general configuration options */ char config_file[MAXPGPATH]; @@ -135,21 +148,34 @@ typedef struct bool verbose; /* connection options */ - char data_dir[MAXPGPATH]; char superuser[MAXLEN]; + /* node options */ + int node_id; + char node_name[MAXLEN]; + char data_dir[MAXPGPATH]; + + /* event options */ + char event[MAXLEN]; + int limit; + bool all; } t_runtime_options; #define T_RUNTIME_OPTIONS_INITIALIZER { \ /* configuration metadata */ \ - false, false, false, \ + false, false, false, false, \ /* general configuration options */ \ "", false, "", \ /* logging options */ \ "", false, false, false, \ /* connection options */ \ - "", ""} + "", \ + /* node options */ \ + UNKNOWN_NODE_ID, "", "", \ + /* event options */ \ + "", 20, false} + static void do_help(void); static void do_master_register(void);