The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/276

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===

From b68eca381b74b78db6d80bba8bce0a6791a4e12c Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Thu, 13 Feb 2020 16:40:14 +0100
Subject: [PATCH 1/2] generators: Add lxd-agent generator

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 generators/generators.go |  6 +++
 generators/lxd-agent.go  | 83 ++++++++++++++++++++++++++++++++++++++++
 shared/definition.go     |  1 +
 3 files changed, 90 insertions(+)
 create mode 100644 generators/lxd-agent.go

diff --git a/generators/generators.go b/generators/generators.go
index 3842852..2080e86 100644
--- a/generators/generators.go
+++ b/generators/generators.go
@@ -1,6 +1,7 @@
 package generators
 
 import (
+       "errors"
        "os"
        p "path"
        "path/filepath"
@@ -12,6 +13,9 @@ import (
        "github.com/lxc/distrobuilder/shared"
 )
 
+// ErrNotSupported returns a "Not supported" error
+var ErrNotSupported = errors.New("Not supported")
+
 // Generator interface.
 type Generator interface {
        RunLXC(string, string, *image.LXCImage, shared.DefinitionFile) error
@@ -36,6 +40,8 @@ func Get(generator string) Generator {
                return UpstartTTYGenerator{}
        case "cloud-init":
                return CloudInitGenerator{}
+       case "lxd-agent":
+               return LXDAgentGenerator{}
        }
 
        return nil
diff --git a/generators/lxd-agent.go b/generators/lxd-agent.go
new file mode 100644
index 0000000..8cae145
--- /dev/null
+++ b/generators/lxd-agent.go
@@ -0,0 +1,83 @@
+package generators
+
+import (
+       "io/ioutil"
+       "os"
+       "path/filepath"
+
+       "github.com/lxc/distrobuilder/image"
+       "github.com/lxc/distrobuilder/shared"
+)
+
+// LXDAgentGenerator represents the lxd-agent generator.
+type LXDAgentGenerator struct{}
+
+// RunLXC is not supported.
+func (g LXDAgentGenerator) RunLXC(cacheDir, sourceDir string, img 
*image.LXCImage, defFile shared.DefinitionFile) error {
+       return ErrNotSupported
+}
+
+// RunLXD creates systemd unit files for the lxd-agent.
+func (g LXDAgentGenerator) RunLXD(cacheDir, sourceDir string, img 
*image.LXDImage, defFile shared.DefinitionFile) error {
+       lxdAgentServiceUnit := `[Unit]
+Description=LXD - agent
+Documentation=https://linuxcontainers.org/lxd
+ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd
+Requires=lxd-agent-9p.service
+After=lxd-agent-9p.service
+Before=cloud-init.target
+
+[Service]
+Type=simple
+WorkingDirectory=/run/lxd_config/9p
+ExecStart=/run/lxd_config/9p/lxd-agent
+
+[Install]
+WantedBy=multi-user.target
+`
+
+       err := ioutil.WriteFile(filepath.Join(sourceDir, 
"/lib/systemd/lxd-agent.service"), []byte(lxdAgentServiceUnit), 0400)
+       if err != nil {
+               return err
+       }
+
+       err = os.Symlink(filepath.Join(sourceDir, 
"/lib/systemd/system/lxd-agent.service"), 
"/etc/systemd/system/multi-user.target.wants/lxd-agent.service")
+       if err != nil {
+               return err
+       }
+
+       lxdConfigShareMountUnit := `[Unit]
+Description=LXD - agent - 9p mount
+Documentation=https://linuxcontainers.org/lxd
+ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStartPre=-/sbin/modprobe 9pnet_virtio
+ExecStartPre=/bin/mkdir -p /run/lxd_config/9p
+ExecStartPre=/bin/chmod 0700 /run/lxd_config/
+ExecStart=/bin/mount -t 9p config /run/lxd_config/9p -o access=0
+
+[Install]
+WantedBy=multi-user.target
+`
+
+       err = ioutil.WriteFile(filepath.Join(sourceDir, 
"/lib/systemd/lxd-agent-9p.service"), []byte(lxdConfigShareMountUnit), 0400)
+       if err != nil {
+               return err
+       }
+
+       err = os.Symlink(filepath.Join(sourceDir, 
"/lib/systemd/system/lxd-agent-9p.service"), 
"/etc/systemd/system/multi-user.target.wants/lxd-agent-9p.service")
+       if err != nil {
+               return err
+       }
+
+       return nil
+}
+
+// Run does nothing.
+func (g LXDAgentGenerator) Run(cacheDir, sourceDir string,
+       defFile shared.DefinitionFile) error {
+       return nil
+}
diff --git a/shared/definition.go b/shared/definition.go
index 7b586d5..b74fb5a 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -352,6 +352,7 @@ func (d *Definition) Validate() error {
                "remove",
                "upstart-tty",
                "cloud-init",
+               "lxd-agent",
        }
 
        for _, file := range d.Files {

From e2c7d53e78002feefcc0c107eae5dcef7283e291 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Fri, 14 Feb 2020 09:51:33 +0100
Subject: [PATCH 2/2] doc: Add lxd-agent generator

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 doc/generators.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/doc/generators.md b/doc/generators.md
index 61eaa46..74b613c 100644
--- a/doc/generators.md
+++ b/doc/generators.md
@@ -82,3 +82,7 @@ See [LXD image 
format](https://lxd.readthedocs.io/en/latest/image-handling/#imag
 
 This generator creates an upstart job which prevents certain TTYs from 
starting.
 The job script is written to `path`.
+
+## lxd-agent
+
+This generator creates the systemd unit files which are needed to start the 
lxd-agent in LXD VMs.
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to