converge/cmd/fsnotifytest/monitor.go
Erik Brakkee e01a2bc729 Added pprof to convergeserver and optionally to
the agent if PPROF_PORT is set.

Fixed issue with converge server not cleaning up goroutines because of blocking channel. Made sure to create channels with > 1 size everywhere it can be done. The blocking behavior of a default channel size is mostly in the way.

Known issue: Killing the SSH client will lead to the server side process not being terminated and some goroutines still running in the agent. This would require additional investigation to solve. The remote processes are still being cleaned up ok (at least on linux) when the agent exits.

This should not be an issue at all since the agent is a short-lived process and when running in a containerized environment with containers running on demand the cleanup will definitely work.
2024-09-08 11:16:49 +02:00

59 lines
953 B
Go

package main
import (
"fmt"
"log"
"github.com/fsnotify/fsnotify"
)
// create .hold
// CREATE + CHMOD
// remove
// REMOVE
// touch existing:
// CHMOD
// echo > .hold
//
// file name: ./.hold on linux and just .hold on windows
func main() {
// Create a new watcher
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
// Start listening for events
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
fmt.Printf("Event: %s File: %s\n", event.Op, event.Name)
if event.Op&fsnotify.Write == fsnotify.Write {
fmt.Println("Modified file:", event.Name)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
fmt.Println("Error:", err)
}
}
}()
// Add a directory to watch
err = watcher.Add(".")
if err != nil {
log.Fatal(err)
}
// Block main goroutine forever
<-make(chan struct{}, 10)
}