Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point to godoc.org in the README. #50

Open
santhosh-kumar opened this issue Feb 11, 2016 · 2 comments
Open

Point to godoc.org in the README. #50

santhosh-kumar opened this issue Feb 11, 2016 · 2 comments

Comments

@santhosh-kumar
Copy link

Thanks for the library. I went through the example and used simple as reference: https://github.com/kardianos/service/blob/master/example/simple/main.go

Here is my run function:

// run the program
func (p *program) run() {
configuration := InitConfiguration()

log.Printf("Running Web Socket Server")

c := wsServer.NewServer()
c.Run(port)

}

When I run my app using:

$GOROOT/bin/myApp

My app seems to block the run call forever, I was expecting Run to be executed in the background. Am I missing something here?

It would be great if you can update the README.md with additional information on usage.

Thanks once again.

@kardianos
Copy link
Owner

Have you read https://godoc.org/github.com/kardianos/service ?

From the docs:

type Service interface {
    // Run should be called shortly after the program entry point.
    // After Interface.Stop has finished running, Run will stop blocking.
    // After Run stops blocking, the program must exit shortly after.
    Run() error
...
}

From this I can see that (a) Run blocks, (b) when Run returns, the program should exit.

Your work should be done in:

type Interface interface {
    // Start provides a place to initiate the service. The service doesn't not
    // signal a completed start until after this function returns, so the
    // Start function must not take more then a few seconds at most.
    Start(s Service) error

    // Stop provides a place to clean up program execution before it is terminated.
    // It should not take more then a few seconds to execute.
    // Stop should not call os.Exit directly in the function.
    Stop(s Service) error
}

Pay attention to "Start function must not take more then a few seconds at most.", meaning you need to run go doRealWork() in Start().

@kardianos kardianos changed the title How to use the service? Point to godoc.org in the README. Feb 14, 2016
turtlemonvh added a commit to turtlemonvh/service that referenced this issue Mar 1, 2016
@AlekSi
Copy link
Contributor

AlekSi commented Nov 13, 2017

I think that one can be closed.

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

No branches or pull requests

3 participants