[lxc-devel] [distrobuilder/master] generators: Disable cloud-init for LXC in upstart
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Thu Aug 8 15:39:45 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190808/bb92b5fa/attachment.bin>
-------------- next part --------------
From 5ce6c1530cf3c427c769d505d986e52fd4d9124e Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 7 Aug 2019 16:45:46 +0200
Subject: [PATCH] generators: Disable cloud-init for LXC in upstart
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
generators/cloud-init.go | 50 ++++++++++++++++++++++++++++++++--------
1 file changed, 41 insertions(+), 9 deletions(-)
diff --git a/generators/cloud-init.go b/generators/cloud-init.go
index ee50ae5..ed89e36 100644
--- a/generators/cloud-init.go
+++ b/generators/cloud-init.go
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "regexp"
"strings"
lxd "github.com/lxc/lxd/shared"
@@ -21,20 +22,51 @@ func (g CloudInitGenerator) RunLXC(cacheDir, sourceDir string, img *image.LXCIma
defFile shared.DefinitionFile) error {
// With OpenRC:
// Remove all symlinks to /etc/init.d/cloud-{init-local,config,init,final} in /etc/runlevels/*
- filepath.Walk(filepath.Join(sourceDir, "/etc/runlevels"), func(path string, info os.FileInfo, err error) error {
- if info.IsDir() {
+ fullPath := filepath.Join(sourceDir, "/etc/runlevels")
+
+ if lxd.PathExists(fullPath) {
+ filepath.Walk(fullPath, func(path string, info os.FileInfo, err error) error {
+ if info.IsDir() {
+ return nil
+ }
+
+ if lxd.StringInSlice(info.Name(), []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"}) {
+ err := os.Remove(path)
+ if err != nil {
+ return err
+ }
+ }
+
return nil
+ })
+ }
+
+ // With upstart:
+ // Remove all symlinks to /etc/rc.d/init.d/cloud-{init-local,config,init,final} in /etc/rc.d/rc<runlevel>.d/*
+ re := regexp.MustCompile(`^[KS]\d+cloud-(?:config|final|init|init-local)$`)
+
+ for i := 0; i <= 6; i++ {
+ fullPath := filepath.Join(sourceDir, fmt.Sprintf("/etc/rc.d/rc%d.d", i))
+
+ if !lxd.PathExists(fullPath) {
+ continue
}
- if lxd.StringInSlice(info.Name(), []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"}) {
- err := os.Remove(path)
- if err != nil {
- return err
+ filepath.Walk(fullPath, func(path string, info os.FileInfo, err error) error {
+ if info.IsDir() {
+ return nil
}
- }
- return nil
- })
+ if re.MatchString(info.Name()) {
+ err := os.Remove(path)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+ })
+ }
// With systemd:
// Create file /etc/cloud/cloud-init.disabled
More information about the lxc-devel
mailing list