Skip to content

Commit

Permalink
Merge pull request #1822 from owncloud/runtime-hostname-port-configur…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
refs authored Mar 18, 2021
2 parents 29897ca + 61a15be commit d183cdb
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 25 deletions.
17 changes: 17 additions & 0 deletions changelog/unreleased/runtime-address-configurable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Enhancement: Runtime Hostname and Port are now configurable

Without any configuration the ocis runtime will start on `localhost:9250` unless specified otherwise. Usage:

- `OCIS_RUNTIME_PORT=6061 bin/ocis server`
- overrides the oCIS runtime and starts on port 6061
- `OCIS_RUNTIME_PORT=6061 bin/ocis list`
- lists running extensions for the runtime on `localhost:6061`

All subcommands are updated and expected to work with the following environment variables:

```
OCIS_RUNTIME_HOST
OCIS_RUNTIME_PORT
```

https://github.com/owncloud/ocis/pull/1822
7 changes: 7 additions & 0 deletions ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const (

type Mode int

// Runtime configures the oCIS runtime when running in supervised mode.
type Runtime struct {
Port string
Host string
}

// Config combines all available configuration parts.
type Config struct {
Mode Mode
Expand All @@ -80,6 +86,7 @@ type Config struct {
GRPC GRPC
Tracing Tracing
TokenManager TokenManager
Runtime Runtime

Accounts *accounts.Config
GLAuth *glauth.Config
Expand Down
16 changes: 9 additions & 7 deletions ocis/pkg/command/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ func KillCommand(cfg *config.Config) *cli.Command {
Category: "Runtime",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "hostname",
Value: "localhost",
EnvVars: []string{"OCIS_RUNTIME_HOSTNAME"},
Name: "hostname",
Value: "localhost",
EnvVars: []string{"OCIS_RUNTIME_HOST"},
Destination: &cfg.Runtime.Host,
},
&cli.StringFlag{
Name: "port",
Value: "6060",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Name: "port",
Value: "9250",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Destination: &cfg.Runtime.Port,
},
},
Action: func(c *cli.Context) error {
client, err := rpc.DialHTTP("tcp", net.JoinHostPort("localhost", "6060"))
client, err := rpc.DialHTTP("tcp", net.JoinHostPort(cfg.Runtime.Host, cfg.Runtime.Port))
if err != nil {
log.Fatal("dialing:", err)
}
Expand Down
16 changes: 9 additions & 7 deletions ocis/pkg/command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ func ListCommand(cfg *config.Config) *cli.Command {
Category: "Runtime",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "hostname",
Value: "localhost",
EnvVars: []string{"OCIS_RUNTIME_HOSTNAME"},
Name: "hostname",
Value: "localhost",
EnvVars: []string{"OCIS_RUNTIME_HOST"},
Destination: &cfg.Runtime.Host,
},
&cli.StringFlag{
Name: "port",
Value: "6060",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Name: "port",
Value: "9250",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Destination: &cfg.Runtime.Port,
},
},
Action: func(c *cli.Context) error {
client, err := rpc.DialHTTP("tcp", net.JoinHostPort("localhost", "6060"))
client, err := rpc.DialHTTP("tcp", net.JoinHostPort(cfg.Runtime.Host, cfg.Runtime.Port))
if err != nil {
log.Fatal("dialing:", err)
}
Expand Down
16 changes: 9 additions & 7 deletions ocis/pkg/command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ func RunCommand(cfg *config.Config) *cli.Command {
Category: "Runtime",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "hostname",
Value: "localhost",
EnvVars: []string{"OCIS_RUNTIME_HOSTNAME"},
Name: "hostname",
Value: "localhost",
EnvVars: []string{"OCIS_RUNTIME_HOST"},
Destination: &cfg.Runtime.Host,
},
&cli.StringFlag{
Name: "port",
Value: "6060",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Name: "port",
Value: "9250",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Destination: &cfg.Runtime.Port,
},
},
Action: func(c *cli.Context) error {
client, err := rpc.DialHTTP("tcp", net.JoinHostPort("localhost", "6060"))
client, err := rpc.DialHTTP("tcp", net.JoinHostPort(cfg.Runtime.Host, cfg.Runtime.Port))
if err != nil {
log.Fatal("dialing:", err)
}
Expand Down
14 changes: 14 additions & 0 deletions ocis/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"OCIS_JWT_SECRET"},
Destination: &cfg.TokenManager.JWTSecret,
},
&cli.StringFlag{
Name: "runtime-port",
Value: "9250",
Usage: "Configures which port the runtime starts",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
Destination: &cfg.Runtime.Port,
},
&cli.StringFlag{
Name: "runtime-host",
Value: "localhost",
Usage: "Configures the host where the runtime process is running",
EnvVars: []string{"OCIS_RUNTIME_HOST"},
Destination: &cfg.Runtime.Host,
},
}
}

Expand Down
6 changes: 2 additions & 4 deletions ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,15 @@ func Start(o ...Option) error {
halt := make(chan os.Signal, 1)
signal.Notify(halt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)

// TODO(refs) change default port
l, err := net.Listen("tcp", fmt.Sprintf("%v:%v", "localhost", "6060"))
l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port))
if err != nil {
s.Log.Fatal().Err(err)
}

defer func() {
if r := recover(); r != nil {
reason := strings.Builder{}
// TODO(refs) change default port
if _, err := net.Dial("localhost", "6060"); err != nil {
if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil {
reason.WriteString("runtime address already in use")
}

Expand Down

0 comments on commit d183cdb

Please sign in to comment.