Documentation ¶
Overview ¶
Package daemon provides functionalities for handling process identifiers (PID).
Index ¶
Constants ¶
const Name = "daemon"
Constant representing the name of the daemon.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DaemonHandler ¶
type DaemonHandler struct { PIDHandler *PIDHandler // PIDHandler is used to manage the PID file of the daemon. // contains filtered or unexported fields }
DaemonHandler manages the lifecycle and signal handling of the daemon.
func New ¶
func New() *DaemonHandler
New creates a new instance of DaemonHandler. It initializes the PIDHandler and channels for signal and completion handling.
func (*DaemonHandler) Start ¶
func (d *DaemonHandler) Start(handlers ...*Handler)
Start begins the daemon execution. It starts the specified handlers and listens for system signals to handle graceful shutdown. Parameters: - handlers: ...*Handler A variadic list of handlers to be executed by the daemon.
func (*DaemonHandler) Stop ¶
func (d *DaemonHandler) Stop()
Stop gracefully stops the daemon. It sends a SIGTERM signal to the daemon.
type Handler ¶
type Handler struct { Name string // Name of the handler. Call func() error // Call is the function to execute the handler's task. }
Handler struct defines a structure for handling specific daemon tasks.
type PIDHandler ¶
type PIDHandler struct {
// contains filtered or unexported fields
}
PIDHandler handles the creation, retrieval, and deletion of PID files. It is used to manage PID files for processes, typically in a Unix-like environment.
func NewPIDHandler ¶
func NewPIDHandler(processName, pathRun string) *PIDHandler
NewPIDHandler creates and returns a new instance of PIDHandler for a given process name and path. It initializes a PIDHandler with a specified process name and the path for the PID file.
Parameters: - processName: string The name of the process. - pathRun: string The path to the directory containing the PID file.
Returns: - *PIDHandler: A new instance of PIDHandler.
func (*PIDHandler) ClearPID ¶
func (p *PIDHandler) ClearPID() error
ClearPID deletes the PID file associated with the process. It removes the PID file, indicating that the process is no longer running.
Returns: - error: An error if the file operation fails.
func (*PIDHandler) GetPID ¶
func (p *PIDHandler) GetPID() (int, error)
func (*PIDHandler) SetPID ¶
func (p *PIDHandler) SetPID() error
SetPID creates or updates the PID file with the provided PID. It writes the given PID to the PID file for the process.
Parameters: - pid: int The process ID to set in the PID file.
Returns: - error: An error if the file operation fails.