[lxc-devel] [lxd/master] Hook cleanup

tych0 on Github lxc-bot at linuxcontainers.org
Mon Oct 24 18:39:40 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161024/b4352f7d/attachment.bin>
-------------- next part --------------
From a03d267d38fe3c66c725ebd671d0323cc1743451 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Mon, 24 Oct 2016 18:33:32 +0000
Subject: [PATCH 1/2] also clean up apparmor stuff in OnStart when something
 fails

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/container_lxc.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 7170548..ff048d8 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1569,6 +1569,7 @@ func (c *containerLXC) OnStart() error {
 		// Run any template that needs running
 		err = c.templateApplyNow(c.localConfig[key])
 		if err != nil {
+			AADestroy(c)
 			c.StorageStop()
 			return err
 		}
@@ -1576,6 +1577,7 @@ func (c *containerLXC) OnStart() error {
 		// Remove the volatile key from the DB
 		err := dbContainerConfigRemove(c.daemon.db, c.id, key)
 		if err != nil {
+			AADestroy(c)
 			c.StorageStop()
 			return err
 		}
@@ -1583,6 +1585,7 @@ func (c *containerLXC) OnStart() error {
 
 	err = c.templateApplyNow("start")
 	if err != nil {
+		AADestroy(c)
 		c.StorageStop()
 		return err
 	}

From 8f5d0ef5e3ee447546f2991ba565225f7776c2dd Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Mon, 24 Oct 2016 18:38:25 +0000
Subject: [PATCH 2/2] log OnStart/OnStop hook errors

The problem here is that liblxc doesn't log errors in hooks, it just logs
the exit code, so if a hook fails and someone isn't running in debug mode,
we really have no way to figure out what went wrong. Let's at least log the
error that the hook gave.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/api_internal.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index ad32446..51c11e3 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -6,6 +6,10 @@ import (
 	"strconv"
 
 	"github.com/gorilla/mux"
+
+	"github.com/lxc/lxd/shared"
+
+	log "gopkg.in/inconshreveable/log15.v2"
 )
 
 var apiInternal = []Command{
@@ -55,6 +59,7 @@ func internalContainerOnStart(d *Daemon, r *http.Request) Response {
 
 	err = c.OnStart()
 	if err != nil {
+		shared.Log.Error("start hook failed", log.Ctx{"container": c.Name(), "err": err})
 		return SmartError(err)
 	}
 
@@ -79,6 +84,7 @@ func internalContainerOnStop(d *Daemon, r *http.Request) Response {
 
 	err = c.OnStop(target)
 	if err != nil {
+		shared.Log.Error("stop hook failed", log.Ctx{"container": c.Name(), "err": err})
 		return SmartError(err)
 	}
 


More information about the lxc-devel mailing list