Skip to content

Commit

Permalink
feat: remove daemon dependency (#2195)
Browse files Browse the repository at this point in the history
* feat: remove daemon dependency
  • Loading branch information
rahulguptajss committed Aug 21, 2023
1 parent c631075 commit 8f44053
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 114 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ harvest: deps
@echo "Building harvest"
@GOOS=$(GOOS) GOARCH=$(GOARCH) $(FLAGS) go build -trimpath -o bin -ldflags=$(LD_FLAGS) ./cmd/harvest ./cmd/poller

@# Build the daemonize for the pollers
@echo "Building daemonize"
@cd cmd/tools/daemonize; gcc daemonize.c -o ../../../bin/daemonize

@cp service/contrib/grafana bin; chmod +x bin/grafana

###############################################################################
Expand Down
25 changes: 24 additions & 1 deletion cmd/harvest/harvest.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,30 @@ func startPoller(pollerName string, promPort int, opts *options) {
os.Exit(0)
}

cmd := exec.Command(path.Join(HarvestHomePath, "bin", "daemonize"), argv...) //nolint:gosec
// Set the Setsid attribute to true, which creates a new session for the child process
// This effectively detaches the child process from the parent process
cmd := exec.Command(argv[0], argv[1:]...) //nolint:gosec
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}

// Redirect standard file descriptors to /dev/null
devNull, err := os.OpenFile(os.DevNull, os.O_RDWR, 0)
if err != nil {
fmt.Println("Error opening /dev/null:", err)
os.Exit(1)
}
defer func() {
if err := devNull.Close(); err != nil {
fmt.Println("Error closing /dev/null:", err)
}
}()

cmd.Stdin = devNull
cmd.Stdout = devNull
cmd.Stderr = devNull

// Start the poller process in the background
if err := cmd.Start(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
109 changes: 0 additions & 109 deletions cmd/tools/daemonize/daemonize.c

This file was deleted.

0 comments on commit 8f44053

Please sign in to comment.