Files
ocis/pkg/command/server.go
T

59 lines
1.4 KiB
Go
Raw Normal View History

2020-01-30 15:55:40 +01:00
package command
import (
"context"
"fmt"
2020-02-04 11:54:45 +01:00
"os"
"path/filepath"
2020-01-30 15:55:40 +01:00
"syscall"
2020-02-04 10:09:38 +01:00
"github.com/micro/cli/v2"
2020-01-30 15:55:40 +01:00
"github.com/oklog/run"
2020-02-04 10:16:12 +01:00
"github.com/owncloud/ocis-accounts/pkg/config"
2020-01-30 15:55:40 +01:00
"github.com/owncloud/ocis-accounts/pkg/micro/grpc"
)
// Server is the entry point for the server command.
2020-02-04 10:16:12 +01:00
func Server(cfg *config.Config) *cli.Command {
2020-02-04 11:54:45 +01:00
baseDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
2020-02-04 10:09:38 +01:00
return &cli.Command{
2020-01-30 15:55:40 +01:00
Name: "server",
Usage: "Start accounts service",
2020-02-04 11:54:45 +01:00
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,
},
},
2020-01-30 15:55:40 +01:00
Action: func(c *cli.Context) error {
gr := run.Group{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
2020-02-04 11:54:45 +01:00
service := grpc.NewService(ctx, cfg)
2020-01-30 15:55:40 +01:00
gr.Add(func() error {
return service.Run()
}, func(_ error) {
fmt.Println("shutting down grpc server")
cancel()
})
run.SignalHandler(ctx, syscall.SIGKILL)
return gr.Run()
},
}
}