nestor

package module
v0.0.0-...-48b2ff2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2014 License: GPL-2.0 Imports: 13 Imported by: 0

README

Nestor

Nestor is a simple framework to write unix daemon program in Golang.

Usage

Daemon Example

package main

Supervised Daemon Example

package main

Code released under GPL v2.0 license. Docs released under Creative commons.

Documentation

Overview

Simple framework to write daemon and supervised program

Index

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

func NewLogger

func NewLogger() (l *stdlog.Logger)

func Start

func Start(s SinkServer) error

a function calls different sink 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 NewDaemon

func NewDaemon() *Daemon

func (*Daemon) Handle

func (d *Daemon) Handle(h Handler)

func (*Daemon) HandleFunc

func (d *Daemon) HandleFunc(f func())

func (*Daemon) RunForever

func (d *Daemon) RunForever(handler func()) error

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

func (d *Daemon) RunOnce(handler func()) error

RunForever returns imediately to the caller and run the specified function in background

func (*Daemon) RunWait

func (d *Daemon) RunWait(handler func()) error

RunWait will run the specified function in safe mode, it blocks the caller until it finished

func (*Daemon) Serve

func (d *Daemon) Serve()

func (*Daemon) Sink

func (d *Daemon) Sink() error

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 Handler

type Handler interface {
	Serve()
	Stop()
}

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 Handle

func Handle(pidfile string, foreground bool, h Handler) 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL