-
Notifications
You must be signed in to change notification settings - Fork 95
Update plugin to support running as a Windows service #1624
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks great! Have a few nits and comments.
client_plugin/vmdk_plugin/main.go
Outdated
@@ -31,6 +31,10 @@ import ( | |||
// main for docker-volume-vsphere | |||
// Parses flags, initializes and mounts refcounters and finally initializes the server. | |||
func main() { | |||
runVdvs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a better name? May be startDaemon()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startDaemon looks better.
@@ -0,0 +1,21 @@ | |||
// Copyright 2016-2017 VMware, Inc. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove 2016
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// A VMDK Docker Data Volume plugin for Linux | ||
package main | ||
|
||
// Run vDVS plugin on Linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should the comment start with the function name itself? That comes from Effective Go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm aware of that convention. My understanding is: exported functions should follow this convention so that godoc can generate the documents properly. Unexported functions shouldn't really matter. But anyway, I will still fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, just for consistency sake.
|
||
func (p *program) Stop(s service.Service) error { | ||
// Stop should not block. Return directly. | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A query: does the service actually stop without us having to handle anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it stops properly. I didn't see anything unexpected when stopping the service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
return nil | ||
} | ||
|
||
// Run vDVS plugin on Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: function comment style, like above.
log "github.com/Sirupsen/logrus" | ||
) | ||
|
||
var logger service.Logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, logger
is only used inside runVdvs()
, so can have it as a local member there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine. I was thinking we might need to add more service logs to Start/Stop in the future. But anyway, we can add it whenever we really need it.
|
||
var logger service.Logger | ||
|
||
type program struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name it differently? May be pluginService
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with either one, as both will not affect the readability of this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add a comment explaining the need to have the service code for Windows, specifically about the Windows service timing-out because of the infinitely blocking startPluginServer()
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add some comments.
|
||
func (p *program) Start(s service.Service) error { | ||
// Start should not block. Do the actual work async. | ||
go p.run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just do go startPluginServer()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but I think we'd better keep Start() as a wrapper of run(), in case we may need to add some logic into run() in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
// pluginServer is a wrapper for vDVS plugin so that the plugin can be run | ||
// as a service on Windows. Windows controls services by setting up callbacks | ||
// that is non-trivial. This wrapper utilizes a vendor library to handle this. | ||
type pluginServer struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have another PluginServer
in our project, so I'm not sure if we should name this something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change it to PluginService then. Let me know if you have better suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is good :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good.
client_plugin/vmdk_plugin/main.go
Outdated
@@ -31,6 +31,11 @@ import ( | |||
// main for docker-volume-vsphere | |||
// Parses flags, initializes and mounts refcounters and finally initializes the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code which parses flags is moved to startPluginServer. So should move this comment to that function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
|
||
logger, err := svc.Logger(nil) | ||
if err != nil { | ||
log.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about log.Fatal("Failed to get logger : ", err)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
@shaominchen |
Fixes issue #1623.
Note: this PR changes the plugin server code so that the plugin can be run as a Windows service. The Windows service installation related logic will be handled in a separate PR.
Testing done: manually registered vdvs.exe as a Windows service - start/stop the service successfully and docker volume ops ran smoothly.