Skip to content

Commit

Permalink
feat(oomagent): write down the listening addres
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxr committed Jan 25, 2022
1 parent 58d0eeb commit fd752ad
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions oomagent/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"os"
"path/filepath"
"strconv"

"github.com/adrg/xdg"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -43,6 +44,16 @@ var rootCmd = &cobra.Command{
if err != nil {
log.Fatalf("failed to listen: %v", err)
}

// write the listening address
tmpdir := filepath.Join(os.TempDir(), "oomagent", strconv.Itoa(os.Getpid()))
if err := os.MkdirAll(tmpdir, 0755); err != nil {
log.Fatalf("failed to create temp directory: %v", err)
}
if err := os.WriteFile(filepath.Join(tmpdir, "address"), []byte(lis.Addr().String()), 0644); err != nil {
log.Fatalf("failed to write listen address: %v", err)
}

grpcServer := grpc.NewServer()
codegen.RegisterOomAgentServer(grpcServer, &server{oomstore: oomStore})
if err := grpcServer.Serve(lis); err != nil {
Expand Down

0 comments on commit fd752ad

Please sign in to comment.