Skip to content

Commit

Permalink
main: Fix systemd capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
  • Loading branch information
monstermunchkin committed Apr 21, 2021
1 parent a6ea76a commit 6023d70
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions distrobuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
"strings"
"time"

lxd "github.com/lxc/lxd/shared"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -441,3 +442,18 @@ func getDefinition(fname string, options []string) (*shared.Definition, error) {

return &def, nil
}

func fixCapabilities() {
// Check if container has systemd
if !lxd.PathExists("/etc/systemd") {
return
}

os.MkdirAll("/etc/systemd/system/service.d", 0755)

content := `[Service]
ProtectProc=default
ProtectControlGroups=no
`
ioutil.WriteFile("/etc/systemd/system/service.d/lxc.conf", []byte(content), 0644)
}
2 changes: 2 additions & 0 deletions distrobuilder/main_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (c *cmdLXC) run(cmd *cobra.Command, args []string, overlayDir string) error
}
}

fixCapabilities()

exitChroot()

err = img.Build()
Expand Down
4 changes: 4 additions & 0 deletions distrobuilder/main_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string, overlayDir string) error
}
}

if !c.flagVM {
fixCapabilities()
}

exitChroot()

// Unmount VM directory and loop device before creating the image.
Expand Down

0 comments on commit 6023d70

Please sign in to comment.