Skip to content

Commit b0a4a0d

Browse files
authored
Merge pull request #252 from spiral/rr_1.6.2
release 1.6.2
2 parents 0bc6017 + 954fa52 commit b0a4a0d

17 files changed

+1176
-85
lines changed

.rr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static:
160160
health:
161161
# http host to serve health requests.
162162
address: localhost:2113
163-
163+
164164
# reload can reset rr servers when files change
165165
reload:
166166
# refresh internval (default 1s)
@@ -176,4 +176,4 @@ reload:
176176
dirs: [""]
177177

178178
# include sub directories
179-
recursive: true
179+
recursive: true

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ test:
2222
go test -v -race -cover ./service/metrics
2323
go test -v -race -cover ./service/health
2424
go test -v -race -cover ./service/gzip
25+
go test -v -race -cover ./service/reload
2526
lint:
2627
go fmt ./...
2728
golint ./...

build.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cd $(dirname "${BASH_SOURCE[0]}")
33
OD="$(pwd)"
44

55
# Pushes application version into the build information.
6-
RR_VERSION=1.6.1
6+
RR_VERSION=1.6.2
77

88
# Hardcode some values to the core package
99
LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${RR_VERSION}"
@@ -12,7 +12,7 @@ LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.BuildTime=$(date +%
1212
LDFLAGS="$LDFLAGS -s"
1313

1414
build(){
15-
echo Packaging $1 Build
15+
echo Packaging "$1" Build
1616
bdir=roadrunner-${RR_VERSION}-$2-$3
1717
rm -rf builds/"$bdir" && mkdir -p builds/"$bdir"
1818
GOOS=$2 GOARCH=$3 ./build.sh
@@ -29,12 +29,12 @@ build(){
2929
cd builds
3030

3131
if [ "$2" == "linux" ]; then
32-
tar -zcf $bdir.tar.gz $bdir
32+
tar -zcf "$bdir".tar.gz "$bdir"
3333
else
34-
zip -r -q $bdir.zip $bdir
34+
zip -r -q "$bdir".zip "$bdir"
3535
fi
3636

37-
rm -rf $bdir
37+
rm -rf "$bdir"
3838
cd ..
3939
}
4040

cmd/rr/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/spiral/roadrunner/service/http"
3434
"github.com/spiral/roadrunner/service/limit"
3535
"github.com/spiral/roadrunner/service/metrics"
36+
"github.com/spiral/roadrunner/service/reload"
3637
"github.com/spiral/roadrunner/service/rpc"
3738
"github.com/spiral/roadrunner/service/static"
3839

@@ -51,6 +52,7 @@ func main() {
5152
rr.Container.Register(limit.ID, &limit.Service{})
5253
rr.Container.Register(health.ID, &health.Service{})
5354
rr.Container.Register(gzip.ID, &gzip.Service{})
55+
rr.Container.Register(reload.ID, &reload.Service{})
5456

5557
// you can register additional commands using cmd.CLI
5658
rr.Execute()

controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ type Controller interface {
88
// Detach pool watching.
99
Detach()
1010
}
11+
12+
// Attacher defines the ability to attach rr controller.
13+
type Attacher interface {
14+
// Attach attaches controller to the service.
15+
Attach(c Controller)
16+
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require (
1010
github.com/go-ole/go-ole v1.2.4 // indirect
1111
github.com/mattn/go-colorable v0.1.4 // indirect
1212
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
13+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
14+
github.com/modern-go/reflect2 v1.0.1 // indirect
1315
github.com/olekukonko/tablewriter v0.0.4
1416
github.com/pkg/errors v0.9.1
1517
github.com/prometheus/client_golang v1.4.1

server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const (
2323
EventPoolDestruct
2424
)
2525

26+
// Controllable defines the ability to attach rr controller.
27+
type Controllable interface {
28+
// Server represents RR server
29+
Server() *Server
30+
}
31+
2632
// Server manages pool creation and swapping.
2733
type Server struct {
2834
// configures server, pool, cmd creation and factory.

service/gzip/service_test.go

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,6 @@ func (cfg *testCfg) Unmarshal(out interface{}) error {
3131
return json.Unmarshal([]byte(cfg.target), out)
3232
}
3333

34-
//func get(url string) (string, *http.Response, error) {
35-
// r, err := http.Get(url)
36-
// if err != nil {
37-
// return "", nil, err
38-
// }
39-
//
40-
// b, err := ioutil.ReadAll(r.Body)
41-
// if err != nil {
42-
// return "", nil, err
43-
// }
44-
//
45-
// err = r.Body.Close()
46-
// if err != nil {
47-
// return "", nil, err
48-
// }
49-
//
50-
// return string(b), r, err
51-
//}
5234

5335
func Test_Disabled(t *testing.T) {
5436
logger, _ := test.NewNullLogger()
@@ -65,56 +47,3 @@ func Test_Disabled(t *testing.T) {
6547
assert.NotNil(t, s)
6648
assert.Equal(t, service.StatusInactive, st)
6749
}
68-
69-
// func Test_Files(t *testing.T) {
70-
// logger, _ := test.NewNullLogger()
71-
// logger.SetLevel(logrus.DebugLevel)
72-
73-
// c := service.NewContainer(logger)
74-
// c.Register(rrhttp.ID, &rrhttp.Service{})
75-
// c.Register(ID, &Service{})
76-
77-
// assert.NoError(t, c.Init(&testCfg{
78-
// gzip: `{"enable":true}`,
79-
// static: `{"enable":true, "dir":"../../tests", "forbid":[]}`,
80-
// httpCfg: `{
81-
// "enable": true,
82-
// "address": ":6029",
83-
// "maxRequestSize": 1024,
84-
// "uploads": {
85-
// "dir": ` + tmpDir() + `,
86-
// "forbid": []
87-
// },
88-
// "workers":{
89-
// "command": "php ../../tests/http/client.php pid pipes",
90-
// "relay": "pipes",
91-
// "pool": {
92-
// "numWorkers": 1,
93-
// "allocateTimeout": 10000000,
94-
// "destroyTimeout": 10000000
95-
// }
96-
// }
97-
// }`}))
98-
99-
// go func() {
100-
// err := c.Serve()
101-
// if err != nil {
102-
// t.Errorf("serve error: %v", err)
103-
// }
104-
// }()
105-
// time.Sleep(time.Millisecond * 1000)
106-
// defer c.Stop()
107-
108-
// b, _, _ := get("http://localhost:6029/sample.txt")
109-
// assert.Equal(t, "sample", b)
110-
// //header should not contain content-encoding:gzip because content-length < gziphandler.DefaultMinSize
111-
// // b, _, _ := get("http://localhost:6029/gzip-large-file.txt")
112-
// //header should contain content-encoding:gzip because content-length > gziphandler.DefaultMinSize
113-
// }
114-
115-
//func tmpDir() string {
116-
// p := os.TempDir()
117-
// r, _ := json.Marshal(p)
118-
//
119-
// return string(r)
120-
//}

service/limit/service.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ import (
88
// ID defines controller service name.
99
const ID = "limit"
1010

11-
// controllable defines the ability to attach rr controller.
12-
type controllable interface {
13-
// Attach attaches controller to the service.
14-
Attach(c roadrunner.Controller)
15-
}
16-
1711
// Service to control the state of rr service inside other services.
1812
type Service struct {
1913
lsns []func(event int, ctx interface{})
@@ -24,7 +18,7 @@ func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
2418
// mount Services to designated services
2519
for id, watcher := range cfg.Controllers(s.throw) {
2620
svc, _ := c.Get(id)
27-
if ctrl, ok := svc.(controllable); ok {
21+
if ctrl, ok := svc.(roadrunner.Attacher); ok {
2822
ctrl.Attach(watcher)
2923
}
3024
}

service/reload/config.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package reload
2+
3+
import (
4+
"errors"
5+
"github.com/spiral/roadrunner"
6+
"github.com/spiral/roadrunner/service"
7+
"time"
8+
)
9+
10+
// Config is a Reload configuration point.
11+
type Config struct {
12+
// Interval is a global refresh interval
13+
Interval time.Duration
14+
15+
// Patterns is a global file patterns to watch. It will be applied to every directory in project
16+
Patterns []string
17+
18+
// Services is set of services which would be reloaded in case of FS changes
19+
Services map[string]ServiceConfig
20+
}
21+
22+
type ServiceConfig struct {
23+
// Enabled indicates that service must be watched, doest not required when any other option specified
24+
Enabled bool
25+
26+
// Recursive is options to use nested files from root folder
27+
Recursive bool
28+
29+
// Patterns is per-service specific files to watch
30+
Patterns []string
31+
32+
// Dirs is per-service specific dirs which will be combined with Patterns
33+
Dirs []string
34+
35+
// Ignore is set of files which would not be watched
36+
Ignore []string
37+
38+
// service is a link to service to restart
39+
service *roadrunner.Controllable
40+
}
41+
42+
// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
43+
func (c *Config) Hydrate(cfg service.Config) error {
44+
if err := cfg.Unmarshal(c); err != nil {
45+
return err
46+
}
47+
48+
return nil
49+
}
50+
51+
// InitDefaults sets missing values to their default values.
52+
func (c *Config) InitDefaults() error {
53+
c.Interval = time.Second
54+
c.Patterns = []string{".php"}
55+
56+
return nil
57+
}
58+
59+
// Valid validates the configuration.
60+
func (c *Config) Valid() error {
61+
if c.Interval < time.Second {
62+
return errors.New("too short interval")
63+
}
64+
65+
return nil
66+
}

0 commit comments

Comments
 (0)