Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Update plugin to support running as a Windows service #1624

Merged
merged 6 commits into from
Jul 24, 2017
Merged

Conversation

shaominchen
Copy link
Contributor

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.

@shaominchen shaominchen changed the title Refactor plugin main function to support Windows platform Update plugin to support running as a Windows service Jul 22, 2017
Copy link
Contributor

@venilnoronha venilnoronha left a 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.

@@ -31,6 +31,10 @@ import (
// main for docker-volume-vsphere
// Parses flags, initializes and mounts refcounters and finally initializes the server.
func main() {
runVdvs()
Copy link
Contributor

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()?

Copy link
Contributor Author

@shaominchen shaominchen Jul 22, 2017

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove 2016

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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{}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@venilnoronha venilnoronha Jul 22, 2017

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.

Copy link
Contributor Author

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()
Copy link
Contributor

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()?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright.

Copy link
Contributor

@venilnoronha venilnoronha left a 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{}
Copy link
Contributor

@venilnoronha venilnoronha Jul 22, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is good :)

Copy link
Contributor

@lipingxue lipingxue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good.

@@ -31,6 +31,11 @@ import (
// main for docker-volume-vsphere
// Parses flags, initializes and mounts refcounters and finally initializes the server.
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@luomiao
Copy link
Contributor

luomiao commented Jul 25, 2017

@shaominchen
Sorry to bring back a merged PR.
This file:
client_plugin/vmdk_plugin/main_windows.go
the format (indent) seems wrong.
Everytime after I did a build, this file will be changed by go's formatting tool.
Can you update it with the correct format?

@shaominchen
Copy link
Contributor Author

@luomiao Fixed with PR #1630. Sorry for the confusion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants