Documentation
¶
Overview ¶
Simple framework to write daemon and supervised program
Index ¶
- Constants
- Variables
- func NewLogger() (l *stdlog.Logger)
- func Start(s SinkServer) error
- type Daemon
- func (d *Daemon) Handle(h Handler)
- func (d *Daemon) HandleFunc(f func())
- func (d *Daemon) RunForever(handler func()) error
- func (d *Daemon) RunOnce(handler func()) error
- func (d *Daemon) RunWait(handler func()) error
- func (d *Daemon) Serve()
- func (d *Daemon) Sink() error
- func (d *Daemon) WaitSignal()
- type Handler
- type HandlerFunc
- type SinkServer
- type Supervisor
Constants ¶
View Source
const (
ENV_DAEMON = "__GO_DAEMON_MODE"
)
View Source
const (
ENV_SUPERVISOR = "__GO_SUPERVISOR_MODE"
)
View Source
const (
UNSET_ENV = false // set it to false to support reexec
)
Variables ¶
View Source
var (
DefaultDaemon = NewDaemon()
)
View Source
var (
DefaultSupervisor = NewSupervisor()
)
Functions ¶
Types ¶
type Daemon ¶
type Daemon struct { PidFile string Foreground bool Signalc chan os.Signal Command exec.Cmd WaitSeconds time.Duration Log logFile // contains filtered or unexported fields }
func (*Daemon) HandleFunc ¶
func (d *Daemon) HandleFunc(f func())
func (*Daemon) RunForever ¶
RunForever returns imediately to the caller and run the specified function in background, it watches over the requested function in a separate goroutine, the function will get restarted infinitely on errors.
func (*Daemon) RunOnce ¶
RunForever returns imediately to the caller and run the specified function in background
func (*Daemon) RunWait ¶
RunWait will run the specified function in safe mode, it blocks the caller until it finished
func (*Daemon) Sink ¶
Start will setup the daemon environment and create pidfile if pidfile is not empty Parent process will never return Will return back to the worker process
func (*Daemon) WaitSignal ¶
func (d *Daemon) WaitSignal()
type HandlerFunc ¶
type HandlerFunc func()
func (HandlerFunc) Serve ¶
func (h HandlerFunc) Serve()
func (HandlerFunc) Stop ¶
func (h HandlerFunc) Stop()
type SinkServer ¶
type SinkServer interface { Sink() error Serve() WaitSignal() }
func DaemonHandle ¶
func DaemonHandle(pidfile string, foreground bool, h Handler) SinkServer
func DaemonHandleFunc ¶
func DaemonHandleFunc(pidfile string, foreground bool, f func()) SinkServer
func HandleFunc ¶
func HandleFunc(pidfile string, foreground bool, f func()) SinkServer
type Supervisor ¶
type Supervisor struct {
*Daemon
}
func NewSupervisor ¶
func NewSupervisor() *Supervisor
func (*Supervisor) Sink ¶
func (s *Supervisor) Sink() error
Click to show internal directories.
Click to hide internal directories.