From 2d6dd8e608ad1a45c10bc5052ab6eb805341a60c Mon Sep 17 00:00:00 2001 From: Brent Salisbury Date: Sun, 19 Jul 2015 18:00:12 -0400 Subject: [PATCH] issue #7 create the socket filehandle path if it doesnt exist Signed-off-by: Brent Salisbury --- plugin/main.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/plugin/main.go b/plugin/main.go index 6ff152f..d63d80b 100644 --- a/plugin/main.go +++ b/plugin/main.go @@ -47,22 +47,21 @@ func cliInit(ctx *cli.Context) error { log.SetLevel(log.InfoLevel) } log.SetOutput(os.Stderr) - // Verify the path to the plugin socket exists - // Should we make it if it doesnt exist? - sockDir, _ := filepath.Split(socketFile) - dhandle, err := os.Stat(sockDir) - if err != nil { - log.Fatalf("socket filepath [ %s ] does not exist", sockDir) + // Verify the path to the plugin socket oath and filename were passed + sockDir, fileHandle := filepath.Split(socketFile) + if fileHandle == "" { + log.Fatalf("Socket file path and name are required. Ex. /usr/share/docker/plugins/.sock") } - // Verify the path is a directory - if !dhandle.IsDir() { - log.Fatalf("socket filepath [ %s ] is not a directory", sockDir) + // Make the plugin filepath and parent dir if it does not already exist + if err := os.MkdirAll(sockDir, 0755); err != nil && !os.IsExist(err) { + log.Warnf("Could not create net plugin path directory: [ %s ]", err) } - // If the ovs plugin socket file already exists, remove it. + // If the plugin socket file already exists, remove it. if _, err := os.Stat(socketFile); err == nil { - log.Debugf("socket file [ %s ] already exists, attempting to remove it.", socketFile) + log.Debugf("socket file [ %s ] already exists, deleting..", socketFile) removeSock(socketFile) } + log.Debugf("Plugin socket path is [ %s ] with a file handle [ %s ]", sockDir, fileHandle) return nil }