From 385d6ecc4841d64466232a83c01b72e53f8c7dbb Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 18 Mar 2021 15:23:36 +0100 Subject: [PATCH 1/3] make runtime port and host configurable --- ocis-pkg/config/config.go | 7 +++++++ ocis/pkg/command/kill.go | 16 +++++++++------- ocis/pkg/command/list.go | 16 +++++++++------- ocis/pkg/command/run.go | 16 +++++++++------- ocis/pkg/flagset/flagset.go | 14 ++++++++++++++ ocis/pkg/runtime/service/service.go | 6 ++---- 6 files changed, 50 insertions(+), 25 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 2e484880d6..5b0ddfcf43 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -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 @@ -80,6 +86,7 @@ type Config struct { GRPC GRPC Tracing Tracing TokenManager TokenManager + Runtime Runtime Accounts *accounts.Config GLAuth *glauth.Config diff --git a/ocis/pkg/command/kill.go b/ocis/pkg/command/kill.go index 6b673473f4..07c29edf5f 100644 --- a/ocis/pkg/command/kill.go +++ b/ocis/pkg/command/kill.go @@ -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_HOSTNAME"}, + Destination: &cfg.Runtime.Host, }, &cli.StringFlag{ - Name: "port", - Value: "6060", - EnvVars: []string{"OCIS_RUNTIME_PORT"}, + Name: "port", + Value: "6060", + 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) } diff --git a/ocis/pkg/command/list.go b/ocis/pkg/command/list.go index 0e04647165..cb91e0cf95 100644 --- a/ocis/pkg/command/list.go +++ b/ocis/pkg/command/list.go @@ -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_HOSTNAME"}, + Destination: &cfg.Runtime.Host, }, &cli.StringFlag{ - Name: "port", - Value: "6060", - EnvVars: []string{"OCIS_RUNTIME_PORT"}, + Name: "port", + Value: "6060", + 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) } diff --git a/ocis/pkg/command/run.go b/ocis/pkg/command/run.go index ae45e7dc7e..07936a7cc0 100644 --- a/ocis/pkg/command/run.go +++ b/ocis/pkg/command/run.go @@ -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_HOSTNAME"}, + Destination: &cfg.Runtime.Host, }, &cli.StringFlag{ - Name: "port", - Value: "6060", - EnvVars: []string{"OCIS_RUNTIME_PORT"}, + Name: "port", + Value: "6060", + 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) } diff --git a/ocis/pkg/flagset/flagset.go b/ocis/pkg/flagset/flagset.go index fb43c6cab6..77d113b70b 100644 --- a/ocis/pkg/flagset/flagset.go +++ b/ocis/pkg/flagset/flagset.go @@ -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: "6060", + 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, + }, } } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 7eeb49f836..d8a80dcc3c 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -149,8 +149,7 @@ 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) } @@ -158,8 +157,7 @@ func Start(o ...Option) error { 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") } From 25ea46324fb2a1bc0b8c90c8246012909796e7b0 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 18 Mar 2021 15:27:45 +0100 Subject: [PATCH 2/3] add changelog + rename OCIS_RUNTIME_HOSTNAME -> OCIS_RUNTIME_HOST --- .../unreleased/runtime-address-configurable.md | 17 +++++++++++++++++ ocis/pkg/command/kill.go | 2 +- ocis/pkg/command/list.go | 2 +- ocis/pkg/command/run.go | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/runtime-address-configurable.md diff --git a/changelog/unreleased/runtime-address-configurable.md b/changelog/unreleased/runtime-address-configurable.md new file mode 100644 index 0000000000..16a2906b30 --- /dev/null +++ b/changelog/unreleased/runtime-address-configurable.md @@ -0,0 +1,17 @@ +Enhancement: Runtime Hostname and Port are now configurable + +Without any configuration the ocis runtime will start on `localhost:6060` 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 diff --git a/ocis/pkg/command/kill.go b/ocis/pkg/command/kill.go index 07c29edf5f..3e09793adb 100644 --- a/ocis/pkg/command/kill.go +++ b/ocis/pkg/command/kill.go @@ -22,7 +22,7 @@ func KillCommand(cfg *config.Config) *cli.Command { &cli.StringFlag{ Name: "hostname", Value: "localhost", - EnvVars: []string{"OCIS_RUNTIME_HOSTNAME"}, + EnvVars: []string{"OCIS_RUNTIME_HOST"}, Destination: &cfg.Runtime.Host, }, &cli.StringFlag{ diff --git a/ocis/pkg/command/list.go b/ocis/pkg/command/list.go index cb91e0cf95..62fd0a8e46 100644 --- a/ocis/pkg/command/list.go +++ b/ocis/pkg/command/list.go @@ -21,7 +21,7 @@ func ListCommand(cfg *config.Config) *cli.Command { &cli.StringFlag{ Name: "hostname", Value: "localhost", - EnvVars: []string{"OCIS_RUNTIME_HOSTNAME"}, + EnvVars: []string{"OCIS_RUNTIME_HOST"}, Destination: &cfg.Runtime.Host, }, &cli.StringFlag{ diff --git a/ocis/pkg/command/run.go b/ocis/pkg/command/run.go index 07936a7cc0..bf2d55a29c 100644 --- a/ocis/pkg/command/run.go +++ b/ocis/pkg/command/run.go @@ -23,7 +23,7 @@ func RunCommand(cfg *config.Config) *cli.Command { &cli.StringFlag{ Name: "hostname", Value: "localhost", - EnvVars: []string{"OCIS_RUNTIME_HOSTNAME"}, + EnvVars: []string{"OCIS_RUNTIME_HOST"}, Destination: &cfg.Runtime.Host, }, &cli.StringFlag{ From 61a15be7a81ed293a401dd23c4c0ac040289f24d Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 18 Mar 2021 15:38:36 +0100 Subject: [PATCH 3/3] update default port to 9250 --- changelog/unreleased/runtime-address-configurable.md | 2 +- ocis/pkg/command/kill.go | 2 +- ocis/pkg/command/list.go | 2 +- ocis/pkg/command/run.go | 2 +- ocis/pkg/flagset/flagset.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/changelog/unreleased/runtime-address-configurable.md b/changelog/unreleased/runtime-address-configurable.md index 16a2906b30..8bba5a62bc 100644 --- a/changelog/unreleased/runtime-address-configurable.md +++ b/changelog/unreleased/runtime-address-configurable.md @@ -1,6 +1,6 @@ Enhancement: Runtime Hostname and Port are now configurable -Without any configuration the ocis runtime will start on `localhost:6060` unless specified otherwise. Usage: +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 diff --git a/ocis/pkg/command/kill.go b/ocis/pkg/command/kill.go index 3e09793adb..e96e4a057c 100644 --- a/ocis/pkg/command/kill.go +++ b/ocis/pkg/command/kill.go @@ -27,7 +27,7 @@ func KillCommand(cfg *config.Config) *cli.Command { }, &cli.StringFlag{ Name: "port", - Value: "6060", + Value: "9250", EnvVars: []string{"OCIS_RUNTIME_PORT"}, Destination: &cfg.Runtime.Port, }, diff --git a/ocis/pkg/command/list.go b/ocis/pkg/command/list.go index 62fd0a8e46..137f1331c3 100644 --- a/ocis/pkg/command/list.go +++ b/ocis/pkg/command/list.go @@ -26,7 +26,7 @@ func ListCommand(cfg *config.Config) *cli.Command { }, &cli.StringFlag{ Name: "port", - Value: "6060", + Value: "9250", EnvVars: []string{"OCIS_RUNTIME_PORT"}, Destination: &cfg.Runtime.Port, }, diff --git a/ocis/pkg/command/run.go b/ocis/pkg/command/run.go index bf2d55a29c..273bb1d3e5 100644 --- a/ocis/pkg/command/run.go +++ b/ocis/pkg/command/run.go @@ -28,7 +28,7 @@ func RunCommand(cfg *config.Config) *cli.Command { }, &cli.StringFlag{ Name: "port", - Value: "6060", + Value: "9250", EnvVars: []string{"OCIS_RUNTIME_PORT"}, Destination: &cfg.Runtime.Port, }, diff --git a/ocis/pkg/flagset/flagset.go b/ocis/pkg/flagset/flagset.go index 77d113b70b..1267d64753 100644 --- a/ocis/pkg/flagset/flagset.go +++ b/ocis/pkg/flagset/flagset.go @@ -84,7 +84,7 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "runtime-port", - Value: "6060", + Value: "9250", Usage: "Configures which port the runtime starts", EnvVars: []string{"OCIS_RUNTIME_PORT"}, Destination: &cfg.Runtime.Port,