|
|
533c21 |
From 09ef95a2eed48b4eb7488788a1b655d67eafe783 Mon Sep 17 00:00:00 2001
|
|
|
533c21 |
From: Chris Lumens <clumens@redhat.com>
|
|
|
533c21 |
Date: Tue, 30 Nov 2021 14:47:12 -0500
|
|
|
533c21 |
Subject: [PATCH] Low: libcrmservice: Handle systemd service templates.
|
|
|
533c21 |
|
|
|
533c21 |
These unit files (which have an @ sign at the end) expect to be
|
|
|
533c21 |
parameterized by an instance name. Not providing an instance name
|
|
|
533c21 |
causes the dbus lookup to fail, and we fall back to assume this is an
|
|
|
533c21 |
LSB service. If the user doesn't provide an instance name, just add a
|
|
|
533c21 |
fake one. It doesn't seem to matter what name is given for the lookup.
|
|
|
533c21 |
|
|
|
533c21 |
See: rhbz#2003151
|
|
|
533c21 |
---
|
|
|
533c21 |
lib/services/systemd.c | 22 ++++++++++++++++------
|
|
|
533c21 |
1 file changed, 16 insertions(+), 6 deletions(-)
|
|
|
533c21 |
|
|
|
533c21 |
diff --git a/lib/services/systemd.c b/lib/services/systemd.c
|
|
|
533c21 |
index 8e9fff484..27a3b376d 100644
|
|
|
533c21 |
--- a/lib/services/systemd.c
|
|
|
533c21 |
+++ b/lib/services/systemd.c
|
|
|
533c21 |
@@ -206,17 +206,27 @@ systemd_unit_extension(const char *name)
|
|
|
533c21 |
}
|
|
|
533c21 |
|
|
|
533c21 |
static char *
|
|
|
533c21 |
-systemd_service_name(const char *name)
|
|
|
533c21 |
+systemd_service_name(const char *name, bool add_instance_name)
|
|
|
533c21 |
{
|
|
|
533c21 |
- if (name == NULL) {
|
|
|
533c21 |
+ if (pcmk__str_empty(name)) {
|
|
|
533c21 |
return NULL;
|
|
|
533c21 |
}
|
|
|
533c21 |
|
|
|
533c21 |
if (systemd_unit_extension(name)) {
|
|
|
533c21 |
return strdup(name);
|
|
|
533c21 |
- }
|
|
|
533c21 |
|
|
|
533c21 |
- return crm_strdup_printf("%s.service", name);
|
|
|
533c21 |
+ /* Services that end with an @ sign are systemd templates. They expect an
|
|
|
533c21 |
+ * instance name to follow the service name. If no instance name was
|
|
|
533c21 |
+ * provided, just add "x" to the string as the instance name. It doesn't
|
|
|
533c21 |
+ * seem to matter for purposes of looking up whether a service exists or
|
|
|
533c21 |
+ * not.
|
|
|
533c21 |
+ */
|
|
|
533c21 |
+ } else if (add_instance_name && *(name+strlen(name)-1) == '@') {
|
|
|
533c21 |
+ return crm_strdup_printf("%sx.service", name);
|
|
|
533c21 |
+
|
|
|
533c21 |
+ } else {
|
|
|
533c21 |
+ return crm_strdup_printf("%s.service", name);
|
|
|
533c21 |
+ }
|
|
|
533c21 |
}
|
|
|
533c21 |
|
|
|
533c21 |
static void
|
|
|
533c21 |
@@ -427,7 +437,7 @@ invoke_unit_by_name(const char *arg_name, svc_action_t *op, char **path)
|
|
|
533c21 |
CRM_ASSERT(msg != NULL);
|
|
|
533c21 |
|
|
|
533c21 |
// Add the (expanded) unit name as the argument
|
|
|
533c21 |
- name = systemd_service_name(arg_name);
|
|
|
533c21 |
+ name = systemd_service_name(arg_name, op == NULL || pcmk__str_eq(op->action, "meta-data", pcmk__str_none));
|
|
|
533c21 |
CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
|
|
|
533c21 |
DBUS_TYPE_INVALID));
|
|
|
533c21 |
free(name);
|
|
|
533c21 |
@@ -944,7 +954,7 @@ invoke_unit_by_path(svc_action_t *op, const char *unit)
|
|
|
533c21 |
/* (ss) */
|
|
|
533c21 |
{
|
|
|
533c21 |
const char *replace_s = "replace";
|
|
|
533c21 |
- char *name = systemd_service_name(op->agent);
|
|
|
533c21 |
+ char *name = systemd_service_name(op->agent, pcmk__str_eq(op->action, "meta-data", pcmk__str_none));
|
|
|
533c21 |
|
|
|
533c21 |
CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID));
|
|
|
533c21 |
CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &replace_s, DBUS_TYPE_INVALID));
|
|
|
533c21 |
--
|
|
|
533c21 |
2.27.0
|
|
|
533c21 |
|