From a793a4d1e6ebbb9b5edfadfaba8a1c0103350746 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 9 May 2022 11:31:26 +0200 Subject: [PATCH 1/3] remove run and kill commands from the runtime --- ...change-remove-runtime-kill-run-commands.md | 10 ++++ ocis/pkg/command/kill.go | 55 ------------------ ocis/pkg/command/run.go | 56 ------------------- 3 files changed, 10 insertions(+), 111 deletions(-) create mode 100644 changelog/unreleased/change-remove-runtime-kill-run-commands.md delete mode 100644 ocis/pkg/command/kill.go delete mode 100644 ocis/pkg/command/run.go diff --git a/changelog/unreleased/change-remove-runtime-kill-run-commands.md b/changelog/unreleased/change-remove-runtime-kill-run-commands.md new file mode 100644 index 00000000000..84068ab38a3 --- /dev/null +++ b/changelog/unreleased/change-remove-runtime-kill-run-commands.md @@ -0,0 +1,10 @@ +Bugfix: Remove runtime kill and run commands + +We've removed the kill and run commands from the oCIS runtime. +If these dynamic capabilities are needed, one should switch to a full fledged +supervisor and start oCIS as individual services. + +If one wants to start a only a subset of services, this is still possible +by setting OCIS_RUN_EXTENSIONS. + +https://github.com/owncloud/ocis/pull/3740 diff --git a/ocis/pkg/command/kill.go b/ocis/pkg/command/kill.go deleted file mode 100644 index 27770ece2ae..00000000000 --- a/ocis/pkg/command/kill.go +++ /dev/null @@ -1,55 +0,0 @@ -package command - -import ( - "fmt" - "log" - "net" - "net/rpc" - "os" - - "github.com/owncloud/ocis/v2/ocis-pkg/config" - "github.com/owncloud/ocis/v2/ocis/pkg/register" - "github.com/urfave/cli/v2" -) - -// KillCommand is the entrypoint for the kill command. -func KillCommand(cfg *config.Config) *cli.Command { - return &cli.Command{ - Name: "kill", - Usage: "kill an extension by name in the runtime (supervised mode)", - Category: "runtime", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "hostname", - Value: "localhost", - EnvVars: []string{"OCIS_RUNTIME_HOST"}, - Destination: &cfg.Runtime.Host, - }, - &cli.StringFlag{ - 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(cfg.Runtime.Host, cfg.Runtime.Port)) - if err != nil { - log.Fatalf("Failed to connect to the runtime. Has the runtime been started and did you configure the right runtime address (\"%s\")", cfg.Runtime.Host+":"+cfg.Runtime.Port) - } - - var arg1 int - - if err := client.Call("Service.Kill", os.Args[2], &arg1); err != nil { - log.Fatal(err) - } - fmt.Printf("process %v terminated", os.Args[2]) - - return nil - }, - } -} - -func init() { - register.AddCommand(KillCommand) -} diff --git a/ocis/pkg/command/run.go b/ocis/pkg/command/run.go deleted file mode 100644 index d5e264f4471..00000000000 --- a/ocis/pkg/command/run.go +++ /dev/null @@ -1,56 +0,0 @@ -package command - -import ( - "fmt" - "log" - "net" - "net/rpc" - "os" - - cli "github.com/urfave/cli/v2" - - "github.com/owncloud/ocis/v2/ocis-pkg/config" - "github.com/owncloud/ocis/v2/ocis/pkg/register" -) - -// RunCommand is the entrypoint for the run command. -func RunCommand(cfg *config.Config) *cli.Command { - return &cli.Command{ - Name: "run", - Usage: "run an extension by name in the runtime (supervised mode)", - Category: "runtime", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "hostname", - Value: "localhost", - EnvVars: []string{"OCIS_RUNTIME_HOST"}, - Destination: &cfg.Runtime.Host, - }, - &cli.StringFlag{ - 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(cfg.Runtime.Host, cfg.Runtime.Port)) - if err != nil { - log.Fatalf("Failed to connect to the runtime. Has the runtime been started and did you configure the right runtime address (\"%s\")", cfg.Runtime.Host+":"+cfg.Runtime.Port) - } - - var reply int - - if err := client.Call("Service.Start", os.Args[2], &reply); err != nil { - log.Fatal(err) - } - fmt.Println(reply) - - return nil - }, - } -} - -func init() { - register.AddCommand(RunCommand) -} From 53e26f8ad252215983cbb3a0afab46ab98a6882d Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 9 May 2022 11:32:46 +0200 Subject: [PATCH 2/3] remove run / kill from docs --- docs/ocis/getting-started/_index.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/ocis/getting-started/_index.md b/docs/ocis/getting-started/_index.md index 5a31560b831..e6d2619358c 100644 --- a/docs/ocis/getting-started/_index.md +++ b/docs/ocis/getting-started/_index.md @@ -112,16 +112,6 @@ The list command prints all running oCIS extensions. ocis list {{< / highlight >}} -To stop a particular extension: -{{< highlight txt >}} -ocis kill web -{{< / highlight >}} - -To start a particular extension: -{{< highlight txt >}} -ocis run web -{{< / highlight >}} - The version command prints the version of your installed oCIS. {{< highlight txt >}} ocis --version From 0453dba7a37b02f7c9f9dd6c0989a00684aa0e3a Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 9 May 2022 13:23:17 +0200 Subject: [PATCH 3/3] remove rpc side of kill and run commands --- ocis/pkg/runtime/cmd/kill.go | 35 ----------------------------- ocis/pkg/runtime/cmd/run.go | 33 --------------------------- ocis/pkg/runtime/service/service.go | 35 ----------------------------- 3 files changed, 103 deletions(-) delete mode 100644 ocis/pkg/runtime/cmd/kill.go delete mode 100644 ocis/pkg/runtime/cmd/run.go diff --git a/ocis/pkg/runtime/cmd/kill.go b/ocis/pkg/runtime/cmd/kill.go deleted file mode 100644 index 42622bb3db2..00000000000 --- a/ocis/pkg/runtime/cmd/kill.go +++ /dev/null @@ -1,35 +0,0 @@ -package cmd - -import ( - "fmt" - "log" - "net" - "net/rpc" - - "github.com/owncloud/ocis/v2/ocis/pkg/runtime/config" - "github.com/spf13/cobra" -) - -// Kill an extension. -func Kill(cfg *config.Config) *cobra.Command { - return &cobra.Command{ - Use: "kill", - Aliases: []string{"k"}, - Short: "Kill a running extensions.", - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - client, err := rpc.DialHTTP("tcp", net.JoinHostPort(cfg.Hostname, cfg.Port)) - if err != nil { - log.Fatal("dialing:", err) - } - - var arg1 int - - if err := client.Call("Service.Kill", &args[0], &arg1); err != nil { - log.Fatal(err) - } - - fmt.Println(arg1) - }, - } -} diff --git a/ocis/pkg/runtime/cmd/run.go b/ocis/pkg/runtime/cmd/run.go deleted file mode 100644 index 83b82add333..00000000000 --- a/ocis/pkg/runtime/cmd/run.go +++ /dev/null @@ -1,33 +0,0 @@ -package cmd - -import ( - "fmt" - "log" - "net" - "net/rpc" - - "github.com/owncloud/ocis/v2/ocis/pkg/runtime/config" - "github.com/spf13/cobra" -) - -// Run an extension. -func Run(cfg *config.Config) *cobra.Command { - return &cobra.Command{ - Use: "run", - Short: "Run an extension.", - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - client, err := rpc.DialHTTP("tcp", net.JoinHostPort(cfg.Hostname, cfg.Port)) - if err != nil { - log.Fatal("dialing:", err) - } - var res int - - if err = client.Call("Service.Start", &args[0], &res); err != nil { - log.Fatal(err) - } - - fmt.Println(res) - }, - } -} diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 4d5b30c6184..5d07f08afee 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -274,25 +274,6 @@ func (s *Service) generateRunSet(cfg *ociscfg.Config) { } } -// Start indicates the Service Controller to start a new supervised service as an OS thread. -func (s *Service) Start(name string, reply *int) error { - swap := deepcopy.Copy(s.cfg) - if _, ok := s.ServicesRegistry[name]; ok { - *reply = 0 - s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.ServicesRegistry[name](swap.(*ociscfg.Config)))) - return nil - } - - if _, ok := s.Delayed[name]; ok { - *reply = 0 - s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.Delayed[name](swap.(*ociscfg.Config)))) - return nil - } - - *reply = 0 - return fmt.Errorf("cannot start service %s: unknown service", name) -} - // List running processes for the Service Controller. func (s *Service) List(args struct{}, reply *string) error { tableString := &strings.Builder{} @@ -317,22 +298,6 @@ func (s *Service) List(args struct{}, reply *string) error { return nil } -// Kill a supervised process by subcommand name. -func (s *Service) Kill(name string, reply *int) error { - if len(s.serviceToken[name]) > 0 { - for i := range s.serviceToken[name] { - if err := s.Supervisor.RemoveAndWait(s.serviceToken[name][i], 5000*time.Millisecond); err != nil { - return err - } - } - delete(s.serviceToken, name) - } else { - return fmt.Errorf("service %s not found", name) - } - - return nil -} - // trap blocks on halt channel. When the runtime is interrupted it // signals the controller to stop any supervised process. func trap(s *Service, halt chan os.Signal) {