Incomplete go app to HUP nginx when a config file changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hupper.go 1006B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "golang.org/x/exp/inotify"
  6. "strings"
  7. )
  8. type arrayFlags []string
  9. func (i *arrayFlags) String() string {
  10. return strings.Join(*i, ", ")
  11. }
  12. func (i *arrayFlags) Set(value string) error {
  13. *i = append(*i, value)
  14. return nil
  15. }
  16. func main() {
  17. var paths arrayFlags
  18. var container string
  19. flag.Var(&paths, "path", "Path to monitor for changes (may be specified multiple times)")
  20. flag.StringVar(&container, "container", "nginx", "Name of the container in which nginx is running")
  21. flag.Parse()
  22. fmt.Printf("Hello, world.\nPaths: %v\nContainer: %v\n", paths, container)
  23. if len(paths) == 0 {
  24. panic("No paths specified")
  25. }
  26. watch_for_changes(paths)
  27. }
  28. func watch_for_changes(paths []string) {
  29. watcher, err := inotify.NewWatcher()
  30. if err != nil {
  31. panic(err)
  32. }
  33. defer watcher.Close()
  34. for _, path := range paths {
  35. watcher.Watch(path)
  36. }
  37. for {
  38. select {
  39. case event := <-watcher.Event:
  40. panic(event)
  41. case err := <-watcher.Error:
  42. panic(err)
  43. }
  44. }
  45. }