Skip to content

Commit

Permalink
wip: Implement a run as a system service path
Browse files Browse the repository at this point in the history
  • Loading branch information
etu committed Feb 16, 2025
1 parent ed26ce5 commit 03bb0e4
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
)

require (
github.com/kardianos/service v1.2.2 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/net v0.17.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/jedib0t/go-pretty/v6 v6.4.4 h1:N+gz6UngBPF4M288kiMURPHELDMIhF/Em35aYuKrsSc=
github.com/jedib0t/go-pretty/v6 v6.4.4/go.mod h1:MgmISkTWDSFu0xOqiZ0mKNntMQ2mDgOcwOkwBEkMDJI=
github.com/kardianos/service v1.2.2 h1:ZvePhAHfvo0A7Mftk/tEzqEZ7Q4lgnR8sGz4xu1YX60=
github.com/kardianos/service v1.2.2/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
Expand All @@ -22,6 +24,7 @@ github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func main() {
}

runner := Runner{config: &config}
serve := NewServe(&config, &runner)
services := Services{config: &config}
serve := NewServe(&config, &runner, &services)
cli := Cli{config: &config}

config.Read(configFile)
Expand Down
10 changes: 9 additions & 1 deletion serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type Serve struct {
config *Config
runner *Runner
services *Services
stateChange chan bool // Channel to signal a state change
clientSubscriptions map[*websocket.Conn]string // Map of client connections and their subscriptions
clientLocks map[*websocket.Conn]*sync.Mutex // Map of locks for each client connection to not send multiple messages at once
Expand All @@ -44,10 +45,11 @@ type ServeMessageResponse struct {
Message string `json:"message"`
}

func NewServe(config *Config, runner *Runner) *Serve {
func NewServe(config *Config, runner *Runner, services *Services) *Serve {
return &Serve{
config: config,
runner: runner,
services: services,
stateChange: make(chan bool),
clientSubscriptions: make(map[*websocket.Conn]string),
clientLocks: make(map[*websocket.Conn]*sync.Mutex),
Expand Down Expand Up @@ -170,6 +172,12 @@ func (serve *Serve) newRouter() *mux.Router {
var resp ServeMessageResponse
vars := mux.Vars(r)

// Trigger the service start
err2 := serve.services.Start(vars["name"])
if err2 != nil {
fmt.Println(err2)
}

err := serve.runner.Start(vars["name"], serve)

if err != nil {
Expand Down
Loading

0 comments on commit 03bb0e4

Please sign in to comment.