Documentation
¶
Overview ¶
Package godaemon provides a simple daemon library for Go applications. It allows applications to run as daemon processes with start/stop/restart capabilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDaemon ¶
func IsDaemon() bool
IsDaemon checks if the current process is the daemon process
Returns:
- bool: true if this is the daemon process, false otherwise
func IsDaemonTask ¶
func IsDaemonTask() bool
IsDaemonTask checks if the current process is the task process
Returns:
- bool: true if this is the task process, false otherwise
Types ¶
type GoDaemon ¶
type GoDaemon struct {
*gologger.Logger // Embedded logger for logging
Running *exec.Cmd // Currently running task process
StartFn func(*GoDaemon) // Function called when task starts
StopFn func(*GoDaemon) // Function called when task stops
// contains filtered or unexported fields
}
GoDaemon represents a daemon process manager
func NewGoDaemon ¶
NewGoDaemon creates a new GoDaemon instance
Parameters:
- start: function to be called when the task process starts
- stop: function to be called when the task process stops
Returns:
- *GoDaemon: initialized GoDaemon instance
func (*GoDaemon) GetPid ¶
GetPid retrieves the daemon process ID from the PID file
Returns:
- int: process ID if found and valid, 0 otherwise
func (*GoDaemon) GetTaskPid ¶
GetTaskPid retrieves the task process ID from the task PID file
Returns:
- int: process ID if found and valid, 0 otherwise
func (*GoDaemon) Start ¶
func (g *GoDaemon) Start()
Start begins the daemon process management based on the current process role
Behavior depends on process role:
- Master: starts the daemon process or sends signals to running daemon
- Daemon: manages task process lifecycle
- Task: executes the user-provided StartFn