[lxc-devel] [lxd/master] container: Rename's OnStop hook function to OnPostStop()
tomponline on Github
lxc-bot at linuxcontainers.org
Sun May 19 14:43:52 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 574 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190519/e5024d84/attachment.bin>
-------------- next part --------------
From 0ca23869e4243ff9d4aa542e476c6ebfa718c3e1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Sun, 19 May 2019 15:37:49 +0100
Subject: [PATCH] container: Rename's OnStop hook function to OnPostStop()
This better reflects the actual LXC hook type being used (lxc.hook.post-stop) and allows the OnStop() function to be added back in the future with different functionality to be run by LXC's lxc.hook.stop hook.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/api_internal.go | 12 ++++++------
lxd/container.go | 2 +-
lxd/container_lxc.go | 8 +++++---
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index 508801f243..40f06acbf9 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -34,7 +34,7 @@ var apiInternal = []APIEndpoint{
internalShutdownCmd,
internalContainerOnStartCmd,
internalContainerOnNetworkUpCmd,
- internalContainerOnStopCmd,
+ internalContainerOnPostStopCmd,
internalContainersCmd,
internalSQLCmd,
internalClusterAcceptCmd,
@@ -63,10 +63,10 @@ var internalContainerOnStartCmd = APIEndpoint{
Get: APIEndpointAction{Handler: internalContainerOnStart},
}
-var internalContainerOnStopCmd = APIEndpoint{
- Name: "containers/{id}/onstop",
+var internalContainerOnPostStopCmd = APIEndpoint{
+ Name: "containers/{id}/onpoststop",
- Get: APIEndpointAction{Handler: internalContainerOnStop},
+ Get: APIEndpointAction{Handler: internalContainerOnPostStop},
}
var internalContainerOnNetworkUpCmd = APIEndpoint{
@@ -136,7 +136,7 @@ func internalContainerOnStart(d *Daemon, r *http.Request) Response {
return EmptySyncResponse
}
-func internalContainerOnStop(d *Daemon, r *http.Request) Response {
+func internalContainerOnPostStop(d *Daemon, r *http.Request) Response {
id, err := strconv.Atoi(mux.Vars(r)["id"])
if err != nil {
return SmartError(err)
@@ -152,7 +152,7 @@ func internalContainerOnStop(d *Daemon, r *http.Request) Response {
return SmartError(err)
}
- err = c.OnStop(target)
+ err = c.OnPostStop(target)
if err != nil {
logger.Error("The stop hook failed", log.Ctx{"container": c.Name(), "err": err})
return SmartError(err)
diff --git a/lxd/container.go b/lxd/container.go
index e935dde899..ccfae6a5fa 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -681,7 +681,7 @@ type container interface {
// Hooks
OnStart() error
- OnStop(target string) error
+ OnPostStop(target string) error
OnNetworkUp(deviceName string, hostVeth string) error
// Properties
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index f46fc24887..525c2de3f5 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1223,7 +1223,7 @@ func (c *containerLXC) initLXC(config bool) error {
}
}
- err = lxcSetConfigItem(cc, "lxc.hook.post-stop", fmt.Sprintf("%s callhook %s %d stop", c.state.OS.ExecPath, shared.VarPath(""), c.id))
+ err = lxcSetConfigItem(cc, "lxc.hook.post-stop", fmt.Sprintf("%s callhook %s %d poststop", c.state.OS.ExecPath, shared.VarPath(""), c.id))
if err != nil {
return err
}
@@ -3050,10 +3050,12 @@ func (c *containerLXC) Shutdown(timeout time.Duration) error {
return nil
}
-func (c *containerLXC) OnStop(target string) error {
+// OnPostStop is triggered by LXC's post-stop once a container is shutdown and after the container's
+// namespaces have been closed.
+func (c *containerLXC) OnPostStop(target string) error {
// Validate target
if !shared.StringInSlice(target, []string{"stop", "reboot"}) {
- logger.Error("Container sent invalid target to OnStop", log.Ctx{"container": c.Name(), "target": target})
+ logger.Error("Container sent invalid target to OnPostStop", log.Ctx{"container": c.Name(), "target": target})
return fmt.Errorf("Invalid stop target: %s", target)
}
More information about the lxc-devel
mailing list