daemon

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const EnvName = "XW_DAEMON_IDX"

Variables

This section is empty.

Functions

func Background

func Background(logFile string, isExit bool) (*exec.Cmd, error)

Background 把本身程序转化为后台运行(启动一个子进程, 然后自己退出) logFile 若不为空,子程序的标准输出和错误输出将记入此文件 isExit 启动子加进程后是否直接退出主程序, 若为false, 主程序返回*os.Process, 子程序返回 nil. 需自行判断处理

func NewSysProcAttr

func NewSysProcAttr() *syscall.SysProcAttr

Types

type Daemon

type Daemon struct {
	LogFile     string // 日志文件, 记录守护进程和子进程的标准输出和错误输出. 若为空则不记录
	MaxCount    int    // 循环重启最大次数, 若为0则无限重启
	MaxError    int    // 连续启动失败或异常退出的最大次数, 超过此数, 守护进程退出, 不再重启子进程
	MinExitTime int64  // 子进程正常退出的最小时间(秒). 小于此时间则认为是异常退出
}

Daemon 守护进程

func NewDaemon

func NewDaemon(logFile string) *Daemon

func (*Daemon) Run

func (d *Daemon) Run()

Run 启动后台守护进程

Jump to

Keyboard shortcuts

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