diff options
-rw-r--r-- | cmd/rr/.rr.yaml | 4 | ||||
-rw-r--r-- | server_config.go | 26 | ||||
-rw-r--r-- | server_config_test.go | 60 | ||||
-rw-r--r-- | worker.go | 2 |
4 files changed, 87 insertions, 5 deletions
diff --git a/cmd/rr/.rr.yaml b/cmd/rr/.rr.yaml index 6e3b689b..5ccf73e9 100644 --- a/cmd/rr/.rr.yaml +++ b/cmd/rr/.rr.yaml @@ -42,6 +42,10 @@ http: # php worker command. command: "php /Users/wolfy-j/Projects/phpapp/webroot/index.php rr pipes --no-ansi" + user: "wolfy-j" + + group: "wolfy-j" + # connection method (pipes, tcp://:9000, unix://socket.unix). relay: "pipes" diff --git a/server_config.go b/server_config.go index 37f3359b..99eaa678 100644 --- a/server_config.go +++ b/server_config.go @@ -5,6 +5,7 @@ import ( "net" "strings" "time" + "os/exec" ) const ( @@ -12,7 +13,20 @@ const ( FactorySocket ) +// Server config combines factory, pool and cmd configurations. type ServerConfig struct { + // Command includes command strings with all the parameters, example: "php worker.php pipes". This config section + // // must not change on re-configuration. + Command string + + // User specifies what user to run command under, for Unix systems only. Support both UID and name options. Keep + // empty to use current user.This config section must not change on re-configuration. + User string + + // Group specifies what group to run command under, for Unix systems only. Support GID or name options. Keep empty + // to use current user.This config section must not change on re-configuration. + Group string + // Relay defines connection method and factory to be used to connect to workers: // "pipes", "tcp://:6001", "unix://rr.sock" // This config section must not change on re-configuration. @@ -24,12 +38,16 @@ type ServerConfig struct { // Pool defines worker pool configuration, number of workers, timeouts and etc. This config section might change // while server is running. - Pool Config + Pool *Config +} + +func (f *ServerConfig) makeCommand() (func() *exec.Cmd, error) { + return nil, nil } -// buildFactory creates and connects new factory instance based on given parameters. -func (f *ServerConfig) buildFactory() (Factory, error) { - if f.Relay == "pipes" { +// makeFactory creates and connects new factory instance based on given parameters. +func (f *ServerConfig) makeFactory() (Factory, error) { + if f.Relay == "pipes" || f.Relay == "pipe" { return NewPipeFactory(), nil } diff --git a/server_config_test.go b/server_config_test.go new file mode 100644 index 00000000..667cfced --- /dev/null +++ b/server_config_test.go @@ -0,0 +1,60 @@ +package roadrunner + +import ( + "testing" + "github.com/stretchr/testify/assert" +) + +func Test_ServerConfig_PipeFactory(t *testing.T) { + cfg := &ServerConfig{Relay: "pipes"} + f, err := cfg.makeFactory() + + assert.NoError(t, err) + assert.IsType(t, &PipeFactory{}, f) + + cfg = &ServerConfig{Relay: "pipe"} + f, err = cfg.makeFactory() + defer f.Close() + + assert.NoError(t, err) + assert.IsType(t, &PipeFactory{}, f) +} + +func Test_ServerConfig_SocketFactory(t *testing.T) { + cfg := &ServerConfig{Relay: "tcp://:9000"} + f, err := cfg.makeFactory() + defer f.Close() + + assert.NoError(t, err) + assert.IsType(t, &SocketFactory{}, f) + assert.Equal(t, "tcp", f.(*SocketFactory).ls.Addr().Network(), ) + assert.Equal(t, "[::]:9000", f.(*SocketFactory).ls.Addr().String()) + + cfg = &ServerConfig{Relay: "tcp://localhost:9000"} + f, err = cfg.makeFactory() + defer f.Close() + + assert.NoError(t, err) + assert.IsType(t, &SocketFactory{}, f) + assert.Equal(t, "tcp", f.(*SocketFactory).ls.Addr().Network()) + assert.Equal(t, "127.0.0.1:9000", f.(*SocketFactory).ls.Addr().String()) +} + +func Test_ServerConfig_UnixSocketFactory(t *testing.T) { + cfg := &ServerConfig{Relay: "unix://unix.sock"} + f, err := cfg.makeFactory() + defer f.Close() + + assert.NoError(t, err) + assert.IsType(t, &SocketFactory{}, f) + assert.Equal(t, "unix", f.(*SocketFactory).ls.Addr().Network()) + assert.Equal(t, "unix.sock", f.(*SocketFactory).ls.Addr().String()) +} + +func Test_ServerConfig_ErrorFactory(t *testing.T) { + cfg := &ServerConfig{Relay: "uni:unix.sock"} + f, err := cfg.makeFactory() + assert.Nil(t, f) + assert.Error(t, err) + assert.Equal(t, "invalid relay DSN (pipes, tcp://:6001, unix://rr.sock)", err.Error()) +} @@ -30,7 +30,7 @@ type Worker struct { state *state // underlying command with associated process, command must be - // provided to worker from outside in non-started form. Cmd + // provided to worker from outside in non-started form. CmdSource // stdErr direction will be handled by worker to aggregate error message. cmd *exec.Cmd |