cmdctrl

package
v0.0.0-...-7a729f8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Like python-supervisor Manager process start, stop, restart Hope no bugs :)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyRunning = errors.New("already running")
	ErrAlreadyStopped = errors.New("already stopped")
)

Functions

func KillProcessByMatchName

func KillProcessByMatchName(processNameMatch string) bool

根据进程名模糊匹配,杀死进程

func KillProcessByName

func KillProcessByName(processName string) bool

根据进程名,杀死进程

Types

type CommandCtrl

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

func New

func New() *CommandCtrl

func (*CommandCtrl) Add

func (cc *CommandCtrl) Add(name string, c CommandInfo) error

func (*CommandCtrl) Exists

func (cc *CommandCtrl) Exists(name string) bool

func (*CommandCtrl) Restart

func (cc *CommandCtrl) Restart(name string) error

func (*CommandCtrl) Running

func (cc *CommandCtrl) Running(name string) bool

Running return bool indicate if program is still running

func (*CommandCtrl) Start

func (cc *CommandCtrl) Start(name string) error

func (*CommandCtrl) Stop

func (cc *CommandCtrl) Stop(name string, waits ...bool) error

Stop send stop signal Stop("demo") will quit immediately Stop("demo", true) will quit until command really killed

func (*CommandCtrl) StopAll

func (cc *CommandCtrl) StopAll()

StopAll command and wait until all program quited

func (*CommandCtrl) UpdateArgs

func (cc *CommandCtrl) UpdateArgs(name string, args ...string) error

UpdateArgs func is not like exec.Command, the first argument name means cmdctl service name the seconds argument args, should like "echo", "hello" Example usage:

UpdateArgs("minitouch", "/data/local/tmp/minitouch", "-t", "1")

type CommandInfo

type CommandInfo struct {
	Environ         []string
	Args            []string
	ArgsFunc        func() ([]string, error) // generate Args when args is dynamic
	MaxRetries      int                      // 3
	NextLaunchWait  time.Duration            // 0.5s
	RecoverDuration time.Duration            // 30s
	StopSignal      os.Signal
	Shell           bool

	OnStart func() error // if return non nil, cmd will not run
	OnStop  func()

	Stderr io.Writer // nil
	Stdout io.Writer // nil
	Stdin  io.Reader // nil
}

Jump to

Keyboard shortcuts

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