command.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package daemon
  2. import (
  3. "errors"
  4. "git.beejay.kim/WatchDog/ward/player"
  5. "github.com/urfave/cli/v2"
  6. "os"
  7. "os/signal"
  8. "syscall"
  9. )
  10. var (
  11. topic string
  12. pid string
  13. bid string
  14. pathRecord string
  15. pathPlayer string
  16. players []player.Player
  17. exit = make(chan error, 8)
  18. ctrlSignal = make(chan os.Signal)
  19. Command = cli.Command{
  20. Name: "daemon",
  21. Usage: "run daemon",
  22. Flags: flags,
  23. Action: action,
  24. Before: func(ctx *cli.Context) error {
  25. // Intercept Interrupt signals
  26. signal.Notify(ctrlSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
  27. go func() {
  28. <-ctrlSignal
  29. exit <- errors.New("interrupted by user")
  30. }()
  31. var (
  32. p player.Player
  33. err error
  34. )
  35. if pathRecord != "" {
  36. if p, err = player.NewRecorder(pathRecord, bid); err != nil {
  37. return err
  38. }
  39. players = append(players, p)
  40. }
  41. if pathPlayer == "vlc" {
  42. if p, err = player.NewVLC(ctx.Context); err != nil {
  43. return err
  44. }
  45. players = append(players, p)
  46. }
  47. return nil
  48. },
  49. }
  50. )