Skip to content

Latest commit

 

History

History
68 lines (45 loc) · 1.7 KB

DOC.md

File metadata and controls

68 lines (45 loc) · 1.7 KB

xdaemon

import "github.com/fufuok/utils/xdaemon"

Index

Constants

const EnvName = "XW_DAEMON_IDX"

func Background

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

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

func NewSysProcAttr

func NewSysProcAttr() *syscall.SysProcAttr

type Daemon

Daemon 守护进程

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

func NewDaemon

func NewDaemon(logFile string) *Daemon

func (*Daemon) Run

func (d *Daemon) Run()

Run 启动后台守护进程

Generated by gomarkdoc