mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-24 22:49:06 -06:00
Merge pull request #3740 from wkloucek/remove-run-kill-runtime
remove run and kill commands from the runtime
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user