deemon

package module
v0.0.0-...-6184259 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2016 License: Apache-2.0 Imports: 15 Imported by: 0

README

deemon

Packge deemon is a small experimental package that aims to simplify creating daemon processes in GO. It is inspired by sevlyar/go-daemon but focuses more on recovering a crashed process and supporting a rc.d compatible start,stop,restart,status interface.

Usage


ctx, _ := Launch(
	StartFunc(func() error { 
		/* The main loop of the service/daemon */
		for {
			time.Sleep(time.Millisecond * 100)
			panic("test")
		}
	}), ReturnHandlerFunc(func(err error) error {
		/* what do do if the main loop returns */
		return nil
	}), ExitHandlerFunc(func(state *os.ProcessState) error {
		/* What to do if the child process exits */
		return nil
	}), PanicHandlerFunc(func(i interface{}) error {
		/* What do do if the main loop panics */
		return nil
	}))

TODO

  • add examples
  • add more testcase. SEGFAULT (CGO) handling in particular.
  • do SIGKILL after SIGTERM tries.
  • add SIGINFO
  • redirect stdout to logfile/ not just the log package

##Documentation As usual: sebkl/deemon

Documentation

Index

Constants

View Source
const (
	MARK_KEY            = "_DEEMON_PROC_TYPE_"
	MARK_CHILD          = "CHILD"
	MARK_WATCHDOG       = "WATCHDOG"
	MARK_STARTER        = "STARTER"
	DefaultMaxKillRetry = 10
	//TODO: make this one portable. BSD it is SIGINFO under linux SIGQUIT is considerable.
	INFOSIGNAL = syscall.SIGQUIT
)

Variables

This section is empty.

Functions

func Main

func Main(s StartFunc, fs ...interface{})

Main is a convenience function to be called directly from the main function. It assumes the command as the first argument.pa

func PrintUsage

func PrintUsage()

Types

type AnyHandlerFunc

type AnyHandlerFunc func(error) error

type Config

type Config struct {
	Pidfile    string
	Logfile    string
	Workdir    string
	Nolog      bool
	Foreground bool
	RotateSize int
}

type Context

type Context struct {
	Config

	UseWatchdog  bool
	MaxKillRetry int

	OnExit   ExitHandlerFunc
	OnPanic  PanicHandlerFunc
	OnSignal SignalHandlerFunc
	OnReturn ReturnHandlerFunc
	OnAny    AnyHandlerFunc
	OnStatus StatusHandlerFunc

	DefaultOnExit   ExitHandlerFunc
	DefaultOnPanic  PanicHandlerFunc
	DefaultOnSignal SignalHandlerFunc
	DefaultOnReturn ReturnHandlerFunc
	DefaultOnAny    AnyHandlerFunc
	DefaultOnStatus StatusHandlerFunc

	Start StartFunc

	Name    string
	MustRun time.Duration
	// contains filtered or unexported fields
}

func Command

func Command(cmd string, s StartFunc, fs ...interface{}) (ctx *Context, err error)

func Launch

func Launch(s StartFunc, args ...interface{}) (ctx *Context, err error)

func NewContext

func NewContext(s StartFunc, args ...interface{}) *Context

func (*Context) Command

func (c *Context) Command(cmd string) (err error)

func (*Context) Errorf

func (c *Context) Errorf(pat string, args ...interface{}) error

func (*Context) IsDown

func (c *Context) IsDown() bool

func (*Context) IsRunning

func (c *Context) IsRunning() bool

func (*Context) Kill

func (c *Context) Kill() error

func (*Context) Launch

func (c *Context) Launch() (err error)

func (*Context) Logf

func (c *Context) Logf(pat string, args ...interface{})

func (*Context) Stop

func (c *Context) Stop() error

type ExitHandlerFunc

type ExitHandlerFunc func(*os.ProcessState) error

type PanicHandlerFunc

type PanicHandlerFunc func(interface{}) error

type ReturnHandlerFunc

type ReturnHandlerFunc func(error) error

type SignalHandlerFunc

type SignalHandlerFunc func(os.Signal) error

type StartFunc

type StartFunc func() error

The loop is only restarted if none of the Handler implementations return an error != nil.

type StatusHandlerFunc

type StatusHandlerFunc func() string

Jump to

Keyboard shortcuts

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