diff --git a/CREDITS b/CREDITS index 86b8dea1..09b5d46e 100644 --- a/CREDITS +++ b/CREDITS @@ -8,3 +8,4 @@ Gabriele Bartolini Bas van Oostveen Hannu Krosing Cédric Villemain +Charles Duffy diff --git a/HISTORY b/HISTORY index 14a881d9..b7dd303b 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,4 @@ -1.0.0 2010-12-05 First public release +1.0.0 2010-12-05 First public release (Greg Smith) 1.0.1 2011-02-XX Fix missing "--force" option in help Correct warning message for wal_keep_segments (Bas van Oostveen) @@ -13,4 +13,6 @@ Avoid buffer overruns by using snprintf etc. (Gabriele) Fix use of database query after close (Gabriele) Add information about progress during "standby clone" (Gabriele) - + Fix double free error in repmgrd (Charles Duffy) + Make repmgr exit with an error code when encountering an error (Charles) + Standardize on error return codes, use in repmgrd too (Greg) diff --git a/README.rst b/README.rst index 6addf0b0..0cd9edb4 100644 --- a/README.rst +++ b/README.rst @@ -539,6 +539,23 @@ and the same in the standby. The repmgr daemon creates 2 connections: one to the master and another to the standby. +Error codes +----------- + +When the repmgr or repmgrd program exits, it will set one of the +following + +* SUCCESS 0: Program ran successfully. + +* ERR_BAD_CONFIG 1: One of the configuration checks the program makes failed. +* ERR_BAD_RSYNC 2: An rsync call made by the program returned an error. +* ERR_STOP_BACKUP 3: A ``pg_stop_backup()`` call made by the program didn't succeed. +* ERR_NO_RESTART 4: An attempt to restart a PostgreSQL instance failed. +* ERR_NEEDS_XLOG 5: Could note create the ``pg_xlog`` directory when cloning. +* ERR_DB_CON 6: Error when trying to connect to a database. +* ERR_DB_QUERY 7: Error executing a database query. +* ERR_PROMOTED 8: Exiting program because the node has been promoted to master. + Detailed walkthrough ==================== diff --git a/config.c b/config.c index 53113bb1..8e9b4c6f 100644 --- a/config.c +++ b/config.c @@ -30,7 +30,7 @@ parse_config(const char* config_file, t_configuration_options* options) if (fp == NULL) { fprintf(stderr, _("Could not find configuration file '%s'\n"), config_file); - exit(1); + exit(ERR_BAD_CONFIG); } /* Initialize */ @@ -75,14 +75,14 @@ parse_config(const char* config_file, t_configuration_options* options) { fprintf(stderr, "Cluster name is missing. " "Check the configuration file.\n"); - exit(1); + exit(ERR_BAD_CONFIG); } if (config->node == -1) { fprintf(stderr, "Node information is missing. " "Check the configuration file.\n"); - exit(1); + exit(ERR_BAD_CONFIG); } } diff --git a/dbutils.c b/dbutils.c index 38b8c05f..446062e1 100644 --- a/dbutils.c +++ b/dbutils.c @@ -36,7 +36,7 @@ establishDBConnection(const char *conninfo, const bool exit_on_error) if (exit_on_error) { PQfinish(conn); - exit(1); + exit(ERR_DB_CON); } } @@ -57,7 +57,7 @@ is_standby(PGconn *conn) fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - exit(1); + exit(ERR_NO_DB_CON); } if (strcmp(PQgetvalue(res, 0, 0), "f") == 0) @@ -89,7 +89,7 @@ pg_version(PGconn *conn, char* major_version) fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - exit(1); + exit(ERR_DB_QUERY); } major_version1 = atoi(PQgetvalue(res, 0, 0)); major_version2 = PQgetvalue(res, 0, 1); @@ -123,7 +123,7 @@ guc_setted(PGconn *conn, const char *parameter, const char *op, const char *valu fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - exit(1); + exit(ERR_DB_QUERY); } if (PQntuples(res) == 0) { @@ -152,7 +152,7 @@ get_cluster_size(PGconn *conn) fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - exit(1); + exit(ERR_DB_QUERY); } size = PQgetvalue(res, 0, 0); PQclear(res); @@ -184,7 +184,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id) fprintf(stderr, "Can't get nodes info: %s\n", PQerrorMessage(standby_conn)); PQclear(res1); PQfinish(standby_conn); - exit(1); + exit(ERR_DB_QUERY); } for (i = 0; i < PQntuples(res1); i++) diff --git a/repmgr.c b/repmgr.c index 196baef4..08bca365 100644 --- a/repmgr.c +++ b/repmgr.c @@ -101,12 +101,12 @@ main(int argc, char **argv) if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { help(progname); - exit(0); + exit(SUCCESS); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { printf("%s (PostgreSQL) " PG_VERSION "\n", progname); - exit(0); + exit(SUCCESS); } } @@ -149,7 +149,7 @@ main(int argc, char **argv) break; default: usage(); - exit(1); + exit(ERR_BAD_CONFIG); } } @@ -167,7 +167,7 @@ main(int argc, char **argv) if (strcasecmp(server_mode, "STANDBY") != 0 && strcasecmp(server_mode, "MASTER") != 0) { usage(); - exit(1); + exit(ERR_BAD_CONFIG); } } @@ -196,7 +196,7 @@ main(int argc, char **argv) else { usage(); - exit(1); + exit(ERR_BAD_CONFIG); } } @@ -209,7 +209,7 @@ main(int argc, char **argv) { log_err(_("Conflicting parameters you can't use -h while providing a node separately.\n")); usage(); - exit(1); + exit(ERR_BAD_CONFIG); } strncpy(runtime_options.host, argv[optind++], MAXLEN); } @@ -223,11 +223,11 @@ main(int argc, char **argv) log_err(_("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind + 1]); usage(); - exit(1); + exit(ERR_BAD_CONFIG); } if (!check_parameters_for_action(action)) - exit(1); + exit(ERR_BAD_CONFIG); if (!runtime_options.dbname[0]) { @@ -247,7 +247,7 @@ main(int argc, char **argv) { fprintf(stderr, "Node information is missing. " "Check the configuration file.\n"); - exit(1); + exit(ERR_BAD_CONFIG); } keywords[2] = "user"; @@ -276,7 +276,7 @@ main(int argc, char **argv) { log_err("Node information is missing. " "Check the configuration file.\n"); - exit(1); + exit(ERR_BAD_CONFIG); } } @@ -305,7 +305,7 @@ main(int argc, char **argv) break; default: usage(); - exit(1); + exit(ERR_BAD_CONFIG); } logger_shutdown(); @@ -339,7 +339,7 @@ do_master_register(void) { log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } /* Check if there is a schema for this cluster */ @@ -351,7 +351,7 @@ do_master_register(void) log_err(_("Can't get info about schemas: %s\n"), PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } if (PQntuples(res) > 0) /* schema exists */ @@ -361,7 +361,7 @@ do_master_register(void) log_notice(_("Schema %s already exists.\n"), repmgr_schema); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } schema_exists = true; } @@ -379,7 +379,7 @@ do_master_register(void) log_err(_("Cannot create the schema %s: %s\n"), repmgr_schema, PQerrorMessage(conn)); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } /* ... the tables */ @@ -393,7 +393,7 @@ do_master_register(void) log_err(_("Cannot create the table %s.repl_nodes: %s\n"), repmgr_schema, PQerrorMessage(conn)); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } snprintf(sqlquery, QUERY_STR_LEN, "CREATE TABLE %s.repl_monitor ( " @@ -410,7 +410,7 @@ do_master_register(void) log_err(_("Cannot create the table %s.repl_monitor: %s\n"), repmgr_schema, PQerrorMessage(conn)); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } /* and the view */ @@ -429,7 +429,7 @@ do_master_register(void) log_err(_("Cannot create the view %s.repl_status: %s\n"), repmgr_schema, PQerrorMessage(conn)); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } } else @@ -443,7 +443,7 @@ do_master_register(void) { PQfinish(master_conn); log_warning(_("There is a master already in cluster %s\n"), options.cluster_name); - return; + exit(ERR_BAD_CONFIG); } } @@ -460,7 +460,7 @@ do_master_register(void) log_warning(_("Cannot delete node details, %s\n"), PQerrorMessage(conn)); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } } @@ -474,7 +474,7 @@ do_master_register(void) log_warning(_("Cannot insert node details, %s\n"), PQerrorMessage(conn)); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } PQfinish(conn); @@ -505,7 +505,7 @@ do_standby_register(void) { PQfinish(conn); log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname); - return; + exit(ERR_BAD_CONFIG); } /* Check we are a standby */ @@ -513,7 +513,7 @@ do_standby_register(void) { log_err(_("repmgr: This node should be a standby (%s)\n"), options.conninfo); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } /* Check if there is a schema for this cluster */ @@ -525,23 +525,23 @@ do_standby_register(void) log_err("Can't get info about tablespaces: %s\n", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } - if (PQntuples(res) == 0) /* schema doesn't exists */ + if (PQntuples(res) == 0) /* schema doesn't exist */ { log_err("Schema %s doesn't exists.\n", repmgr_schema); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } PQclear(res); /* check if there is a master in this cluster */ master_conn = getMasterConnection(conn, options.node, options.cluster_name, &master_id); if (!master_conn) { - log_err(_("Cannot retrieve information about the connection to the master\n")); - return; + log_err(_("A master must be defined before configuring a slave\n")); + exit(ERR_BAD_CONFIG); } /* master should be v9 or better */ @@ -551,7 +551,7 @@ do_standby_register(void) PQfinish(conn); PQfinish(master_conn); log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname); - return; + exit(ERR_BAD_CONFIG); } /* master and standby version should match */ @@ -561,7 +561,7 @@ do_standby_register(void) PQfinish(master_conn); log_err(_("%s needs versions of both master (%s) and standby (%s) to match.\n"), progname, master_version, standby_version); - return; + exit(ERR_BAD_CONFIG); } @@ -579,7 +579,7 @@ do_standby_register(void) PQerrorMessage(master_conn)); PQfinish(master_conn); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } } @@ -594,7 +594,7 @@ do_standby_register(void) PQerrorMessage(master_conn)); PQfinish(master_conn); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } PQfinish(master_conn); @@ -645,7 +645,7 @@ do_standby_clone(void) { log_err(_("%s: couldn't create directory %s ...\n"), progname, runtime_options.dest_dir); - return; + exit(ERR_BAD_CONFIG); } break; case 1: @@ -658,7 +658,7 @@ do_standby_clone(void) { log_err(_("%s: could not change permissions of directory \"%s\": %s\n"), progname, runtime_options.dest_dir, strerror(errno)); - return; + exit(ERR_BAD_CONFIG); } break; case 2: @@ -673,7 +673,7 @@ do_standby_clone(void) "If you are sure you want to clone here, " "please check there is no PostgreSQL server " "running and use the --force option\n")); - return; + exit(ERR_BAD_CONFIG); } else if (pg_dir && runtime_options.force) { @@ -686,6 +686,7 @@ do_standby_clone(void) /* Trouble accessing directory */ log_err( _("%s: could not access directory \"%s\": %s\n"), progname, runtime_options.dest_dir, strerror(errno)); + exit(ERR_BAD_CONFIG); } /* Connection parameters for master only */ @@ -700,7 +701,7 @@ do_standby_clone(void) { log_err(_("%s: could not connect to master\n"), progname); - return; + exit(ERR_BAD_CONFIG); } /* primary should be v9 or better */ @@ -709,7 +710,7 @@ do_standby_clone(void) { PQfinish(conn); log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname); - return; + exit(ERR_BAD_CONFIG); } /* Check we are cloning a primary node */ @@ -717,7 +718,7 @@ do_standby_clone(void) { PQfinish(conn); log_err(_("\nThe command should clone a primary node\n")); - return; + exit(ERR_BAD_CONFIG); } /* And check if it is well configured */ @@ -725,19 +726,19 @@ do_standby_clone(void) { PQfinish(conn); log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname); - return; + exit(ERR_BAD_CONFIG); } if (!guc_setted(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments)) { PQfinish(conn); log_err(_("%s needs parameter 'wal_keep_segments' to be set to %s or greater (see the '-w' option)\n"), progname, runtime_options.wal_keep_segments); - return; + exit(ERR_BAD_CONFIG); } if (!guc_setted(conn, "archive_mode", "=", "on")) { PQfinish(conn); log_err(_("%s needs parameter 'archive_mode' to be set to 'on'\n"), progname); - return; + exit(ERR_BAD_CONFIG); } log_info(_("Succesfully connected to primary. Current installation size is %s\n"), get_cluster_size(conn)); @@ -752,7 +753,7 @@ do_standby_clone(void) log_err("Can't get info about tablespaces: %s\n", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } for (i = 0; i < PQntuples(res); i++) { @@ -772,7 +773,7 @@ do_standby_clone(void) progname, tblspc_dir); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } break; case 1: @@ -788,7 +789,7 @@ do_standby_clone(void) progname, tblspc_dir, strerror(errno)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } break; case 2: @@ -800,7 +801,7 @@ do_standby_clone(void) progname, tblspc_dir); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } default: /* Trouble accessing directory */ @@ -808,7 +809,7 @@ do_standby_clone(void) progname, tblspc_dir, strerror(errno)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } } @@ -825,7 +826,7 @@ do_standby_clone(void) log_err("Can't get info about data directory and configuration files: %s\n", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } for (i = 0; i < PQntuples(res); i++) { @@ -855,7 +856,7 @@ do_standby_clone(void) log_err("Can't start backup: %s\n", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } first_wal_segment = PQgetvalue(res, 0, 0); PQclear(res); @@ -949,7 +950,7 @@ stop_backup: { log_err(_("%s: could not connect to master\n"), progname); - return; + exit(ERR_BAD_RSYNC); } log_notice("Finishing backup...\n"); @@ -963,36 +964,39 @@ stop_backup: log_err("Can't stop backup: %s\n", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_STOP_BACKUP); } last_wal_segment = PQgetvalue(res, 0, 0); - /* Now, if the rsync failed then exit */ - if (r == 0) - { + /* If the rsync failed then exit */ + if (r != 0) + exit(ERR_BAD_RSYNC); if (runtime_options.verbose) printf(_("%s requires primary to keep WAL files %s until at least %s\n"), progname, first_wal_segment, last_wal_segment); - /* we need to create the pg_xlog sub directory too, i'm reusing a variable here */ - snprintf(local_control_file, MAXFILENAME, "%s/pg_xlog", runtime_options.dest_dir); - if (!create_directory(local_control_file)) - { - log_err(_("%s: couldn't create directory %s, you will need to do it manually...\n"), - progname, runtime_options.dest_dir); - } - - /* Finally, write the recovery.conf file */ - create_recovery_file(runtime_options.dest_dir); - + /* we need to create the pg_xlog sub directory too, i'm reusing a variable here */ + snprintf(local_control_file, MAXFILENAME, "%s/pg_xlog", runtime_options.dest_dir); + if (!create_directory(local_control_file)) + { + log_err(_("%s: couldn't create directory %s, you will need to do it manually...\n"), + progname, runtime_options.dest_dir); + r = ERR_NEEDS_XLOG; /* continue, but eventually exit returning error */ } + /* Finally, write the recovery.conf file */ + create_recovery_file(runtime_options.dest_dir); + PQclear(res); PQfinish(conn); - /* We don't start the service because we still may want to move the directory */ - return; + /* + * We don't start the service yet because we still may want to + * move the directory + */ + + exit(r); } @@ -1023,14 +1027,14 @@ do_standby_promote(void) { PQfinish(conn); log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname); - return; + exit(ERR_BAD_CONFIG); } /* Check we are in a standby node */ if (!is_standby(conn)) { log_err("repmgr: The command should be executed on a standby node\n"); - return; + exit(ERR_BAD_CONFIG); } /* we also need to check if there isn't any master already */ @@ -1039,7 +1043,7 @@ do_standby_promote(void) { PQfinish(old_master_conn); log_err("There is a master already in this cluster\n"); - return; + exit(ERR_BAD_CONFIG); } if (runtime_options.verbose) @@ -1055,7 +1059,7 @@ do_standby_promote(void) log_err("Can't get info about data directory: %s\n", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } strcpy(data_dir, PQgetvalue(res, 0, 0)); PQclear(res); @@ -1065,26 +1069,27 @@ do_standby_promote(void) snprintf(recovery_done_path, MAXFILENAME, "%s/%s", data_dir, RECOVERY_DONE_FILE); rename(recovery_file_path, recovery_done_path); - /* We assume the pg_ctl script is in the PATH */ - snprintf(script, QUERY_STR_LEN, "pg_ctl -D %s -m fast restart", data_dir); + /* + * We assume the pg_ctl script is in the PATH. Restart and wait for + * the server to finish starting, so that the check below will + * find an active server rather than one starting up. This may + * hang for up the default timeout (60 seconds). + */ + snprintf(script, QUERY_STR_LEN, "pg_ctl -D %s -w -m fast restart", data_dir); r = system(script); if (r != 0) { - log_err("Can't restart service\n"); - return; + log_err("Can't restart PostgreSQL server\n"); + exit(ERR_NO_RESTART); } /* reconnect to check we got promoted */ - /* - * XXX i'm removing this because it gives an annoying message saying couldn't connect - * but is just the server starting up - * conn = establishDBConnection(options.conninfo, true); - * if (is_standby(conn)) - * log_err("\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname); - * else - * log_err("\n%s: you should REINDEX any hash indexes you have.\n", progname); - * PQfinish(conn); - */ + conn = establishDBConnection(options.conninfo, true); + if (is_standby(conn)) + log_err("\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname); + else + log_err("\n%s: you should REINDEX any hash indexes you have.\n", progname); + PQfinish(conn); return; } @@ -1115,6 +1120,7 @@ do_standby_follow(void) { log_err("\n%s: The command should be executed in a standby node\n", progname); return; + exit(ERR_BAD_CONFIG); } /* should be v9 or better */ @@ -1123,7 +1129,7 @@ do_standby_follow(void) { PQfinish(conn); log_err(_("\n%s needs standby to be PostgreSQL 9.0 or better\n"), progname); - return; + exit(ERR_BAD_CONFIG); } /* we also need to check if there is any master in the cluster */ @@ -1132,7 +1138,7 @@ do_standby_follow(void) { PQfinish(conn); log_err("There isn't a master to follow in this cluster\n"); - return; + exit(ERR_BAD_CONFIG); } /* Check we are going to point to a master */ @@ -1140,7 +1146,7 @@ do_standby_follow(void) { PQfinish(conn); log_err("%s: The node to follow should be a master\n", progname); - return; + exit(ERR_BAD_CONFIG); } /* should be v9 or better */ @@ -1150,7 +1156,7 @@ do_standby_follow(void) PQfinish(conn); PQfinish(master_conn); log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname); - return; + exit(ERR_BAD_CONFIG); } /* master and standby version should match */ @@ -1160,7 +1166,7 @@ do_standby_follow(void) PQfinish(master_conn); log_err(_("%s needs versions of both master (%s) and standby (%s) to match.\n"), progname, master_version, standby_version); - return; + exit(ERR_BAD_CONFIG); } /* @@ -1185,7 +1191,7 @@ do_standby_follow(void) log_err("Can't get info about data directory: %s\n", PQerrorMessage(conn)); PQclear(res); PQfinish(conn); - return; + exit(ERR_BAD_CONFIG); } strcpy(data_dir, PQgetvalue(res, 0, 0)); PQclear(res); @@ -1193,7 +1199,7 @@ do_standby_follow(void) /* write the recovery.conf file */ if (!create_recovery_file(data_dir)) - return; + exit(ERR_BAD_CONFIG); /* Finally, restart the service */ /* We assume the pg_ctl script is in the PATH */ @@ -1203,6 +1209,7 @@ do_standby_follow(void) { log_err("Can't restart service\n"); return; + exit(ERR_NO_RESTART); } return; diff --git a/repmgr.h b/repmgr.h index 3d87a91d..a8455e80 100644 --- a/repmgr.h +++ b/repmgr.h @@ -45,6 +45,18 @@ #define DEFAULT_DBNAME "postgres" #define DEFAULT_REPMGR_SCHEMA_PREFIX "repmgr_" +/* Exit return code */ + +#define SUCCESS 0 +#define ERR_BAD_CONFIG 1 +#define ERR_BAD_RSYNC 2 +#define ERR_STOP_BACKUP 3 +#define ERR_NO_RESTART 4 +#define ERR_NEEDS_XLOG 5 +#define ERR_DB_CON 6 +#define ERR_DB_QUERY 7 +#define ERR_PROMOTED 8 + /* Run time options type */ typedef struct { diff --git a/repmgrd.c b/repmgrd.c index 3f5ec96c..c883821e 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -107,12 +107,12 @@ main(int argc, char **argv) if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { help(progname); - exit(0); + exit(SUCCESS); } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { printf("%s (PostgreSQL) " PG_VERSION "\n", progname); - exit(0); + exit(SUCCESS); } } @@ -129,7 +129,7 @@ main(int argc, char **argv) break; default: usage(); - exit(1); + exit(ERR_BAD_CONFIG); } } @@ -143,7 +143,7 @@ main(int argc, char **argv) { log_err("Node information is missing. " "Check the configuration file.\n"); - exit(1); + exit(ERR_BAD_CONFIG); } logger_init(progname, local_options.loglevel, local_options.logfacility); snprintf(repmgr_schema, MAXLEN, "%s%s", DEFAULT_REPMGR_SCHEMA_PREFIX, local_options.cluster_name); @@ -156,7 +156,7 @@ main(int argc, char **argv) { PQfinish(myLocalConn); log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname); - exit(1); + exit(ERR_BAD_CONFIG); } /* @@ -175,7 +175,7 @@ main(int argc, char **argv) /* I need the id of the primary as well as a connection to it */ primaryConn = getMasterConnection(myLocalConn, local_options.node, local_options.cluster_name, &primary_options.node); if (primaryConn == NULL) - exit(1); + exit(ERR_BAD_CONFIG); } checkClusterConfiguration(); @@ -258,7 +258,7 @@ MonitorExecute(void) if (PQstatus(primaryConn) != CONNECTION_OK) { log_err(_("We couldn't reconnect for long enough, exiting...")); - exit(1); + exit(ERR_DB_CON); } /* Check if we still are a standby, we could have been promoted */ @@ -266,7 +266,7 @@ MonitorExecute(void) { log_err(_("It seems like we have been promoted, so exit from monitoring...")); CloseConnections(); - exit(1); + exit(ERR_PROMOTED); } /* @@ -354,7 +354,7 @@ checkClusterConfiguration(void) PQclear(res); PQfinish(myLocalConn); PQfinish(primaryConn); - exit(1); + exit(ERR_DB_QUERY); } /* @@ -368,7 +368,7 @@ checkClusterConfiguration(void) PQclear(res); PQfinish(myLocalConn); PQfinish(primaryConn); - exit(1); + exit(ERR_BAD_CONFIG); } PQclear(res); } @@ -393,7 +393,7 @@ checkNodeConfiguration(char *conninfo) PQclear(res); PQfinish(myLocalConn); PQfinish(primaryConn); - exit(1); + exit(ERR_BAD_CONFIG); } /* @@ -414,7 +414,7 @@ checkNodeConfiguration(char *conninfo) PQerrorMessage(primaryConn)); PQfinish(myLocalConn); PQfinish(primaryConn); - exit(1); + exit(ERR_BAD_CONFIG); } } PQclear(res);