[lxc-devel] [lxd/master] lxd: Fix socket activated startup

stgraber on Github lxc-bot at linuxcontainers.org
Wed Mar 14 14:45:24 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180314/51f773c7/attachment.bin>
-------------- next part --------------
From b193e0cfa6c6bf90988286957fd8b16b322d9081 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 14 Mar 2018 10:34:05 -0400
Subject: [PATCH] lxd: Fix socket activated startup
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/endpoints/socket.go | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lxd/endpoints/socket.go b/lxd/endpoints/socket.go
index 8db63d09c..558a04df0 100644
--- a/lxd/endpoints/socket.go
+++ b/lxd/endpoints/socket.go
@@ -4,8 +4,9 @@ import (
 	"fmt"
 	"net"
 	"os"
+	"strconv"
 
-	lxd "github.com/lxc/lxd/client"
+	"github.com/lxc/lxd/client"
 	"github.com/lxc/lxd/shared"
 	"github.com/lxc/lxd/shared/logger"
 )
@@ -34,12 +35,20 @@ func socketUnixListen(path string) (net.Listener, error) {
 //        this logic has historically behaved, so let's keep it like it
 //        was.
 func CheckAlreadyRunning(path string) error {
+	// If socket activated, nothing to do
+	pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
+	if err == nil {
+		if pid == os.Getpid() {
+			return nil
+		}
+	}
+
 	// If there's no socket file at all, there's nothing to do.
 	if !shared.PathExists(path) {
 		return nil
 	}
 
-	_, err := lxd.ConnectLXDUnix(path, nil)
+	_, err = lxd.ConnectLXDUnix(path, nil)
 
 	// If the connection succeeded it means there's another LXD running.
 	if err == nil {


More information about the lxc-devel mailing list