Documentation ¶
Index ¶
- Constants
- Variables
- func Demonize(ctx *Context) (err error)
- func FindDaemonProcess(ctx *Context) (present bool, process *os.Process)
- func GetChs() (stopCh, doneCh chan struct{})
- func HandleSignalCaughtEvent() bool
- func IsPidFileExists(ctx *Context) bool
- func IsRunningInDemonizedMode() bool
- func Readlink(name string) (string, error)
- func Reload(appName string, ctx *Context)
- func ServeSignals(ctx *Context) (err error)
- func SetReloadSignals(sig func() []os.Signal)
- func SetSigEmtSignals(sig func() []os.Signal)
- func SetSigHandler(handler SignalHandlerFunc, signals ...os.Signal)
- func SetTermSignals(sig func() []os.Signal)
- func Stop(appName string, ctx *Context)
- type Context
- type SignalHandlerFunc
Constants ¶
const (
// ErrnoForkAndDaemonFailed is os errno when daemon plugin and its impl occurs errors.
ErrnoForkAndDaemonFailed = -1
)
Variables ¶
var ( // ErrStop should be returned signal handler function // for termination of handling signals. ErrStop = errors.New("stop serve signals") )
Functions ¶
func Demonize ¶
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 ¶
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 IsPidFileExists ¶
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 ¶
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 ServeSignals ¶
ServeSignals calls handlers for system signals. before invoking ServeSignals(), you should run SetupSignals() at first.
func SetReloadSignals ¶
SetReloadSignals allows an functor to provide a list of Signals
func SetSigEmtSignals ¶
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 ¶
SetTermSignals allows an functor to provide a list of Signals
Types ¶
type Context ¶
type Context struct { // daemon.Context PidFileName string PidFilePerm int LogFileName string LogFilePerm int WorkDir string Umask int Args []string }
Context of daemon operations
type SignalHandlerFunc ¶
SignalHandlerFunc is the interface for signal handler functions.