repmgrd: daemonize process by default

It's hard to imagine a use case where this isn't desirable, but
in case, for whatever reason, the user does not wish to daemonize the
process, the command line option "--daemonize=false" can be provided.

Implements GitHub #458.
This commit is contained in:
Ian Barwick
2018-06-29 22:01:49 +09:00
parent d00c0c67d0
commit 802755fd60
6 changed files with 26 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
4.1.0 2018-??-?? 4.1.0 2018-??-??
repmgr: add "--missing-slots" check to "repmgr node check" (Ian) repmgr: add "--missing-slots" check to "repmgr node check" (Ian)
repmgrd: create a PID file by default; GitHub #457 (Ian) repmgrd: create a PID file by default; GitHub #457 (Ian)
repmgrd: daemonize process by default; GitHub #458 (Ian)
4.0.6 2018-06-14 4.0.6 2018-06-14
repmgr: (witness register) prevent registration of a witness server with the repmgr: (witness register) prevent registration of a witness server with the

View File

@@ -29,9 +29,6 @@ static bool config_file_provided = false;
bool config_file_found = false; bool config_file_found = false;
static void _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *warning_list); static void _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *warning_list);
static bool parse_bool(const char *s,
const char *config_item,
ItemList *error_list);
static void _parse_line(char *buf, char *name, char *value); static void _parse_line(char *buf, char *name, char *value);
static void parse_event_notifications_list(t_configuration_options *options, const char *arg); static void parse_event_notifications_list(t_configuration_options *options, const char *arg);
@@ -1481,7 +1478,7 @@ repmgr_atoi(const char *value, const char *config_item, ItemList *error_list, in
* *
* https://www.postgresql.org/docs/current/static/config-setting.html * https://www.postgresql.org/docs/current/static/config-setting.html
*/ */
static bool bool
parse_bool(const char *s, const char *config_item, ItemList *error_list) parse_bool(const char *s, const char *config_item, ItemList *error_list)
{ {
PQExpBufferData errors; PQExpBufferData errors;

View File

@@ -283,6 +283,10 @@ bool reload_config(t_configuration_options *orig_options);
bool parse_recovery_conf(const char *data_dir, t_recovery_conf *conf); bool parse_recovery_conf(const char *data_dir, t_recovery_conf *conf);
bool parse_bool(const char *s,
const char *config_item,
ItemList *error_list);
int repmgr_atoi(const char *s, int repmgr_atoi(const char *s,
const char *config_item, const char *config_item,
ItemList *error_list, ItemList *error_list,

View File

@@ -37,6 +37,7 @@
<title>repmgrd enhancements</title> <title>repmgrd enhancements</title>
<para> <para>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para> <para>
<application>repmgrd</application>: create a PID file by default <application>repmgrd</application>: create a PID file by default
@@ -44,6 +45,16 @@
</para> </para>
</listitem> </listitem>
<listitem>
<para>
<application>repmgrd</application>: daemonize process by default.
In case, for whatever reason, the user does not wish to daemonize the
process, provice <option>--daemonize=false</option>.
(GitHub #458).
</para>
</listitem>
</itemizedlist> </itemizedlist>
</para> </para>
</sect2> </sect2>

View File

@@ -159,7 +159,7 @@
<para> <para>
<application>repmgrd</application> can be started manually like this: <application>repmgrd</application> can be started manually like this:
<programlisting> <programlisting>
repmgrd -f /etc/repmgr.conf --pid-file /tmp/repmgrd.pid --daemonize</programlisting> repmgrd -f /etc/repmgr.conf --pid-file /tmp/repmgrd.pid</programlisting>
and stopped with <command>kill `cat /tmp/repmgrd.pid`</command>. Adjust paths as appropriate. and stopped with <command>kill `cat /tmp/repmgrd.pid`</command>. Adjust paths as appropriate.
</para> </para>
<para> <para>

View File

@@ -36,7 +36,7 @@
static char *config_file = NULL; static char *config_file = NULL;
static bool verbose = false; static bool verbose = false;
static char pid_file[MAXPGPATH]; static char pid_file[MAXPGPATH];
static bool daemonize = false; static bool daemonize = true;
static bool show_pid_file = false; static bool show_pid_file = false;
static bool no_pid_file = false; static bool no_pid_file = false;
@@ -101,7 +101,7 @@ main(int argc, char **argv)
{"config-file", required_argument, NULL, 'f'}, {"config-file", required_argument, NULL, 'f'},
/* daemon options */ /* daemon options */
{"daemonize", no_argument, NULL, 'd'}, {"daemonize", optional_argument, NULL, 'd'},
{"pid-file", required_argument, NULL, 'p'}, {"pid-file", required_argument, NULL, 'p'},
{"show-pid-file", no_argument, NULL, 's'}, {"show-pid-file", no_argument, NULL, 's'},
{"no-pid-file", no_argument, NULL, OPT_NO_PID_FILE}, {"no-pid-file", no_argument, NULL, OPT_NO_PID_FILE},
@@ -175,7 +175,10 @@ main(int argc, char **argv)
/* daemon options */ /* daemon options */
case 'd': case 'd':
daemonize = true; if (optarg != NULL)
{
daemonize = parse_bool(optarg, "-d/--daemonize", &cli_errors);
}
break; break;
case 'p': case 'p':
@@ -747,7 +750,8 @@ show_help(void)
puts(""); puts("");
printf(_("Daemon configuration options:\n")); printf(_("Daemon configuration options:\n"));
printf(_(" -d, --daemonize detach process from foreground\n")); printf(_(" -d, --daemonize[=true/false]\n"));
printf(_(" detach process from foreground (default: true)\n"));
printf(_(" -p, --pid-file=PATH use the specified PID file\n")); printf(_(" -p, --pid-file=PATH use the specified PID file\n"));
printf(_(" -s, --show-pid-file show PID file which would be used by the current configuration\n")); printf(_(" -s, --show-pid-file show PID file which would be used by the current configuration\n"));
printf(_(" --no-pid-file don't write a PID file\n")); printf(_(" --no-pid-file don't write a PID file\n"));