mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Add placeholder functions for "repmgr $command --help"
There are now too many options to sensibly fit into general --help output; we'll add separate output for each repmgr command, e.g. "repmgr node --help".
This commit is contained in:
@@ -414,3 +414,12 @@ do_bdr_unregister(void)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
do_bdr_help(void)
|
||||
{
|
||||
print_help_header();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,5 +9,7 @@
|
||||
extern void do_bdr_register(void);
|
||||
extern void do_bdr_unregister(void);
|
||||
|
||||
extern void do_bdr_help(void);
|
||||
|
||||
|
||||
#endif /* _REPMGR_ACTION_BDR_H_ */
|
||||
|
||||
@@ -1083,3 +1083,12 @@ cube_set_node_status(t_node_status_cube **cube, int n, int execute_node_id, int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
do_cluster_help(void)
|
||||
{
|
||||
print_help_header();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -35,5 +35,6 @@ extern void do_cluster_event(void);
|
||||
extern void do_cluster_crosscheck(void);
|
||||
extern void do_cluster_matrix(void);
|
||||
|
||||
extern void do_cluster_help(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1249,11 +1249,7 @@ do_node_check_downstream(PGconn *conn, OutputMode mode, CheckStatusList *list_ou
|
||||
return status;
|
||||
}
|
||||
|
||||
// --action=...
|
||||
// --check
|
||||
// --list -> list what would be executed for each action, filter to --action
|
||||
|
||||
// --checkpoint must be run as superuser - check connection
|
||||
void
|
||||
do_node_service(void)
|
||||
{
|
||||
@@ -1967,3 +1963,12 @@ copy_file(const char *src_file, const char *dest_file)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
do_node_help(void)
|
||||
{
|
||||
print_help_header();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@ extern void do_node_check(void);
|
||||
extern void do_node_rejoin(void);
|
||||
extern void do_node_service(void);
|
||||
|
||||
|
||||
extern void do_node_help(void);
|
||||
|
||||
#endif /* _REPMGR_ACTION_NODE_H_ */
|
||||
|
||||
@@ -489,3 +489,13 @@ do_primary_unregister(void)
|
||||
PQfinish(primary_conn);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
do_primary_help(void)
|
||||
{
|
||||
print_help_header();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,4 +9,5 @@
|
||||
extern void do_primary_register(void);
|
||||
extern void do_primary_unregister(void);
|
||||
|
||||
extern void do_primary_help(void);
|
||||
#endif
|
||||
|
||||
@@ -4065,3 +4065,12 @@ parse_node_check_replication_lag(const char *node_check_output, int *seconds, in
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
do_standby_help(void)
|
||||
{
|
||||
print_help_header();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ extern void do_standby_promote(void);
|
||||
extern void do_standby_follow(void);
|
||||
extern void do_standby_switchover(void);
|
||||
|
||||
extern void do_standby_help(void);
|
||||
|
||||
extern bool do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_record, PQExpBufferData *output);
|
||||
|
||||
|
||||
|
||||
@@ -197,6 +197,7 @@ extern void get_superuser_connection(PGconn **conn, PGconn **superuser_conn, PGc
|
||||
extern bool remote_command(const char *host, const char *user, const char *command, PQExpBufferData *outputbuf);
|
||||
|
||||
extern void make_remote_repmgr_path(PQExpBufferData *outputbuf, t_node_info *remote_node_record);
|
||||
extern void print_help_header(void);
|
||||
|
||||
/* server control functions */
|
||||
extern void get_server_action(t_server_action action, char *script, char *data_dir);
|
||||
|
||||
105
repmgr-client.c
105
repmgr-client.c
@@ -84,12 +84,14 @@ main(int argc, char **argv)
|
||||
int optindex;
|
||||
int c;
|
||||
|
||||
char *repmgr_node_type = NULL;
|
||||
char *repmgr_command = NULL;
|
||||
char *repmgr_action = NULL;
|
||||
bool valid_repmgr_node_type_found = true;
|
||||
bool valid_repmgr_command_found = true;
|
||||
int action = NO_ACTION;
|
||||
char *dummy_action = "";
|
||||
|
||||
bool help_option = false;
|
||||
|
||||
set_progname(argv[0]);
|
||||
|
||||
/*
|
||||
@@ -173,8 +175,10 @@ main(int argc, char **argv)
|
||||
* these are the only ones which can be executed as root user
|
||||
*/
|
||||
case OPT_HELP: /* --help */
|
||||
do_help();
|
||||
exit(SUCCESS);
|
||||
help_option = true;
|
||||
break;
|
||||
//do_help();
|
||||
//exit(SUCCESS);
|
||||
case '?':
|
||||
/* Actual help option given */
|
||||
if (strcmp(argv[optind - 1], "-?") == 0)
|
||||
@@ -646,7 +650,7 @@ main(int argc, char **argv)
|
||||
* We check this here to give the root user a chance to execute --help/--version
|
||||
* options.
|
||||
*/
|
||||
if (geteuid() == 0)
|
||||
if (geteuid() == 0 && help_option == false)
|
||||
{
|
||||
fprintf(stderr,
|
||||
_("%s: cannot be run as root\n"
|
||||
@@ -679,7 +683,7 @@ main(int argc, char **argv)
|
||||
*/
|
||||
if (optind < argc)
|
||||
{
|
||||
repmgr_node_type = argv[optind++];
|
||||
repmgr_command = argv[optind++];
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
@@ -691,11 +695,17 @@ main(int argc, char **argv)
|
||||
repmgr_action = dummy_action;
|
||||
}
|
||||
|
||||
if (repmgr_node_type != NULL)
|
||||
if (repmgr_command != NULL)
|
||||
{
|
||||
#ifndef BDR_ONLY
|
||||
if (strcasecmp(repmgr_node_type, "PRIMARY") == 0 || strcasecmp(repmgr_node_type, "MASTER") == 0 )
|
||||
if (strcasecmp(repmgr_command, "PRIMARY") == 0 || strcasecmp(repmgr_command, "MASTER") == 0 )
|
||||
{
|
||||
if (help_option == true)
|
||||
{
|
||||
do_primary_help();
|
||||
exit(SUCCESS);
|
||||
}
|
||||
|
||||
if (strcasecmp(repmgr_action, "REGISTER") == 0)
|
||||
action = PRIMARY_REGISTER;
|
||||
else if (strcasecmp(repmgr_action, "UNREGISTER") == 0)
|
||||
@@ -706,8 +716,14 @@ main(int argc, char **argv)
|
||||
action = NODE_STATUS;
|
||||
}
|
||||
|
||||
else if (strcasecmp(repmgr_node_type, "STANDBY") == 0)
|
||||
else if (strcasecmp(repmgr_command, "STANDBY") == 0)
|
||||
{
|
||||
if (help_option == true)
|
||||
{
|
||||
do_standby_help();
|
||||
exit(SUCCESS);
|
||||
}
|
||||
|
||||
if (strcasecmp(repmgr_action, "CLONE") == 0)
|
||||
action = STANDBY_CLONE;
|
||||
else if (strcasecmp(repmgr_action, "REGISTER") == 0)
|
||||
@@ -725,11 +741,17 @@ main(int argc, char **argv)
|
||||
else if (strcasecmp(repmgr_action, "STATUS") == 0)
|
||||
action = NODE_STATUS;
|
||||
}
|
||||
else if (strcasecmp(repmgr_node_type, "BDR") == 0)
|
||||
else if (strcasecmp(repmgr_command, "BDR") == 0)
|
||||
#else
|
||||
if (strcasecmp(repmgr_node_type, "BDR") == 0)
|
||||
if (strcasecmp(repmgr_command, "BDR") == 0)
|
||||
#endif
|
||||
{
|
||||
if (help_option == true)
|
||||
{
|
||||
do_bdr_help();
|
||||
exit(SUCCESS);
|
||||
}
|
||||
|
||||
if (strcasecmp(repmgr_action, "REGISTER") == 0)
|
||||
action = BDR_REGISTER;
|
||||
else if (strcasecmp(repmgr_action, "UNREGISTER") == 0)
|
||||
@@ -740,8 +762,14 @@ main(int argc, char **argv)
|
||||
action = NODE_STATUS;
|
||||
}
|
||||
|
||||
else if (strcasecmp(repmgr_node_type, "NODE") == 0)
|
||||
else if (strcasecmp(repmgr_command, "NODE") == 0)
|
||||
{
|
||||
if (help_option == true)
|
||||
{
|
||||
do_node_help();
|
||||
exit(SUCCESS);
|
||||
}
|
||||
|
||||
if (strcasecmp(repmgr_action, "CHECK") == 0)
|
||||
action = NODE_CHECK;
|
||||
else if (strcasecmp(repmgr_action, "STATUS") == 0)
|
||||
@@ -752,8 +780,13 @@ main(int argc, char **argv)
|
||||
action = NODE_SERVICE;
|
||||
}
|
||||
|
||||
else if (strcasecmp(repmgr_node_type, "CLUSTER") == 0)
|
||||
else if (strcasecmp(repmgr_command, "CLUSTER") == 0)
|
||||
{
|
||||
if (help_option == true)
|
||||
{
|
||||
do_cluster_help();
|
||||
exit(SUCCESS);
|
||||
}
|
||||
|
||||
if (strcasecmp(repmgr_action, "SHOW") == 0)
|
||||
action = CLUSTER_SHOW;
|
||||
@@ -769,37 +802,43 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
valid_repmgr_node_type_found = false;
|
||||
valid_repmgr_command_found = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (help_option == true)
|
||||
{
|
||||
do_help();
|
||||
exit(SUCCESS);
|
||||
}
|
||||
|
||||
if (action == NO_ACTION)
|
||||
{
|
||||
PQExpBufferData command_error;
|
||||
initPQExpBuffer(&command_error);
|
||||
|
||||
if (repmgr_node_type == NULL)
|
||||
if (repmgr_command == NULL)
|
||||
{
|
||||
appendPQExpBuffer(&command_error,
|
||||
_("no repmgr command provided"));
|
||||
}
|
||||
else if (valid_repmgr_node_type_found == false && repmgr_action[0] == '\0')
|
||||
else if (valid_repmgr_command_found == false && repmgr_action[0] == '\0')
|
||||
{
|
||||
appendPQExpBuffer(&command_error,
|
||||
_("unknown repmgr node type '%s'"),
|
||||
repmgr_node_type);
|
||||
_("unknown repmgr command '%s'"),
|
||||
repmgr_command);
|
||||
}
|
||||
else if (repmgr_action[0] == '\0')
|
||||
{
|
||||
appendPQExpBuffer(&command_error,
|
||||
_("no action provided for node type '%s'"),
|
||||
repmgr_node_type);
|
||||
_("no action provided for command '%s'"),
|
||||
repmgr_command);
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBuffer(&command_error,
|
||||
_("unknown repmgr action '%s %s'"),
|
||||
repmgr_node_type,
|
||||
repmgr_command,
|
||||
repmgr_action);
|
||||
}
|
||||
|
||||
@@ -1565,8 +1604,8 @@ print_error_list(ItemList *error_list, int log_level)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_help(void)
|
||||
void
|
||||
print_help_header(void)
|
||||
{
|
||||
printf(_("%s: replication management tool for PostgreSQL\n"), progname());
|
||||
puts("");
|
||||
@@ -1579,15 +1618,25 @@ do_help(void)
|
||||
printf(_(" **************************************************\n"));
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_help(void)
|
||||
{
|
||||
print_help_header();
|
||||
|
||||
printf(_("Usage:\n"));
|
||||
#ifndef BDR_ONLY
|
||||
printf(_(" %s [OPTIONS] primary {register|unregister}\n"), progname());
|
||||
printf(_(" %s [OPTIONS] standby {register|unregister|clone|promote|follow}\n"), progname());
|
||||
printf(_(" %s [OPTIONS] primary {register|unregister}\n"), progname());
|
||||
printf(_(" %s [OPTIONS] standby {register|unregister|clone|promote|follow}\n"), progname());
|
||||
#endif
|
||||
printf(_(" %s [OPTIONS] bdr {register|unregister}\n"), progname());
|
||||
printf(_(" %s [OPTIONS] node status\n"), progname());
|
||||
printf(_(" %s [OPTIONS] cluster {show|event|matrix|crosscheck}\n"), progname());
|
||||
printf(_(" %s [OPTIONS] bdr {register|unregister}\n"), progname());
|
||||
printf(_(" %s [OPTIONS] node status\n"), progname());
|
||||
printf(_(" %s [OPTIONS] cluster {show|event|matrix|crosscheck}\n"), progname());
|
||||
|
||||
puts("");
|
||||
|
||||
printf(_(" Execute \"%s {primary|standby|bdr|node|cluster} --help\" to see command-specific options\n"), progname());
|
||||
|
||||
puts("");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user