Debian Codegraph @

service_test.go

raw symbols SCIP
1 package service_test
2
3 import "gopkg.in/hlandau/service.v2"
4
5 // The following example illustrates the minimal skeleton structure to
6 // implement a daemon. This example can run as a service on Windows or a daemon
7 // on Linux. The systemd notify protocol is supported.
8 func Example() {
9 service.Main(&service.Info{
10 Title: "Foobar Web Server",
11 Name: "foobar",
12 Description: "Foobar Web Server is the greatest webserver ever.",
13
14 RunFunc: func(smgr service.Manager) error {
15 // Start up your service.
16 // ...
17
18 // Once initialization requiring root is done, call this.
19 err := smgr.DropPrivileges()
20 if err != nil {
21 return err
22 }
23
24 // When it is ready to serve requests, call this.
25 // You must call DropPrivileges first.
26 smgr.SetStarted()
27
28 // Optionally set a status
29 smgr.SetStatus("foobar: running ok")
30
31 loop:
32 for {
33 select {
34 // Handle requests, or do so in another goroutine controlled from here.
35 case <-smgr.StopChan():
36 break loop
37 }
38 }
39
40 // Do any necessary teardown.
41 // ...
42
43 return nil
44 },
45 })
46 }
47
48 // © 2015 Hugo Landau <[email protected]> ISC License