list running services

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2021-03-10 15:12:50 +00:00
parent b19e739137
commit 9424caede8
2 changed files with 39 additions and 13 deletions

View File

@@ -1,6 +1,11 @@
package command
import (
"fmt"
"log"
"net"
"net/rpc"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis/pkg/register"
@@ -20,23 +25,23 @@ func ListCommand(cfg *config.Config) *cli.Command {
},
&cli.StringFlag{
Name: "port",
Value: "10666",
Value: "6060",
EnvVars: []string{"OCIS_RUNTIME_PORT"},
},
},
Action: func(c *cli.Context) error {
//client, err := rpc.DialHTTP("tcp", net.JoinHostPort(cfg.Runtime.Hostname, cfg.Runtime.Port))
//if err != nil {
// log.Fatal("dialing:", err)
//}
//
//var arg1 string
//
//if err := client.Call("Service.List", struct{}{}, &arg1); err != nil {
// log.Fatal(err)
//}
//
//fmt.Println(arg1)
client, err := rpc.DialHTTP("tcp", net.JoinHostPort("localhost", "6060"))
if err != nil {
log.Fatal("dialing:", err)
}
var arg1 string
if err := client.Call("Service.List", struct{}{}, &arg1); err != nil {
log.Fatal(err)
}
fmt.Println(arg1)
return nil
},

View File

@@ -8,6 +8,7 @@ import (
"net/rpc"
"os"
"os/signal"
"sort"
"strings"
"syscall"
"time"
@@ -25,6 +26,7 @@ import (
"github.com/asim/go-micro/v3/logger"
"github.com/thejerf/suture"
"github.com/olekukonko/tablewriter"
glauth "github.com/owncloud/ocis/glauth/pkg/command"
idp "github.com/owncloud/ocis/idp/pkg/command"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
@@ -193,6 +195,25 @@ func (s *Service) Start(name string, reply *int) error {
// List running processes for the Service Controller.
func (s *Service) List(args struct{}, reply *string) error {
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
table.SetHeader([]string{"Extension"})
names := []string{}
for t := range s.serviceToken {
if len(s.serviceToken[t]) > 0 {
names = append(names, t)
}
}
sort.Strings(names)
for n := range names {
table.Append([]string{names[n]})
}
table.Render()
*reply = tableString.String()
return nil
}