The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/370
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 76a4b2fd347afe795df3263f2ee0fd188495b665 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 30 Oct 2020 15:00:46 +0100 Subject: [PATCH] generators: Add virtio-fs to lxd-agent init scripts Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- generators/lxd-agent.go | 122 +++++++++++++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 15 deletions(-) diff --git a/generators/lxd-agent.go b/generators/lxd-agent.go index 88f1e3e..afa49bc 100644 --- a/generators/lxd-agent.go +++ b/generators/lxd-agent.go @@ -66,15 +66,18 @@ func (g LXDAgentGenerator) handleSystemd(sourceDir string) error { Description=LXD - agent Documentation=https://linuxcontainers.org/lxd ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd -Requires=lxd-agent-9p.service +Wants=lxd-agent-virtiofs.service +After=lxd-agent-virtiofs.service +Wants=lxd-agent-9p.service After=lxd-agent-9p.service + Before=cloud-init.target cloud-init.service cloud-init-local.service DefaultDependencies=no [Service] Type=notify -WorkingDirectory=/run/lxd_config/9p -ExecStart=/run/lxd_config/9p/lxd-agent +WorkingDirectory=/run/lxd_config/drive +ExecStart=/run/lxd_config/drive/lxd-agent Restart=on-failure RestartSec=5s StartLimitInterval=60 @@ -103,16 +106,17 @@ WantedBy=multi-user.target Description=LXD - agent - 9p mount Documentation=https://linuxcontainers.org/lxd ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd -After=local-fs.target +After=local-fs.target lxd-agent-virtiofs.service DefaultDependencies=no +ConditionPathIsMountPoint=!/run/lxd_config/drive [Service] Type=oneshot RemainAfterExit=yes ExecStartPre=-/sbin/modprobe 9pnet_virtio -ExecStartPre=/bin/mkdir -p /run/lxd_config/9p +ExecStartPre=/bin/mkdir -p /run/lxd_config/drive ExecStartPre=/bin/chmod 0700 /run/lxd_config/ -ExecStart=/bin/mount -t 9p config /run/lxd_config/9p -o access=0,trans=virtio +ExecStart=/bin/mount -t 9p config /run/lxd_config/drive -o access=0,trans=virtio [Install] WantedBy=multi-user.target @@ -128,6 +132,36 @@ WantedBy=multi-user.target return err } + lxdConfigShareMountVirtioFSUnit := `[Unit] +Description=LXD - agent - virtio-fs mount +Documentation=https://linuxcontainers.org/lxd +ConditionPathExists=/dev/virtio-ports/org.linuxcontainers.lxd +After=local-fs.target +Before=lxd-agent-9p.service +DefaultDependencies=no +ConditionPathIsMountPoint=!/run/lxd_config/drive + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStartPre=/bin/mkdir -p /run/lxd_config/drive +ExecStartPre=/bin/chmod 0700 /run/lxd_config/ +ExecStart=/bin/mount -t virtiofs config /run/lxd_config/drive + +[Install] +WantedBy=multi-user.target +` + + err = ioutil.WriteFile(filepath.Join(sourceDir, systemdPath, "lxd-agent-virtiofs.service"), []byte(lxdConfigShareMountVirtioFSUnit), 0644) + if err != nil { + return err + } + + err = os.Symlink(filepath.Join(sourceDir, systemdPath, "lxd-agent-virtiofs.service"), filepath.Join(sourceDir, "/etc/systemd/system/multi-user.target.wants/lxd-agent-virtiofs.service")) + if err != nil { + return err + } + udevPath := filepath.Join("/", "lib", "udev", "rules.d") stat, err := os.Lstat(filepath.Join(sourceDir, "lib", "udev")) @@ -148,14 +182,16 @@ func (g LXDAgentGenerator) handleOpenRC(sourceDir string) error { lxdAgentScript := `#!/sbin/openrc-run description="LXD - agent" -command=/run/lxd_config/9p/lxd-agent +command=/run/lxd_config/drive/lxd-agent command_background=true pidfile=/run/lxd-agent.pid -start_stop_daemon_args="--chdir /run/lxd_config/9p" -required_dirs=/run/lxd_config/9p +start_stop_daemon_args="--chdir /run/lxd_config/drive" +required_dirs=/run/lxd_config/drive depend() { - need lxd-agent-9p + want lxd-agent-virtiofs + after lxd-agent-virtiofs + want lxd-agent-9p after lxd-agent-9p before cloud-init before cloud-init-local @@ -176,13 +212,15 @@ depend() { description="LXD - agent - 9p mount" command=/bin/mount -command_args="-t 9p config /run/lxd_config/9p -o access=0,trans=virtio" +command_args="-t 9p config /run/lxd_config/drive -o access=0,trans=virtio" required_files=/dev/virtio-ports/org.linuxcontainers.lxd start_pre() { /sbin/modprobe 9pnet_virtio || true + # Don't proceed if the config drive is mounted already + mount | grep -q /run/lxd_config/drive && false checkpath -d /run/lxd_config -m 0700 - checkpath -d /run/lxd_config/9p + checkpath -d /run/lxd_config/drive } ` @@ -196,6 +234,31 @@ start_pre() { return err } + lxdConfigShareMountVirtioFSScript := `#!/sbin/openrc-run + + description="LXD - agent - virtio-fs mount" + command=/bin/mount + command_args="-t virtiofs config /run/lxd_config/drive" + required_files=/dev/virtio-ports/org.linuxcontainers.lxd + + start_pre() { + # Don't proceed if the config drive is mounted already + mount | grep -q /run/lxd_config/drive && false + checkpath -d /run/lxd_config -m 0700 + checkpath -d /run/lxd_config/drive + } + ` + + err = ioutil.WriteFile(filepath.Join(sourceDir, "/etc/init.d/lxd-agent-virtiofs"), []byte(lxdConfigShareMountVirtioFSScript), 0755) + if err != nil { + return err + } + + err = os.Symlink("/etc/init.d/lxd-agent-virtiofs", filepath.Join(sourceDir, "/etc/runlevels/default/lxd-agent-virtiofs")) + if err != nil { + return err + } + return nil } @@ -218,21 +281,26 @@ exec lxd-agent lxdConfigShareMountScript := `Description "LXD agent 9p mount" -start on runlevel filesystem +start on stopped lxd-agent-virtiofs pre-start script + if mount | grep -q /run/lxd_config/drive; then + stop + exit 0 + fi + if ! modprobe 9pnet_virtio; then stop exit 0 fi - mkdir -p /run/lxd_config/9p + mkdir -p /run/lxd_config/drive chmod 0700 /run/lxd_config end script task -exec mount -t 9p config /run/lxd_config/9p -o access=0,trans=virtio +exec mount -t 9p config /run/lxd_config/drive -o access=0,trans=virtio ` err = ioutil.WriteFile(filepath.Join(sourceDir, "/etc/init/lxd-agent-9p"), []byte(lxdConfigShareMountScript), 0755) @@ -240,6 +308,30 @@ exec mount -t 9p config /run/lxd_config/9p -o access=0,trans=virtio return err } + lxdConfigShareMountVirtioFSScript := `Description "LXD agent virtio-fs mount" + +start on runlevel filesystem + +pre-start script + if mount | grep -q /run/lxd_config/drive; then + stop + exit 0 + fi + + mkdir -p /run/lxd_config/drive + chmod 0700 /run/lxd_config +end script + +task + +exec mount -t virtiofs config /run/lxd_config/drive +` + + err = ioutil.WriteFile(filepath.Join(sourceDir, "/etc/init/lxd-agent-virtiofs"), []byte(lxdConfigShareMountVirtioFSScript), 0755) + if err != nil { + return err + } + return nil }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel