Skip to content

Commit

Permalink
Merge pull request #16 from nerdalert/brent/socket-filepath
Browse files Browse the repository at this point in the history
issue #7 create the socket filehandle path if it doesnt exist
  • Loading branch information
nerdalert committed Jul 19, 2015
2 parents 8f92219 + 2d6dd8e commit 792b043
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/<plugin_name>.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
}

Expand Down

0 comments on commit 792b043

Please sign in to comment.