blob: 78f147b79c74503f8a714113684c12b9bf9e1958 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package reload
import (
"github.com/spiral/roadrunner/service"
"os"
"time"
)
// ID contains default service name.
const ID = "reload"
type Service struct {
reloadConfig *Config
container service.Container
}
// Init controller service
func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
s.container = c
s.reloadConfig = cfg
return true, nil
}
func (s *Service) Serve() error {
w, err := NewWatcher(SetMaxFileEvents(100))
if err != nil {
return err
}
name , err := os.Getwd()
if err != nil {
return err
}
err = w.AddSingle(name)
if err != nil {
return err
}
go func() {
err = w.StartPolling(time.Second)
if err != nil {
}
}()
// read events and restart corresponding services
for {
select {
case e := <- w.Event:
println(e.Name())
}
}
//for e = range w.Event {
//
// println("event")
// // todo use status
// //svc, _ := s.container.Get("http")
// //if svc != nil {
// // if srv, ok := svc.(service.Service); ok {
// // srv.Stop()
// // err = srv.Serve()
// // if err != nil {
// // return err
// // }
// // }
// //}
//
// //println("event skipped due to service is nil")
//}
return nil
}
func (s *Service) Stop() {
}
|