Files
opencloud/pkg/command/server.go
2020-02-04 12:37:23 +01:00

67 lines
1.6 KiB
Go

package command
import (
"context"
"fmt"
"os"
"path/filepath"
"syscall"
"github.com/micro/cli/v2"
"github.com/oklog/run"
"github.com/owncloud/ocis-accounts/pkg/config"
"github.com/owncloud/ocis-accounts/pkg/micro/grpc"
)
// Server is the entry point for the server command.
func Server(cfg *config.Config) *cli.Command {
baseDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
return &cli.Command{
Name: "server",
Usage: "Start accounts service",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "manager",
DefaultText: "filesystem",
Usage: "store controller driver. eg: filesystem",
Value: "filesystem",
EnvVars: []string{"OCIS_ACCOUNTS_MANAGER"},
Destination: &cfg.Manager,
},
&cli.StringFlag{
Name: "mount-path",
DefaultText: "binary default running location",
Usage: "where to mount the ocis accounts store",
Value: baseDir,
EnvVars: []string{"OCIS_ACCOUNTS_MOUNT_PATH"},
Destination: &cfg.MountPath,
},
},
Action: func(c *cli.Context) error {
gr := run.Group{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
service := grpc.NewService(
// TODO read all this from cfg
grpc.Context(ctx),
grpc.Config(cfg),
grpc.Name("accounts"),
grpc.Namespace("com.owncloud"),
grpc.Address("localhost:9999"),
)
gr.Add(func() error {
return service.Run()
}, func(_ error) {
fmt.Println("shutting down grpc server")
cancel()
})
run.SignalHandler(ctx, syscall.SIGKILL)
return gr.Run()
},
}
}