Skip to content

Commit

Permalink
v1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lack30 committed Apr 14, 2023
1 parent 0bfcedf commit 0e4186b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 42 deletions.
2 changes: 2 additions & 0 deletions pkg/ctl/deploy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/vine-io/gpm/pkg/server"
"github.com/vine-io/vine"
vcmd "github.com/vine-io/vine/lib/cmd"
log "github.com/vine-io/vine/lib/logger"
)

var f embed.FS
Expand Down Expand Up @@ -185,6 +186,7 @@ func initRun(root *cobra.Command) error {
return err
}

log.Infof("app init")
if err = app.Init(); err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/internal/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions pkg/server/gpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,36 @@ import (
pb "github.com/vine-io/gpm/api/service/gpm/v1"
gpmv1 "github.com/vine-io/gpm/api/types/gpm/v1"
"github.com/vine-io/gpm/pkg/service"
"github.com/vine-io/vine"
vserver "github.com/vine-io/vine/core/server"
verrs "github.com/vine-io/vine/lib/errors"
)

type GpmServer struct {
vine.Service
server vserver.Server

manager service.GenerateManager
ftp service.GenerateFTP
}

func RegistryGpmRpcServer(s vine.Service, manager service.GenerateManager, ftp service.GenerateFTP) error {
func RegistryGpmRpcServer(ctx context.Context, s vserver.Server, manager service.GenerateManager, ftp service.GenerateFTP) error {

gs := &GpmServer{
Service: s,
server: s,
manager: manager,
ftp: ftp,
}

if err := pb.RegisterGpmServiceHandler(s.Server(), gs); err != nil {
if err := pb.RegisterGpmServiceHandler(s, gs); err != nil {
return err
}

return nil
}

func (s *GpmServer) Name() string {
return s.server.Options().Name
}

func (s *GpmServer) Healthz(ctx context.Context, _ *pb.Empty, rsp *pb.Empty) error {
return nil
}
Expand Down
34 changes: 20 additions & 14 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,49 @@ func (app *GpmApp) Init(opts ...vine.Option) error {
}
_ = uc.UnmarshalKey(&config.DefaultAddress, "server.address")

db := new(store.DB)
svc := app.s
manager, err := service.NewManagerService(svc, db)
if err != nil {
return err
}
ctx := app.s.Options().Context
server := app.s.Options().Server

sftp, err := service.NewSFtpService(svc)
osRelease, _ := release.Get()
log.Infof("system information: %s", osRelease)

handler, err := RegistryGpmAPIServer(app.s)
if err != nil {
return err
}

if err = RegistryGpmRpcServer(svc, manager, sftp); err != nil {
if err = app.s.Server().Init(grpcServer.HttpHandler(handler)); err != nil {
return err
}

if err = openapi.RegisterOpenAPIHandler(svc.Server()); err != nil {
db := new(store.DB)
manager, err := service.NewManagerService(ctx, server, db)
if err != nil {
return err
}

handler, err := RegistryGpmAPIServer(svc)
sftp, err := service.NewSFtpService(ctx, server)
if err != nil {
return err
}

if err = svc.Server().Init(grpcServer.HttpHandler(handler)); err != nil {
if err = RegistryGpmRpcServer(ctx, server, manager, sftp); err != nil {
return err
}

or, _ := release.Get()
log.Infof("system information: %s", or)
if err = openapi.RegisterOpenAPIHandler(server); err != nil {
return err
}

return nil
}

func (app *GpmApp) Run() error {
return app.s.Run()
if err := app.s.Run(); err != nil {
return err
}

return nil
}

func Action(cmd *cobra.Command, args []string) error {
Expand Down
15 changes: 11 additions & 4 deletions pkg/service/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,29 @@ import (

"github.com/google/uuid"
gpmv1 "github.com/vine-io/gpm/api/types/gpm/v1"
"github.com/vine-io/vine"
vserver "github.com/vine-io/vine/core/server"
verrs "github.com/vine-io/vine/lib/errors"
log "github.com/vine-io/vine/lib/logger"
)

func NewSFtpService(s vine.Service) (GenerateFTP, error) {
func NewSFtpService(ctx context.Context, server vserver.Server) (GenerateFTP, error) {

ftp := &sftp{
Service: s,
ctx: ctx,
server: server,
}

return ftp, nil
}

type sftp struct {
vine.Service
ctx context.Context

server vserver.Server
}

func (s *sftp) Name() string {
return s.server.Options().Name
}

func (s *sftp) List(ctx context.Context, root string) ([]*gpmv1.FileInfo, error) {
Expand Down
47 changes: 31 additions & 16 deletions pkg/service/gpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,69 @@ import (
"github.com/vine-io/gpm/pkg/internal"
"github.com/vine-io/gpm/pkg/internal/config"
"github.com/vine-io/gpm/pkg/internal/store"
"github.com/vine-io/vine"
vserver "github.com/vine-io/vine/core/server"
verrs "github.com/vine-io/vine/lib/errors"
log "github.com/vine-io/vine/lib/logger"
)

type manager struct {
sync.RWMutex
vine.Service
ctx context.Context

server vserver.Server

db *store.DB

up time.Time
ps map[string]*Process
}

func NewManagerService(s vine.Service, db *store.DB) (GenerateManager, error) {

var err error
func NewManagerService(ctx context.Context, server vserver.Server, db *store.DB) (GenerateManager, error) {

m := &manager{
Service: s,
s := &manager{
ctx: ctx,
server: server,
db: db,
up: time.Time{},
RWMutex: sync.RWMutex{},
ps: nil,
}

if err = os.MkdirAll(filepath.Join(config.LoadRoot(), "services"), os.ModePerm); err != nil {
log.Infof("init manager service")
if err := s.Init(); err != nil {
return nil, err
}

return s, nil
}

func (g *manager) Init() error {
var err error

if err = os.MkdirAll(filepath.Join(config.LoadRoot(), "services"), os.ModePerm); err != nil {
return err
}
ctx := context.Background()
list, err := db.FindAllServices(ctx)
list, err := g.db.FindAllServices(ctx)
if err != nil {
return nil, err
return err
}

m.ps = map[string]*Process{}
g.ps = map[string]*Process{}
for _, item := range list {
p := NewProcess(item, db)
p := NewProcess(item, g.db)
if item.Status == gpmv1.StatusRunning {
_, _ = m.startService(ctx, p)
_, _ = g.startService(ctx, p)
}
m.ps[item.Name] = p
g.ps[item.Name] = p
}

m.up = time.Now()
g.up = time.Now()
return nil
}

return m, nil
func (g *manager) Name() string {
return g.server.Options().Name
}

func (g *manager) Info(ctx context.Context) (*gpmv1.GpmInfo, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/service/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

type GenerateManager interface {
Init() error
Info(context.Context) (*gpmv1.GpmInfo, error)
Update(context.Context, IOStream) error
List(context.Context) ([]*gpmv1.Service, int64, error)
Expand Down

0 comments on commit 0e4186b

Please sign in to comment.