impl

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrnoForkAndDaemonFailed is os errno when daemon plugin and its impl occurs errors.
	ErrnoForkAndDaemonFailed = -1
)

Variables

View Source
var (
	// ErrStop should be returned signal handler function
	// for termination of handling signals.
	ErrStop = errors.New("stop serve signals")
)

Functions

func Demonize

func Demonize(ctx *Context) (err error)

Demonize enables the demonized mode for this app. It fork a new child process and detach it from linux tty session, and the parent process exit itself.

func FindDaemonProcess

func FindDaemonProcess(ctx *Context) (present bool, process *os.Process)

FindDaemonProcess locates the daemon process if running

func GetChs

func GetChs() (stopCh, doneCh chan struct{})

GetChs returns the standard `stop`, `done` channel

func HandleSignalCaughtEvent

func HandleSignalCaughtEvent() bool

HandleSignalCaughtEvent is a shortcut to block the main business logic loop but break it if os signals caught. `stop` channel will be trigger if any hooked os signal caught, such as os.Interrupt; the main business logic loop should trigger `done` once `stop` holds.

func HotReload added in v1.6.19

func HotReload(appName string, ctx *Context)

HotReload reloads the daemon process if running

func IsPidFileExists

func IsPidFileExists(ctx *Context) bool

IsPidFileExists checks if the pid file exists or not

func IsRunningInDemonizedMode

func IsRunningInDemonizedMode() bool

IsRunningInDemonizedMode returns true if you are running under demonized mode. false means that you're running in normal console/tty mode.

func Readlink(name string) (string, error)

Readlink returns the file pointed to by the given soft link, or an error of type PathError otherwise. This mimics the os.Readlink() function, but works around a bug we've seen in CentOS 5.10 (kernel 2.6.27.10 on x86_64) where the underlying OS function readlink() returns a wrong number of bytes for the result (see man readlink). Here we don't rely blindly on that value; if there's a zero byte among that number of bytes, then we keep only up to that point.

NOTE: We chose not to use os.Readlink() and then search on its result to avoid an extra overhead of converting back to []byte. The function to search for a byte over the string itself (strings.IndexByte()) is only available starting with Go 1.2. Also, we're not searching at every iteration to save some CPU time, even though that could mean extra iterations for systems affected with this bug. But it's wiser to optimize for the general case (i.e., those not affected).

func Reload

func Reload(appName string, ctx *Context)

Reload reloads the daemon process if running

func ServeSignals

func ServeSignals(ctx *Context) (err error)

ServeSignals calls handlers for system signals. before invoking ServeSignals(), you should run SetupSignals() at first.

func SetHotReloadSignals added in v1.6.19

func SetHotReloadSignals(sig func() []os.Signal)

SetHotReloadSignals allows an functor to provide a list of Signals

func SetOnGetListener added in v1.6.19

func SetOnGetListener(fn func() net.Listener)

SetOnGetListener returns tcp/http listener for daemon hot-restarting

func SetReloadSignals

func SetReloadSignals(sig func() []os.Signal)

SetReloadSignals allows an functor to provide a list of Signals

func SetSigEmtSignals

func SetSigEmtSignals(sig func() []os.Signal)

SetSigEmtSignals allows an functor to provide a list of Signals

func SetSigHandler

func SetSigHandler(handler SignalHandlerFunc, signals ...os.Signal)

SetSigHandler sets handler for the given signals. SIGTERM has the default handler, he returns ErrStop.

func SetTermSignals

func SetTermSignals(sig func() []os.Signal)

SetTermSignals allows an functor to provide a list of Signals

func Stop

func Stop(appName string, ctx *Context)

Stop stops the daemon process if running

Types

type Context

type Context struct {
	// daemon.Context
	PidFileName string
	PidFilePerm int
	LogFileName string
	LogFilePerm int
	WorkDir     string
	Umask       int
	Args        []string
	Hot         bool
	DaemonImpl  interface{}
	// contains filtered or unexported fields
}

Context of daemon operations

func DefaultContext

func DefaultContext() *Context

DefaultContext returns a daemon context

func GetContext

func GetContext(cmd *cmdr.Command, args []string, daemonImpl interface{}, onHotReloading func(ctx *Context) error) *Context

GetContext returns daemon Context object with ref to cmdr options store

type SignalHandlerFunc

type SignalHandlerFunc func(sig os.Signal) (err error)

SignalHandlerFunc is the interface for signal handler functions.

Jump to

Keyboard shortcuts

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