Skip to content

Commit

Permalink
Add info about services (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt authored Jul 30, 2024
1 parent df91245 commit ec49af2
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/signal"
"path/filepath"
"reflect"
"sort"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -327,6 +328,8 @@ func setupServices(svcManager *serviceManager, out *output) error {
"--authrpc.port", "8551",
"--authrpc.jwtsecret", "{{.Dir}}/jwtsecret",
).
WithPort("http", 8545).
WithPort("authrpc", 8551).
Run()

// start the beacon node
Expand Down Expand Up @@ -358,6 +361,7 @@ func setupServices(svcManager *serviceManager, out *output) error {
"--always-prepare-payload",
"--prepare-payload-lookahead", "8000",
).
WithPort("http", 3500).
Run()

// start validator client
Expand Down Expand Up @@ -392,6 +396,32 @@ func setupServices(svcManager *serviceManager, out *output) error {
}()
}

services := []*service{}
for _, ss := range svcManager.handles {
services = append(services, ss.Service)
}
services = append(services, &service{
name: "mev-boost-relay",
ports: []*port{
{name: "http", port: 5555},
},
})

// print services info
fmt.Printf("Services started:\n==================\n")
for _, ss := range services {
sort.Slice(ss.ports, func(i, j int) bool {
return ss.ports[i].name < ss.ports[j].name
})

ports := []string{}
for _, p := range ss.ports {
ports = append(ports, fmt.Sprintf("%s: %d", p.name, p.port))
}
fmt.Printf("- %s (%s)\n", ss.name, strings.Join(ports, ", "))
}
fmt.Printf("\n")

fmt.Printf("All services started, press Ctrl+C to stop\n")
return nil
}
Expand Down Expand Up @@ -530,7 +560,7 @@ type sszObject interface {

type serviceManager struct {
out *output
handles []*exec.Cmd
handles []*handle

stopping atomic.Bool

Expand All @@ -541,7 +571,7 @@ type serviceManager struct {
}

func newServiceManager(out *output) *serviceManager {
return &serviceManager{out: out, handles: []*exec.Cmd{}, stopping: atomic.Bool{}, wg: sync.WaitGroup{}, closeCh: make(chan struct{}, 5)}
return &serviceManager{out: out, handles: []*handle{}, stopping: atomic.Bool{}, wg: sync.WaitGroup{}, closeCh: make(chan struct{}, 5)}
}

func (s *serviceManager) emitError() {
Expand Down Expand Up @@ -578,7 +608,15 @@ func (s *serviceManager) Run(ss *service) {
s.emitError()
}()

s.handles = append(s.handles, cmd)
s.handles = append(s.handles, &handle{
Process: cmd,
Service: ss,
})
}

type handle struct {
Process *exec.Cmd
Service *service
}

func (s *serviceManager) NotifyErrCh() <-chan struct{} {
Expand All @@ -590,24 +628,35 @@ func (s *serviceManager) StopAndWait() {

for _, h := range s.handles {
if h.Process != nil {
fmt.Printf("Stopping %s\n", h.Path)
h.Process.Kill()
fmt.Printf("Stopping %s\n", h.Service.name)
h.Process.Process.Kill()
}
}
s.wg.Wait()
}

type port struct {
name string
port int
}

type service struct {
name string
args []string

ports []*port
srvMng *serviceManager
}

func (s *serviceManager) NewService(name string) *service {
return &service{name: name, args: []string{}, srvMng: s}
}

func (s *service) WithPort(name string, portNumber int) *service {
s.ports = append(s.ports, &port{name: name, port: portNumber})
return s
}

func (s *service) WithArgs(args ...string) *service {
tmplVars := map[string]interface{}{
"Dir": s.srvMng.out.dst,
Expand Down

0 comments on commit ec49af2

Please sign in to comment.