From 0d40ebf10b1794ece2c5c9768ea7222d3834d3b3 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 13 May 2021 11:42:18 -0400 Subject: [PATCH 1/4] Build: Use a different variable to find man page includes. With other programs outside of the tools directory being converted to use glib for command line handling, their includes are not going to be in tools/. So we need to use a different autoconf variable to find them. --- mk/common.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mk/common.mk b/mk/common.mk index b247670..aa59feb 100644 --- a/mk/common.mk +++ b/mk/common.mk @@ -1,5 +1,5 @@ # -# Copyright 2014-2020 the Pacemaker project contributors +# Copyright 2014-2021 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -68,11 +68,11 @@ HELP2MAN_ARGS = -N --section 8 --name "Part of the Pacemaker cluster resource ma # and all wrappers to C code. %.8: % $(MAN8DEPS) $(AM_V_at)chmod a+x $(abs_builddir)/$< - $(AM_V_MAN)if [ -f $(top_srcdir)/tools/$@.inc ]; then \ + $(AM_V_MAN)if [ -f $(abs_srcdir)/$@.inc ]; then \ PATH=$(abs_builddir):$$PATH $(HELP2MAN) $(HELP2MAN_ARGS) \ -h --help-all \ --no-discard-stderr \ - -i $(top_srcdir)/tools/$@.inc $(abs_builddir)/$< \ + -i $(abs_srcdir)/$@.inc $(abs_builddir)/$< \ | sed -f $(top_srcdir)/tools/fix-manpages > $@ ; \ else \ PATH=$(abs_builddir):$$PATH $(HELP2MAN) $(HELP2MAN_ARGS) \ -- 1.8.3.1 From c7ab1d901bcbbf0137277e783e072777ca2f82d9 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 13 May 2021 11:44:16 -0400 Subject: [PATCH 2/4] Refactor: daemons: Remove the pid_file variable from pacemakerd. It's never used anywhere. --- daemons/pacemakerd/pacemakerd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c index 8ec9708..03d688e 100644 --- a/daemons/pacemakerd/pacemakerd.c +++ b/daemons/pacemakerd/pacemakerd.c @@ -27,8 +27,7 @@ static crm_trigger_t *shutdown_trigger = NULL; static crm_trigger_t *startup_trigger = NULL; -static const char *pid_file = PCMK_RUN_DIR "/pacemaker.pid"; /* state we report when asked via pacemakerd-api status-ping */ static const char *pacemakerd_state = XML_PING_ATTR_PACEMAKERDSTATE_INIT; static gboolean running_with_sbd = FALSE; /* local copy */ @@ -224,7 +222,6 @@ main(int argc, char **argv) /* Legacy */ break; case 'p': - pid_file = optarg; break; case 's': pcmk__set_env_option("node_start_state", "standby"); -- 1.8.3.1 From 98990eed9f6a5dbde7c8a5aa0783e93d5479295b Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 13 May 2021 13:14:38 -0400 Subject: [PATCH 3/4] Refactor: daemons: Use glib for command line handling in pacemakerd. --- daemons/pacemakerd/Makefile.am | 2 + daemons/pacemakerd/pacemakerd.8.inc | 5 + daemons/pacemakerd/pacemakerd.c | 195 ++++++++++++++++++------------------ 3 files changed, 102 insertions(+), 100 deletions(-) create mode 100644 daemons/pacemakerd/pacemakerd.8.inc diff --git a/daemons/pacemakerd/Makefile.am b/daemons/pacemakerd/Makefile.am index cc657f5..84517a3 100644 --- a/daemons/pacemakerd/Makefile.am +++ b/daemons/pacemakerd/Makefile.am @@ -15,6 +15,8 @@ if BUILD_SYSTEMD systemdsystemunit_DATA = pacemaker.service endif +EXTRA_DIST = pacemakerd.8.inc + ## SOURCES noinst_HEADERS = pacemakerd.h diff --git a/daemons/pacemakerd/pacemakerd.8.inc b/daemons/pacemakerd/pacemakerd.8.inc new file mode 100644 index 0000000..902af4e --- /dev/null +++ b/daemons/pacemakerd/pacemakerd.8.inc @@ -0,0 +1,5 @@ +[synopsis] +pacemakerd [options] + +/subsidiary Pacemaker daemons/ +.SH OPTIONS diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c index 03d688e..ce194bf 100644 --- a/daemons/pacemakerd/pacemakerd.c +++ b/daemons/pacemakerd/pacemakerd.c @@ -23,12 +23,54 @@ #include #include #include +#include #include #include #include #include +#define SUMMARY "pacemakerd - primary Pacemaker daemon that launches and monitors all subsidiary Pacemaker daemons" + +struct { + gboolean features; + gboolean foreground; + gboolean shutdown; + gboolean standby; +} options; + +static gboolean +pid_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **err) { + return TRUE; +} + +static gboolean +standby_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **err) { + options.standby = TRUE; + pcmk__set_env_option("node_start_state", "standby"); + return TRUE; +} + +static GOptionEntry entries[] = { + { "features", 'F', 0, G_OPTION_ARG_NONE, &options.features, + "Display full version and list of features Pacemaker was built with", + NULL }, + { "foreground", 'f', 0, G_OPTION_ARG_NONE, &options.foreground, + "(Ignored) Pacemaker always runs in the foreground", + NULL }, + { "pid-file", 'p', 0, G_OPTION_ARG_CALLBACK, pid_cb, + "(Ignored) Daemon pid file location", + "FILE" }, + { "shutdown", 'S', 0, G_OPTION_ARG_NONE, &options.shutdown, + "Instruct Pacemaker to shutdown on this machine", + NULL }, + { "standby", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, standby_cb, + "Start node in standby state", + NULL }, + + { NULL } +}; + static gboolean fatal_error = FALSE; static GMainLoop *mainloop = NULL; static bool global_keep_tracking = false; @@ -642,49 +685,6 @@ pcmk_sigquit(int nsig) .connection_destroyed = pcmk_ipc_destroy }; -static pcmk__cli_option_t long_options[] = { - // long option, argument type, storage, short option, description, flags - { - "help", no_argument, NULL, '?', - "\tThis text", pcmk__option_default - }, - { - "version", no_argument, NULL, '$', - "\tVersion information", pcmk__option_default - }, - { - "verbose", no_argument, NULL, 'V', - "\tIncrease debug output", pcmk__option_default - }, - { - "shutdown", no_argument, NULL, 'S', - "\tInstruct Pacemaker to shutdown on this machine", pcmk__option_default - }, - { - "features", no_argument, NULL, 'F', - "\tDisplay full version and list of features Pacemaker was built with", - pcmk__option_default - }, - { - "-spacer-", no_argument, NULL, '-', - "\nAdditional Options:", pcmk__option_default - }, - { - "foreground", no_argument, NULL, 'f', - "\t(Ignored) Pacemaker always runs in the foreground", - pcmk__option_default - }, - { - "pid-file", required_argument, NULL, 'p', - "\t(Ignored) Daemon pid file location", pcmk__option_default - }, - { - "standby", no_argument, NULL, 's', - "\tStart node in standby state", pcmk__option_default - }, - { 0, 0, 0, 0 } -}; - static void mcp_chown(const char *path, uid_t uid, gid_t gid) { @@ -1168,83 +1211,66 @@ request_shutdown(crm_ipc_t *ipc) return status; } +static GOptionContext * +build_arg_context(pcmk__common_args_t *args) { + GOptionContext *context = NULL; + + context = pcmk__build_arg_context(args, NULL, NULL, NULL); + pcmk__add_main_args(context, entries); + return context; +} + int main(int argc, char **argv) { - int flag; - int argerr = 0; + crm_exit_t exit_code = CRM_EX_OK; + + GError *error = NULL; + + pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY); + gchar **processed_args = pcmk__cmdline_preproc(argv, "p"); + GOptionContext *context = build_arg_context(args); - int option_index = 0; bool old_instance_connected = false; - gboolean shutdown = FALSE; crm_ipc_t *old_instance = NULL; qb_ipcs_service_t *ipcs = NULL; crm_log_preinit(NULL, argc, argv); - pcmk__set_cli_options(NULL, "[options]", long_options, - "primary Pacemaker daemon that launches and " - "monitors all subsidiary Pacemaker daemons"); mainloop_add_signal(SIGHUP, pcmk_ignore); mainloop_add_signal(SIGQUIT, pcmk_sigquit); - while (1) { - flag = pcmk__next_cli_option(argc, argv, &option_index, NULL); - if (flag == -1) - break; - - switch (flag) { - case 'V': - crm_bump_log_level(argc, argv); - break; - case 'f': - /* Legacy */ - break; - case 'p': - break; - case 's': - pcmk__set_env_option("node_start_state", "standby"); - break; - case '$': - case '?': - pcmk__cli_help(flag, CRM_EX_OK); - break; - case 'S': - shutdown = TRUE; - break; - case 'F': - printf("Pacemaker %s (Build: %s)\n Supporting v%s: %s\n", PACEMAKER_VERSION, BUILD_VERSION, - CRM_FEATURE_SET, CRM_FEATURES); - crm_exit(CRM_EX_OK); - default: - printf("Argument code 0%o (%c) is not (?yet?) supported\n", flag, flag); - ++argerr; - break; - } + if (!g_option_context_parse_strv(context, &processed_args, &error)) { + exit_code = CRM_EX_USAGE; + goto done; } - if (optind < argc) { - printf("non-option ARGV-elements: "); - while (optind < argc) - printf("%s ", argv[optind++]); - printf("\n"); - } - if (argerr) { - pcmk__cli_help('?', CRM_EX_USAGE); + if (options.features) { + printf("Pacemaker %s (Build: %s)\n Supporting v%s: %s\n", PACEMAKER_VERSION, BUILD_VERSION, + CRM_FEATURE_SET, CRM_FEATURES); + exit_code = CRM_EX_OK; + goto done; } + if (args->version) { + g_strfreev(processed_args); + pcmk__free_arg_context(context); + /* FIXME: When pacemakerd is converted to use formatted output, this can go. */ + pcmk__cli_help('v', CRM_EX_USAGE); + } setenv("LC_ALL", "C", 1); pcmk__set_env_option("mcp", "true"); + pcmk__cli_init_logging("pacemakerd", args->verbosity); crm_log_init(NULL, LOG_INFO, TRUE, FALSE, argc, argv, FALSE); crm_debug("Checking for existing Pacemaker instance"); old_instance = crm_ipc_new(CRM_SYSTEM_MCP, 0); old_instance_connected = crm_ipc_connect(old_instance); - if (shutdown) { + if (options.shutdown) { if (old_instance_connected) { crm_exit(request_shutdown(old_instance)); } else { @@ -1253,22 +1279,25 @@ main(int argc, char **argv) "Pacemaker instance: %s", strerror(errno)); crm_ipc_close(old_instance); crm_ipc_destroy(old_instance); - crm_exit(CRM_EX_DISCONNECT); + exit_code = CRM_EX_DISCONNECT; + goto done; } } else if (old_instance_connected) { crm_ipc_close(old_instance); crm_ipc_destroy(old_instance); crm_err("Aborting start-up because active Pacemaker instance found"); - crm_exit(CRM_EX_FATAL); + exit_code = CRM_EX_FATAL; + goto done; } crm_ipc_close(old_instance); crm_ipc_destroy(old_instance); #ifdef SUPPORT_COROSYNC if (mcp_read_config() == FALSE) { - crm_exit(CRM_EX_UNAVAILABLE); + exit_code = CRM_EX_UNAVAILABLE; + goto done; } #endif @@ -1292,7 +1321,8 @@ main(int argc, char **argv) #ifdef SUPPORT_COROSYNC /* Allows us to block shutdown */ if (!cluster_connect_cfg()) { - crm_exit(CRM_EX_PROTOCOL); + exit_code = CRM_EX_PROTOCOL; + goto done; } #endif @@ -1307,9 +1337,11 @@ main(int argc, char **argv) case pcmk_rc_ok: break; case pcmk_rc_ipc_unauthorized: - crm_exit(CRM_EX_CANTCREAT); + exit_code = CRM_EX_CANTCREAT; + goto done; default: - crm_exit(CRM_EX_FATAL); + exit_code = CRM_EX_FATAL; + goto done; }; mainloop_add_signal(SIGTERM, pcmk_shutdown); @@ -1342,5 +1374,11 @@ main(int argc, char **argv) #ifdef SUPPORT_COROSYNC cluster_disconnect_cfg(); #endif - crm_exit(CRM_EX_OK); + +done: + g_strfreev(processed_args); + pcmk__free_arg_context(context); + + pcmk__output_and_clear_error(error, NULL); + crm_exit(exit_code); } -- 1.8.3.1 From 8f7924fbb2a012bedcad59335b7bebc5020b26e3 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 13 May 2021 13:27:13 -0400 Subject: [PATCH 4/4] Low: pacemaker.service: Don't start pacemakerd with -f. This option is completely ignored by pacemakerd. --- daemons/pacemakerd/pacemaker.service.in | 2 +- doc/sphinx/Clusters_from_Scratch/verification.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/daemons/pacemakerd/pacemaker.service.in b/daemons/pacemakerd/pacemaker.service.in index b128ddc..0363a22 100644 --- a/daemons/pacemakerd/pacemaker.service.in +++ b/daemons/pacemakerd/pacemaker.service.in @@ -44,7 +44,7 @@ EnvironmentFile=-@CONFIGDIR@/pacemaker EnvironmentFile=-@CONFIGDIR@/sbd SuccessExitStatus=100 -ExecStart=@sbindir@/pacemakerd -f +ExecStart=@sbindir@/pacemakerd # Systemd v227 and above can limit the number of processes spawned by a # service. That is a bad idea for an HA cluster resource manager, so disable it diff --git a/doc/sphinx/Clusters_from_Scratch/verification.rst b/doc/sphinx/Clusters_from_Scratch/verification.rst index 9d647f8..b7fa20e 100644 --- a/doc/sphinx/Clusters_from_Scratch/verification.rst +++ b/doc/sphinx/Clusters_from_Scratch/verification.rst @@ -103,7 +103,7 @@ the necessary processes are running: 2 ? S 0:00 [kthreadd] ...lots of processes... 17121 ? SLsl 0:01 /usr/sbin/corosync -f - 17133 ? Ss 0:00 /usr/sbin/pacemakerd -f + 17133 ? Ss 0:00 /usr/sbin/pacemakerd 17134 ? Ss 0:00 \_ /usr/libexec/pacemaker/pacemaker-based 17135 ? Ss 0:00 \_ /usr/libexec/pacemaker/pacemaker-fenced 17136 ? Ss 0:00 \_ /usr/libexec/pacemaker/pacemaker-execd -- 1.8.3.1