goforever

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 18 Imported by: 16

README

Mori's Goforever Fork

See the original at https://github.com/gwoo/goforever

Config based process manager. Goforever could be used in place of supervisor, runit, node-forever, etc. Goforever will start an http server on the specified port.

Usage of ./goforever:
  -conf="goforever.toml": Path to config file.

功能描述

  1. 主进程退出不影响子进程,当主进程恢复服务后继续根据pid文件进行监控进程状态
  2. 进程被外部程序结束后自动启动(respawn > 0)
  3. 有延迟启动功能(delay)
  4. 心跳时间可配置(ping)

配置文件模板

ip = "127.0.0.1"	# API 监听地址
port = "2224" 		# API 监听端口
username = "go" 	# API 用户名
password = "forever" 	# API 密码
pidfile = "goforever.pid"
logfile = "goforever.log"
errfile = "goforever.log"

[[process]]
name = "example-panic"
command = "./example/example-panic"
pidfile = "example/example-panic.pid"
logfile = "example/logs/example-panic.debug.log"
errfile = "example/logs/example-panic.errors.log"
respawn = 1 	# 进程被结束时自动重启
delay = "1m" 	# 延迟一分钟启动
ping = "30s"	# 30s检测一次进状态

[[process]]
name = "example"
dir = "/tmp/"			# 切换到此目录下运行 command
env = ["aaa=aaa","bbb=bbb"] 	# 程序指定的环境变量
command = "./example/example"
args = ["-name=foo"] 		# 命令行参数
pidfile = "example/example.pid"
logfile = "example/logs/example.debug.log"
errfile = "example/logs/example.errors.log"
respawn = 1

Running

Help.

./goforever -h

Daemonize main process.

./goforever start

Run main process and output to current session.

./goforever

CLI

list				List processes.
show [process]	    Show a main proccess or named process.
start [process]		Start a main proccess or named process.
stop [process]		Stop a main proccess or named process.
restart [process]	Restart a main proccess or named process.

HTTP API

Return a list of managed processes

GET host:port/

Start the process

POST host:port/:name

Restart the process

PUT host:port/:name

Stop the process

DELETE host:port/:name

Documentation

Index

Constants

View Source
const (
	StatusStarted   = `started`
	StatusRunning   = `running`
	StatusStopped   = `stopped`
	StatusRestarted = `restarted`
	StatusExited    = `exited`
	StatusKilled    = `killed`
)

Variables

View Source
var Default = New()
View Source
var ErrCouldNotFindProcess = errors.New("could not find process")
View Source
var ErrPidfileEmpty = errors.New("Pidfile is empty")

Functions

func ChildKeys added in v0.1.1

func ChildKeys() []string

func IsRunning added in v0.3.0

func IsRunning(name string) bool

func NewLog

func NewLog(path string) *os.File

NewLog Create a new file for logging

func NewSysProcAttr added in v0.3.0

func NewSysProcAttr() *syscall.SysProcAttr

func Pid added in v0.2.0

func Pid() int

func RotateLog added in v0.3.1

func RotateLog(logfile string, keepNum int) error

func Run added in v0.1.1

func Run()

func RunProcess

func RunProcess(name string, p *Process) chan *Process

RunProcess Run the process

func SetOption added in v0.2.3

func SetOption(options map[string]interface{}, name string, value interface{}) map[string]interface{}

func Status added in v0.2.0

func Status() string

func StopChild added in v0.1.1

func StopChild(name string) error

Types

type Children added in v0.1.1

type Children struct {
	// contains filtered or unexported fields
}

Children Child processes.

func NewChildren added in v0.3.0

func NewChildren(m map[string]*Process) *Children

func (Children) Get added in v0.1.1

func (c Children) Get(key string) *Process

Get child process.

func (Children) Keys added in v0.1.1

func (c Children) Keys() []string

Keys Get child processes names.

func (Children) Rotate added in v0.3.1

func (c Children) Rotate(keepNum int)

func (Children) Run added in v0.3.0

func (c Children) Run()

func (Children) Set added in v0.3.0

func (c Children) Set(key string, proc *Process)

Get child process.

func (Children) Stop added in v0.1.1

func (c Children) Stop(names ...string)

func (Children) String added in v0.1.1

func (c Children) String() string

String Stringify

type Pidfile

type Pidfile string

func (*Pidfile) Delete added in v0.1.1

func (f *Pidfile) Delete() bool

Delete the pidfile

func (*Pidfile) Read added in v0.1.1

func (f *Pidfile) Read() int

Read the pidfile.

func (*Pidfile) Write added in v0.1.1

func (f *Pidfile) Write(data int) error

Write the pidfile.

type Process

type Process struct {
	Name    string
	Command string
	Env     []string
	Dir     string
	Args    []string
	User    string
	Pidfile Pidfile
	Logfile string
	Errfile string
	Respawn int
	Delay   string
	Ping    string
	Debug   bool

	// Options
	// HideWindow bool // for windows
	Options map[string]interface{} `json:",omitempty" xml:",omitempty"`
	// contains filtered or unexported fields
}

func Add added in v0.1.1

func Add(name string, procs *Process, run ...bool) *Process

func Child added in v0.1.1

func Child(name string) *Process

func New added in v0.1.1

func New() *Process

func NewProcess added in v0.1.1

func NewProcess(name string, command string, args ...string) *Process

func RestartChild added in v0.1.1

func RestartChild(name string) (*Process, error)

func StartChild added in v0.1.1

func StartChild(name string) (*Process, error)

func (*Process) Add added in v0.1.1

func (p *Process) Add(name string, procs *Process, run ...bool) *Process

func (*Process) AddHook added in v0.1.1

func (p *Process) AddHook(status string, hooks ...func(procs *Process)) *Process

func (*Process) Child added in v0.1.1

func (p *Process) Child(name string) *Process

func (*Process) ChildKeys added in v0.1.1

func (p *Process) ChildKeys() []string

func (*Process) DailyRotate added in v0.3.1

func (p *Process) DailyRotate(keepNum int)

func (*Process) Error added in v0.1.1

func (p *Process) Error() error

func (*Process) Find added in v0.1.1

func (p *Process) Find() (*os.Process, string, error)

Find a process by name

func (*Process) Init added in v0.2.0

func (p *Process) Init() *Process

func (*Process) IsRunning added in v0.3.0

func (p *Process) IsRunning(name string) bool

func (*Process) LogKeepNum added in v0.3.1

func (p *Process) LogKeepNum() int

func (*Process) Pid

func (p *Process) Pid() int

func (*Process) Reset added in v0.1.1

func (p *Process) Reset() error

func (*Process) Restart added in v0.1.1

func (p *Process) Restart() (*Process, string)

Restart the process

func (*Process) RestartChild added in v0.1.1

func (p *Process) RestartChild(name string) (*Process, error)

func (*Process) Rotate added in v0.3.1

func (p *Process) Rotate(keepNum int)

func (*Process) Run added in v0.1.1

func (p *Process) Run()

Run child processes

func (*Process) RunHook added in v0.1.1

func (p *Process) RunHook(status string)

func (*Process) SetAndTriggerStatus added in v0.2.5

func (p *Process) SetAndTriggerStatus(status string)

func (*Process) SetChildKV added in v0.2.0

func (p *Process) SetChildKV(name string, proc *Process)

func (*Process) SetChildren added in v0.2.0

func (p *Process) SetChildren(children map[string]*Process)

func (*Process) SetError added in v0.2.5

func (p *Process) SetError(err error)

func (*Process) SetHook added in v0.1.1

func (p *Process) SetHook(status string, hooks ...func(procs *Process)) *Process

func (*Process) SetLogKeepNum added in v0.3.1

func (p *Process) SetLogKeepNum(keepNum int)

func (*Process) SetStatus added in v0.2.5

func (p *Process) SetStatus(status string, dontTriggerEvent ...bool)

func (*Process) SetX added in v0.2.5

func (p *Process) SetX(x Processer)

func (*Process) Start added in v0.1.1

func (p *Process) Start(name string) string

Start the process

func (*Process) StartChild added in v0.1.1

func (p *Process) StartChild(name string) (*Process, error)

func (*Process) StartProcess added in v0.2.5

func (p *Process) StartProcess(name string, argv []string, attr *os.ProcAttr) (Processer, error)

func (*Process) Status

func (p *Process) Status() string

func (*Process) Stop added in v0.1.1

func (p *Process) Stop() string

Stop the process

func (*Process) StopChild added in v0.1.1

func (p *Process) StopChild(name string) error

func (*Process) String

func (p *Process) String() string

func (*Process) X added in v0.2.5

func (p *Process) X() Processer

type Processer added in v0.2.5

type Processer interface {
	Kill() error
	Release() error
	Wait() (*os.ProcessState, error)
	Pid() int
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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