Skip to content

Commit

Permalink
add logic to write address file to common runtime path (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerinus committed Nov 9, 2022
1 parent fbc8610 commit c56d631
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/IceWhaleTech/CasaOS-MessageBus
go 1.19

require (
github.com/IceWhaleTech/CasaOS-Common v0.3.7-5
github.com/IceWhaleTech/CasaOS-Common v0.3.8-alpha1
github.com/gobwas/ws v1.1.0
github.com/json-iterator/go v1.1.12
github.com/spf13/cobra v1.6.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/IceWhaleTech/CasaOS-Common v0.3.7-5 h1:CLPeUaFoGCA3WNnOWxtdFbBmLIg7odCQglZJ/c878uU=
github.com/IceWhaleTech/CasaOS-Common v0.3.7-5/go.mod h1:2MiivEMzvh41codhEKUcn46WK3Ffesop/04qa9jsvQk=
github.com/IceWhaleTech/CasaOS-Common v0.3.8-alpha1 h1:tTZm14+aUP8vs9Ux2tSD7Z6ZRrlvanj8/tQDxGxgR28=
github.com/IceWhaleTech/CasaOS-Common v0.3.8-alpha1/go.mod h1:2MiivEMzvh41codhEKUcn46WK3Ffesop/04qa9jsvQk=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
Expand Down
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ func main() {
}
}

// write address file
addressFilePath, err := writeAddressFile(config.CommonInfo.RuntimePath, external.MessageBusAddressFilename, "http://"+listener.Addr().String())
if err != nil {
panic(err)
}

// notify systemd
if supported, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
logger.Error("Failed to notify systemd that message bus service is ready", zap.Error(err))
Expand All @@ -142,7 +148,7 @@ func main() {
}

// start http server
logger.Info("MessageBus service is listening...", zap.Any("address", listener.Addr().String()))
logger.Info("MessageBus service is listening...", zap.Any("address", listener.Addr().String()), zap.String("filepath", addressFilePath))

server := &http.Server{
Handler: mux,
Expand All @@ -152,3 +158,13 @@ func main() {
err = server.Serve(listener)
logger.Info("MessageBus service is stopped", zap.Error(err))
}

func writeAddressFile(runtimePath string, filename string, address string) (string, error) {
err := os.MkdirAll(runtimePath, 0o755)
if err != nil {
return "", err
}

filepath := filepath.Join(runtimePath, filename)
return filepath, os.WriteFile(filepath, []byte(address), 0o600)
}

0 comments on commit c56d631

Please sign in to comment.