Documentation ¶
Overview ¶
Package daemon 实现应用进程启动命令、后台启动、信号处理、热重启的代码支持。
启动命令 ¶
app --command=start/status/stop/restart/deamon/disable --pidfile=/run/run/pidfile
command:
start 写入pid前台启动 daemon 写入pid后台启动 status 读取pid判断进程存在 stop 读取pid发送syscall.SIGTERM信号(15) restart 读取pid发送syscall.SIGUSR2信号(12) disable 跳过启动命令处理
后台启动 ¶
func main() { daemon.StartDaemon() }
信号处理 ¶
热重启 ¶
使用command组件或kill命令发送SIGUSR2信号。
父进程接受SIGUSR2信号后,传递当前Listen FD和ppid后台启动子进程; 子进程启动初始化后完成向父进程发送SIGTERM信号关闭父进程。
Index ¶
- Constants
- func AppRestart(ctx context.Context) error
- func AppStop(ctx context.Context) error
- func NewParseDaemon(app *eudore.App) eudore.ConfigParseFunc
- func NewParseRestart() eudore.ConfigParseFunc
- func StartDaemon(envs ...string)
- type Command
- func (cmd *Command) Daemon(ctx context.Context) error
- func (cmd *Command) ExecSignal(sig os.Signal) error
- func (cmd *Command) Reload() error
- func (cmd *Command) Restart() error
- func (cmd *Command) Run(ctx context.Context) (err error)
- func (cmd *Command) Start(ctx context.Context) error
- func (cmd *Command) Status() error
- func (cmd *Command) Stop() error
- func (cmd *Command) Wait(p int)
- type Signal
- type SignalFunc
Constants ¶
View Source
const ( CommandStart = "start" CommandDaemon = "daemon" CommandStatus = "status" CommandStop = "stop" CommandRestart = "restart" CommandDisable = "disable" )
Variables ¶
This section is empty.
Functions ¶
func AppRestart ¶
func NewParseDaemon ¶
func NewParseDaemon(app *eudore.App) eudore.ConfigParseFunc
NewParseCommand 函数创建Command配置解析函数。
func NewParseRestart ¶
func NewParseRestart() eudore.ConfigParseFunc
Types ¶
type Command ¶
type Command struct { Command string Pidfile string Args []string Envs []string Print func(string, ...any) }
Command is a command parser that performs the corresponding behavior based on the current command.
Command 对象是一个命令解析器,根据当前命令执行对应行为。
func (*Command) Daemon ¶
Daemon Start the process in the background. If it is not started in the background, create a background process.
Daemon 函数后台启动进程。若不是后台启动,则创建一个后台进程。
func (*Command) ExecSignal ¶
ExecSignal 函数向pidfile内的进程发送指定命令。
Click to show internal directories.
Click to hide internal directories.