mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-12 03:18:08 -04:00
working runtime
This commit is contained in:
31
go.mod
31
go.mod
@@ -9,12 +9,21 @@ require (
|
||||
github.com/UnnoTed/fileb0x v1.1.4
|
||||
github.com/chzyer/logex v1.1.10 // indirect
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
|
||||
github.com/coreos/etcd v3.3.21+incompatible // indirect
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
|
||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||
github.com/go-log/log v0.2.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.1 // indirect
|
||||
github.com/golang/protobuf v1.4.2 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.12.1 // indirect
|
||||
github.com/lucas-clemente/quic-go v0.15.7 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/micro/cli/v2 v2.1.2-0.20200203150404-894195727d9c
|
||||
github.com/micro/go-micro/v2 v2.0.1-0.20200212105717-d76baf59de2e
|
||||
github.com/micro/micro/v2 v2.0.1-0.20200210100719-f38a1d8d5348
|
||||
github.com/micro/cli/v2 v2.1.2
|
||||
github.com/micro/go-micro/v2 v2.7.0
|
||||
github.com/micro/micro v1.16.0
|
||||
github.com/micro/micro/v2 v2.7.0
|
||||
github.com/miekg/dns v1.1.29 // indirect
|
||||
github.com/nats-io/nats.go v1.10.0 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.2.2
|
||||
github.com/owncloud/flaex v0.2.0
|
||||
github.com/owncloud/ocis-accounts v0.1.1
|
||||
@@ -31,12 +40,20 @@ require (
|
||||
github.com/owncloud/ocis-reva v0.2.2-0.20200513073117-ee9cd9b8d3ab
|
||||
github.com/owncloud/ocis-thumbnails v0.1.2-0.20200422124828-f92a40879feb
|
||||
github.com/owncloud/ocis-webdav v0.1.0
|
||||
github.com/refs/pman v0.0.0-20200518220537-f6667770d0e9
|
||||
github.com/refs/pman v0.0.0-20200520152433-d1823a649d98
|
||||
github.com/restic/calens v0.2.0
|
||||
go.opencensus.io v0.22.3
|
||||
go.uber.org/atomic v1.5.1 // indirect
|
||||
go.uber.org/multierr v1.4.0 // indirect
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
|
||||
go.uber.org/zap v1.15.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
|
||||
golang.org/x/net v0.0.0-20200519113804-d87ec0cfa476 // indirect
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
|
||||
golang.org/x/tools v0.0.0-20200519205726-57a9e4404bf7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20200519141106-08726f379972 // indirect
|
||||
gopkg.in/olivere/elastic.v5 v5.0.83 // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
|
||||
)
|
||||
|
||||
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
|
||||
|
||||
replace github.com/lucas-clemente/quic-go v0.15.7 => github.com/lucas-clemente/quic-go v0.14.1
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/micro/cli/v2"
|
||||
"github.com/micro/go-micro/v2/config/cmd"
|
||||
"github.com/owncloud/ocis/pkg/config"
|
||||
"github.com/owncloud/ocis/pkg/flagset"
|
||||
"github.com/owncloud/ocis/pkg/micro/runtime"
|
||||
@@ -29,19 +28,11 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
if err := tracing.Start(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime := runtime.New(
|
||||
runtime.Services(append(runtime.MicroServices, runtime.Extensions...)),
|
||||
runtime.Logger(logger),
|
||||
runtime.MicroRuntime(cmd.DefaultCmd.Options().Runtime),
|
||||
runtime.Context(c),
|
||||
)
|
||||
|
||||
runtime := runtime.New()
|
||||
runtime.Start()
|
||||
|
||||
return nil
|
||||
|
||||
@@ -2,8 +2,6 @@ package runtime
|
||||
|
||||
import (
|
||||
"github.com/micro/cli/v2"
|
||||
"github.com/micro/go-micro/v2/config/cmd"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
)
|
||||
|
||||
// Command adds micro runtime commands to the cli app
|
||||
@@ -13,12 +11,7 @@ func Command(app *cli.App) *cli.Command {
|
||||
Description: "starts the go-micro runtime services",
|
||||
Category: "Micro",
|
||||
Action: func(c *cli.Context) error {
|
||||
runtime := New(
|
||||
Services(MicroServices),
|
||||
Logger(log.NewLogger()),
|
||||
MicroRuntime(cmd.DefaultCmd.Options().Runtime),
|
||||
)
|
||||
|
||||
runtime := New()
|
||||
runtime.Start()
|
||||
|
||||
return nil
|
||||
|
||||
@@ -2,16 +2,14 @@ package runtime
|
||||
|
||||
import (
|
||||
"github.com/micro/cli/v2"
|
||||
gorun "github.com/micro/go-micro/v2/runtime"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
)
|
||||
|
||||
// Options is a runtime option
|
||||
type Options struct {
|
||||
Services []string
|
||||
Logger log.Logger
|
||||
MicroRuntime *gorun.Runtime
|
||||
Context *cli.Context
|
||||
Services []string
|
||||
Logger log.Logger
|
||||
Context *cli.Context
|
||||
}
|
||||
|
||||
// Option undocummented
|
||||
@@ -35,20 +33,6 @@ func Services(s []string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Logger option
|
||||
func Logger(l log.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = l
|
||||
}
|
||||
}
|
||||
|
||||
// MicroRuntime option
|
||||
func MicroRuntime(rt *gorun.Runtime) Option {
|
||||
return func(o *Options) {
|
||||
o.MicroRuntime = rt
|
||||
}
|
||||
}
|
||||
|
||||
// Context option
|
||||
func Context(c *cli.Context) Option {
|
||||
return func(o *Options) {
|
||||
|
||||
@@ -4,19 +4,14 @@ import (
|
||||
"fmt"
|
||||
golog "log"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/micro/cli/v2"
|
||||
gorun "github.com/micro/go-micro/v2/runtime"
|
||||
"github.com/micro/micro/v2/api"
|
||||
"github.com/micro/micro/v2/proxy"
|
||||
"github.com/micro/micro/v2/registry"
|
||||
"github.com/micro/micro/v2/runtime"
|
||||
"github.com/micro/micro/v2/web"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
|
||||
"github.com/micro/micro/v2/client/api"
|
||||
"github.com/micro/micro/v2/client/proxy"
|
||||
"github.com/micro/micro/v2/client/web"
|
||||
"github.com/micro/micro/v2/service/registry"
|
||||
|
||||
"github.com/refs/pman/pkg/process"
|
||||
"github.com/refs/pman/pkg/service"
|
||||
@@ -61,81 +56,34 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// Runtime is a wrapper around micro's own runtime
|
||||
type Runtime struct {
|
||||
Logger log.Logger
|
||||
R *gorun.Runtime
|
||||
Ctx *cli.Context
|
||||
|
||||
services []*gorun.Service
|
||||
}
|
||||
// Runtime represents an oCIS runtime environment.
|
||||
type Runtime struct{}
|
||||
|
||||
// New creates a new ocis + micro runtime
|
||||
func New(opts ...Option) Runtime {
|
||||
options := newOptions(opts...)
|
||||
|
||||
r := Runtime{
|
||||
Logger: options.Logger,
|
||||
R: options.MicroRuntime,
|
||||
Ctx: options.Context,
|
||||
}
|
||||
|
||||
for _, v := range append(MicroServices, Extensions...) {
|
||||
r.services = append(r.services, &gorun.Service{Name: v})
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// Trap listen and blocks for termination signals
|
||||
func (r Runtime) Trap() {
|
||||
shutdown := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdown, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||
|
||||
if err := (*r.R).Start(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for range shutdown {
|
||||
r.Logger.Info().Msg("shutdown signal received")
|
||||
close(shutdown)
|
||||
}
|
||||
|
||||
if err := (*r.R).Stop(); err != nil {
|
||||
r.Logger.Err(err).Msgf("error while shutting down")
|
||||
}
|
||||
|
||||
for _, s := range r.services {
|
||||
r.Logger.Info().Msgf("gracefully stopping service %v", s.Name)
|
||||
if err := (*r.R).Delete(s); err != nil {
|
||||
r.Logger.Err(err).Msgf("error while deleting service: %v", s.Name)
|
||||
}
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
func New() Runtime {
|
||||
return Runtime{}
|
||||
}
|
||||
|
||||
// Start rpc runtime
|
||||
func (r *Runtime) Start() {
|
||||
func (r *Runtime) Start() error {
|
||||
go r.Launch()
|
||||
service.Start()
|
||||
return service.Start()
|
||||
}
|
||||
|
||||
// Launch ocis Extensions
|
||||
func (r *Runtime) Launch() {
|
||||
client, err := rpc.DialHTTP("tcp", "localhost:10666")
|
||||
if err != nil {
|
||||
// ensure the rpc service is running before attempting to start any extension
|
||||
fmt.Println("rpc service not available, retrying in 1 second...")
|
||||
time.Sleep(1 * time.Second)
|
||||
r.Launch()
|
||||
}
|
||||
|
||||
// loop over extensions starting them
|
||||
for i := range Extensions {
|
||||
all := append(Extensions, MicroServices...)
|
||||
for i := range all {
|
||||
arg0 := process.NewProcEntry(
|
||||
Extensions[i],
|
||||
[]string{Extensions[i]}...,
|
||||
all[i],
|
||||
[]string{all[i]}...,
|
||||
)
|
||||
var arg1 int
|
||||
|
||||
@@ -153,7 +101,6 @@ func AddMicroPlatform(app *cli.App) {
|
||||
app.Commands = append(app.Commands, proxy.Commands()...)
|
||||
app.Commands = append(app.Commands, web.Commands()...)
|
||||
app.Commands = append(app.Commands, registry.Commands()...)
|
||||
app.Commands = append(app.Commands, runtime.Commands()...)
|
||||
}
|
||||
|
||||
// provide a config.Config with default values?
|
||||
@@ -172,7 +119,4 @@ func setDefaults() {
|
||||
|
||||
// registry
|
||||
registry.Name = OwncloudNamespace + "registry"
|
||||
|
||||
// runtime
|
||||
runtime.Name = OwncloudNamespace + "runtime"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user