[lxc-devel] [distrobuilder/master] generator/lxd-agent: Fix systemd units path

monstermunchkin on Github lxc-bot at linuxcontainers.org
Thu Feb 27 15:17:31 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 480 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200227/080112bc/attachment-0001.bin>
-------------- next part --------------
From 608d4db0b8987798742b3b6ec7821ce5081d54e3 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 27 Feb 2020 16:17:01 +0100
Subject: [PATCH] generator/lxd-agent: Fix systemd units path

This checks the existance of /lib/systemd/system, and uses
/usr/lib/systemd/system if the former doesn't exist.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 generators/lxd-agent.go | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/generators/lxd-agent.go b/generators/lxd-agent.go
index cd861eb..9f1b684 100644
--- a/generators/lxd-agent.go
+++ b/generators/lxd-agent.go
@@ -79,12 +79,18 @@ ExecStart=/run/lxd_config/9p/lxd-agent
 WantedBy=multi-user.target
 `
 
-	err := ioutil.WriteFile(filepath.Join(sourceDir, "/lib/systemd/system/lxd-agent.service"), []byte(lxdAgentServiceUnit), 0644)
+	systemdPath := filepath.Join("/", "lib", "systemd", "system")
+
+	if !lxd.PathExists(filepath.Dir(filepath.Join(sourceDir, systemdPath))) {
+		systemdPath = filepath.Join("/", "usr", "lib", "systemd", "system")
+	}
+
+	err := ioutil.WriteFile(filepath.Join(sourceDir, systemdPath, "lxd-agent.service"), []byte(lxdAgentServiceUnit), 0644)
 	if err != nil {
 		return err
 	}
 
-	err = os.Symlink("/lib/systemd/system/lxd-agent.service", filepath.Join(sourceDir, "/etc/systemd/system/multi-user.target.wants/lxd-agent.service"))
+	err = os.Symlink(filepath.Join(sourceDir, systemdPath, "lxd-agent.service"), filepath.Join(sourceDir, "/etc/systemd/system/multi-user.target.wants/lxd-agent.service"))
 	if err != nil {
 		return err
 	}
@@ -106,12 +112,12 @@ ExecStart=/bin/mount -t 9p config /run/lxd_config/9p -o access=0
 WantedBy=multi-user.target
 `
 
-	err = ioutil.WriteFile(filepath.Join(sourceDir, "/lib/systemd/system/lxd-agent-9p.service"), []byte(lxdConfigShareMountUnit), 0644)
+	err = ioutil.WriteFile(filepath.Join(sourceDir, systemdPath, "lxd-agent-9p.service"), []byte(lxdConfigShareMountUnit), 0644)
 	if err != nil {
 		return err
 	}
 
-	err = os.Symlink("/lib/systemd/system/lxd-agent-9p.service", filepath.Join(sourceDir, "/etc/systemd/system/multi-user.target.wants/lxd-agent-9p.service"))
+	err = os.Symlink(filepath.Join(sourceDir, systemdPath, "lxd-agent-9p.service"), filepath.Join(sourceDir, "/etc/systemd/system/multi-user.target.wants/lxd-agent-9p.service"))
 	if err != nil {
 		return err
 	}


More information about the lxc-devel mailing list