sevlyar / go-daemon

A library for writing system daemons in golang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reload flag

icarbajovallejo opened this issue · comments

I run go-daemon on FreeBSD and I don't know if the reload flag is not implemented or I'm ignorant of how to use it (I'm rookie).
I add a function that writes in file: func Writer()

func Worker() {
      for {
            go Writer()
            if _, ok := <-stop; ok {
                  break
            }
      }
}

If I type go-daemon -s reload It does nothing, so i'm sure that I don't know how it works... How can I reload the functions into func Worker()?

Thank you!

If you want to react on reload signal you should change an implementation of reloadHandler func in the example.

Could you give me detailed description what do you wont to do? Thank you.

p.s. I updated comment because i was wrong about _, ok := <-stop.

I have an app that reads a json file and then it runs and I want to send a signal -HUP to reload the app if I change any value of json file.

By the way, I did changes in the daemon:

defer cntxt.Release()

// Start daemon
ticker := time.NewTicker(time.Minute)
zdaemon := true
for zdaemon {
	select {
	case <- ticker.C:
		go App()
	case <- quit:
		// Got a quit signal, stopping
		done <- struct{}{}
		zdaemon = false
		ticker.Stop()
		return
//	case <- reload:
		// Got a reload signal, restarting
		// ...
	default:
		// No stop signal, continuing loop
	}
}

As you can see, I add a select and ticker. Now I execute the func App() each minute but I can stop the execution with zdaemon -s quit. Now, I would like to add a -s reload flag to "restart the for" before the ticker := time.NewTicker(time.Minute) finish...

@IgnacioCarbajoVallejo, have you found solution? Can i close the issue?