system

package
v1.20.101 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Zlib Imports: 22 Imported by: 3

Documentation

Index

Constants

View Source
const (
	KStatusRunning = Status(1)
	KStatusClose   = Status(2)
	KStatusExit    = Status(3)
)
View Source
const (
	IptUnk  = IPType(0)
	IptPub  = IPType(1)
	IptPriA = IPType(2)
	IptPriB = IPType(3)
	IptPriC = IPType(4)
)
View Source
const GB = 1024 * 1024 * 1024
View Source
const (
	KLocalHost = "127.0.0.1"
)
View Source
const KMaxGroupCount = 3000

Variables

View Source
var (
	DefaultDaemonConfig           = DaemonConfig{Config: Config{EnableEnv: true, EnableStd: false}}
	DefaultGroupRun     *GroupRun = nil

	CmdNilErr   = errors.New("cmd obj is nil")
	MaxCountErr = errors.New("max count")
	MaxErr      = errors.New("max error")
)
View Source
var (
	TimeoutError = errors.New("operation timed out")
	ClosedError  = errors.New("process closed")
)
View Source
var ErrNormalQuit = errors.New("normal quit")

Functions

func AfterQuit added in v1.8.56

func AfterQuit(t time.Duration)

func AsyncExec added in v1.8.68

func AsyncExec(cmd string) <-chan Result

AsyncExec 异步执行,返回chan

func ChildRunning added in v1.8.0

func ChildRunning(fn func(), exits ...func())

func Close added in v1.8.56

func Close()

func Closed added in v1.8.0

func Closed() <-chan bool

func CpuPercent added in v1.4.9

func CpuPercent() float64

func CreateShellFile added in v1.20.37

func CreateShellFile(pattern, content string) (tmpFile string, err error)

CreateShellFile 创建临时的 shell 脚本文件 content 创建的脚本内容

func DefaultPingFunc added in v1.20.71

func DefaultPingFunc(ip string) error

func GetClientIP added in v1.4.13

func GetClientIP() ([]net.IP, error)

func GetPublicIP added in v0.5.39

func GetPublicIP() (net.IP, error)

func GetPublicIPWithUrl added in v1.1.3

func GetPublicIPWithUrl(url string) (net.IP, error)

func GetQuitCode added in v1.20.9

func GetQuitCode() int32

func GetQuitErr added in v1.20.9

func GetQuitErr() error

func GetResolveIP added in v0.5.39

func GetResolveIP() (net.IP, error)

func GetResolveIPList added in v1.20.71

func GetResolveIPList(filter func(ip net.IP) bool) ([]net.IP, error)

func GetResolveIPV3 added in v1.4.13

func GetResolveIPV3(tt IPType, index int) (net.IP, error)

func IPIsSelf added in v1.1.3

func IPIsSelf(ip string) string

IPIsSelf 是否是自己

func Info

func Info() string

func IsLanIP added in v1.1.3

func IsLanIP(IP net.IP) bool

IsLanIP 是否局域网 192.168.x.x

func IsNormalQuit added in v1.20.9

func IsNormalQuit() bool

func IsPublicIP

func IsPublicIP(IP net.IP) bool

func IsQuit added in v1.20.9

func IsQuit() bool

func MainRunning added in v1.8.0

func MainRunning(fn func(), exits ...func())

func PortUsed added in v1.4.23

func PortUsed(port int) bool

func PortUsedV2 added in v1.20.75

func PortUsedV2(ip string, port int) bool

func PortsUsed added in v1.4.23

func PortsUsed(ports []int) []bool

func Quit

func Quit(code int)

func QuitApp added in v1.20.9

func QuitApp(code int32)

func Recover added in v1.8.0

func Recover(cleanups ...func())

func SIToString added in v1.4.9

func SIToString(d *DiskPath, m *MemInfo, cpuPercent float64) string

func SetQuitCode added in v1.20.9

func SetQuitCode(code int32)

func SetQuitErr added in v1.20.9

func SetQuitErr(err error)

func Stop added in v1.20.8

func Stop(d time.Duration, stop chan bool)

func StripArgs added in v1.0.58

func StripArgs(args []string, arg string) []string

func Wait added in v1.9.8

func Wait(t time.Duration)

Types

type ArgOption added in v1.6.21

type ArgOption struct {
	Id     int
	AppExe string      // 启动的程序
	Args   []string    //参数
	Env    []string    //环境变量
	Data   interface{} // 用户自己定义
}

type ArgOptionFunc added in v1.6.21

type ArgOptionFunc func(arg *ArgOption)

type Child added in v1.6.21

type Child struct {
	Data interface{}
	// contains filtered or unexported fields
}

func NewChild added in v1.6.21

func NewChild(id int, args []string, data interface{}) *Child

func (*Child) GetId added in v1.6.21

func (it *Child) GetId() int

type Cmd added in v1.6.21

type Cmd struct {
	Cmd  *exec.Cmd
	Err  error
	Data interface{}
	// contains filtered or unexported fields
}

func NewArgCmd added in v1.8.63

func NewArgCmd(id int, args []string, conf *Config, opts ...ArgOptionFunc) (*Cmd, error)

func NewCmd added in v1.6.21

func NewCmd(cmd *exec.Cmd, conf *Config, env ...string) *Cmd

func (*Cmd) AsyncWait added in v1.8.66

func (c *Cmd) AsyncWait(q func(cmd *Cmd, err error))

AsyncWait 异步

func (*Cmd) Kill added in v1.8.63

func (c *Cmd) Kill() error

func (*Cmd) Start added in v1.6.21

func (c *Cmd) Start() error

func (*Cmd) Wait added in v1.8.63

func (c *Cmd) Wait() error

func (*Cmd) WithData added in v1.6.21

func (c *Cmd) WithData(da interface{}) *Cmd

func (*Cmd) WithErr added in v1.6.21

func (c *Cmd) WithErr(err error) *Cmd

type Config added in v1.0.58

type Config struct {
	Stdin     io.Reader
	Stdout    io.Writer
	Stderr    io.Writer
	EnableStd bool `json:"enableStd" yaml:"enableStd" xml:"enableStd"`
	EnableEnv bool `json:"enableEnv" yaml:"enableEnv" xml:"enableEnv"`
}

type CpuInfo added in v1.0.16

type CpuInfo struct {
	User   float64 `json:"user"`
	System float64 `json:"system"`
	Idle   float64 `json:"idle"`
	Nice   float64 `json:"nice"`
}

func Cpu added in v1.0.0

func Cpu() CpuInfo

type Ctrl added in v1.8.68

type Ctrl struct {
}

func NewCtrl added in v1.8.68

func NewCtrl() *Ctrl

func (*Ctrl) Delay added in v1.8.68

func (c *Ctrl) Delay(delay, tick time.Duration, fun func(any) bool, param any, funcDefer func(any) bool, paramDefer any)

func (*Ctrl) DelayOnly added in v1.9.1

func (c *Ctrl) DelayOnly(delay time.Duration, fun func(any) bool, param any, funcDefer func(any) bool, paramDefer any)

func (*Ctrl) RunAfter added in v1.8.68

func (c *Ctrl) RunAfter(timeout time.Duration, task Task) (any, error)

func (*Ctrl) RunWithContext added in v1.8.68

func (c *Ctrl) RunWithContext(ctx context.Context, task Task) (any, error)

func (*Ctrl) Ticker added in v1.8.68

func (c *Ctrl) Ticker(tick time.Duration, fun func(any) bool, param any, funcDefer func(any) bool, paramDefer any)

Ticker 定时调用

type Daemon added in v1.6.21

type Daemon struct {
}

func (*Daemon) Background added in v1.6.21

func (*Daemon) Background(id int, args []string, conf DaemonConfig, opts ...ArgOptionFunc) (*Cmd, error)

func (*Daemon) Group added in v1.6.21

func (*Daemon) Group(group int, args []string, cb ProcessCallback, config DaemonConfig, opts ...ArgOptionFunc)

Group 守护进程启动一个N[1,2000]子进程, 并循环监视

func (*Daemon) Run added in v1.6.21

func (d *Daemon) Run(groupId int, args []string, cb ProcessCallback, config DaemonConfig, opts ...ArgOptionFunc) int

Run 守护进程启动一个子进程, 并循环监视

type DaemonConfig added in v1.6.21

type DaemonConfig struct {
	Config
	MaxCount    int   `json:"maxCount" yaml:"maxCount" xml:"maxCount"`
	MaxError    int   `json:"maxError" yaml:"maxError" xml:"maxError"`
	MinExitTime int64 `json:"minExitTime" yaml:"minExitTime" xml:"minExitTime"`
}

type DiskPath added in v1.0.16

type DiskPath struct {
	Path        string  `json:"path,omitempty"`
	Total       uint64  `json:"total"`
	Free        uint64  `json:"free"`
	Used        uint64  `json:"used"`
	UsedPercent float64 `json:"usedPercent"`
}

func Disk added in v1.0.0

func Disk() DiskPath

func DiskAll added in v1.4.5

func DiskAll() []DiskPath

func DiskWithPath added in v1.8.36

func DiskWithPath(path string) DiskPath

type Event

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

Event represents a one-time event that may occur in the future.

func NewEvent

func NewEvent() *Event

NewEvent returns a new, ready-to-use Event.

func (*Event) Done

func (e *Event) Done() <-chan struct{}

Done returns a channel that will be closed when Fire is called.

func (*Event) Fire

func (e *Event) Fire() bool

Fire causes e to complete. It is safe to call multiple times, and concurrently. It returns true iff this call to Fire caused the signaling channel returned by Done to close.

func (*Event) HasFired

func (e *Event) HasFired() bool

HasFired returns true if Fire has been called.

type ExitSig added in v1.8.0

type ExitSig struct {
	S chan os.Signal
}

func Exit added in v0.2.7

func Exit() *ExitSig

func (*ExitSig) Done added in v1.8.0

func (c *ExitSig) Done() <-chan os.Signal

type GetPublicIPFunc added in v1.9.28

type GetPublicIPFunc func(url string) (net.IP, error)

type GroupRun added in v1.6.21

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

func NewGroup added in v1.6.21

func NewGroup() *GroupRun

func (*GroupRun) Add added in v1.6.21

func (g *GroupRun) Add(id int, it *Child) error

func (*GroupRun) Exec added in v1.6.21

func (g *GroupRun) Exec(cb ProcessCallback, config DaemonConfig, opts ...ArgOptionFunc)

func (*GroupRun) Get added in v1.6.21

func (g *GroupRun) Get(id int) (*Child, bool)

func (*GroupRun) Wait added in v1.6.21

func (g *GroupRun) Wait()

type IP added in v1.20.71

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

func IPX added in v1.20.71

func IPX() *IP

func NewIP added in v1.20.71

func NewIP() *IP

func (*IP) GetAllResolveIP added in v1.20.76

func (p *IP) GetAllResolveIP() []net.IP

func (*IP) GetCurrentPublicIP added in v1.20.73

func (p *IP) GetCurrentPublicIP() net.IP

func (*IP) GetCurrentResolveIP added in v1.20.71

func (p *IP) GetCurrentResolveIP() net.IP

func (*IP) GetResolveIP added in v1.20.71

func (p *IP) GetResolveIP() ([]net.IP, error)

func (*IP) PublicIPValid added in v1.20.71

func (p *IP) PublicIPValid() bool

func (*IP) ResetCurrentPublicIP added in v1.20.73

func (p *IP) ResetCurrentPublicIP() net.IP

func (*IP) ResetCurrentResolveIP added in v1.20.71

func (p *IP) ResetCurrentResolveIP() net.IP

func (*IP) SelectResolveIP added in v1.20.71

func (p *IP) SelectResolveIP(pingFunc PingIPFunc) net.IP

func (*IP) SelfExternalIP added in v1.20.71

func (p *IP) SelfExternalIP(lan bool) string

SelfExternalIP 自己外部IP,可能是局域网IP,公网IP lan 局域网优先

func (*IP) SetCurrentResolveIP added in v1.20.71

func (p *IP) SetCurrentResolveIP(ip net.IP)

func (*IP) SetPingIPFunc added in v1.20.71

func (p *IP) SetPingIPFunc(fn PingIPFunc)

func (*IP) SetPublicIP added in v1.20.71

func (p *IP) SetPublicIP(ip net.IP)

func (*IP) SetPublicIPFunc added in v1.20.71

func (p *IP) SetPublicIPFunc(fn GetPublicIPFunc)

type IPType

type IPType int8

func GetIPType

func GetIPType(ip net.IP) IPType

type MemInfo added in v1.0.0

type MemInfo struct {
	// Total amount of RAM on this system
	Total uint64 `json:"total"`

	// RAM available for programs to allocate
	//
	// This value is computed from the kernel specific values.
	Available uint64 `json:"available"`

	// RAM used by programs
	//
	// This value is computed from the kernel specific values.
	Used uint64 `json:"used"`

	// Percentage of RAM used by programs
	//
	// This value is computed from the kernel specific values.
	UsedPercent float64 `json:"usedPercent"`
}

func Mem added in v1.0.0

func Mem() MemInfo

type Monitor added in v1.4.9

type Monitor struct {
	Dur      int    `json:"dur" yaml:"dur"` //单位秒
	Diff     int64  `json:"diff" yaml:"diff"`
	Count    int    `json:"count" yaml:"count"`
	Cpu      int    `json:"cpu" yaml:"cpu"`
	Mem      int    `json:"mem" yaml:"mem"`
	Disk     int    `json:"disk" yaml:"disk"`
	DiskPath string `json:"diskPath" yaml:"diskPath"`
}

func (*Monitor) RunMonitor added in v1.6.21

func (mon *Monitor) RunMonitor(call func(d []DiskPath, m *MemInfo, cpuPercent float64, flag int) int)

type PingIPFunc added in v1.20.71

type PingIPFunc func(ip string) error

func PingCheck added in v1.20.75

func PingCheck(port int) PingIPFunc

type Process added in v1.20.58

type Process interface {
	// Pid is the process ID for this process.
	Pid() int32

	// PPid is the parent process ID for this process.
	PPid() int32

	// Name name running this process. This is not a path to the
	Name() string

	Path() string
}

Process is the generic interface that is implemented on every platform and provides common operations for processes.

func FindProcessByName added in v1.20.58

func FindProcessByName(name string) (Process, error)

FindProcessByName looks up a single process by pid.

Process will be nil and error will be nil if a matching process is not found.

func FindProcessByPId added in v1.20.58

func FindProcessByPId(pid int32) (Process, error)

FindProcessByPId looks up a single process by pid.

Process will be nil and error will be nil if a matching process is not found.

func Processes added in v1.20.58

func Processes() ([]Process, error)

Processes returns all processes.

This of course will be a point-in-time snapshot of when this method was called. Some operating systems don't provide snapshot capability of the process table, in which case the process table returned might contain ephemeral entities that happened to be running when this was called.

type ProcessCallback added in v1.6.21

type ProcessCallback func(cmd *Cmd, status Status, time int64) int

type RecoverFunc added in v1.8.0

type RecoverFunc func(r any)
var DefRecoverFunc RecoverFunc = func(r any) {
}

type Result added in v1.20.37

type Result struct {
	Command   string
	Err       error
	StartTime time.Time
	EndTime   time.Time
	// contains filtered or unexported fields
}

func SyncCmd added in v1.20.37

func SyncCmd(ctx context.Context, command, env []string, dir string) (Result, error)

func SyncExec added in v1.1.11

func SyncExec(cmd string, second time.Duration) Result

SyncExec 超时同步执行 timeout = 0, default 30 seconds

func (Result) Error added in v1.20.37

func (r Result) Error() string

func (Result) Output added in v1.20.37

func (r Result) Output() string

type Running added in v1.6.6

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

func Go added in v1.8.0

func Go() *Running

func NewRunning added in v1.6.6

func NewRunning() *Running

NewRunning f 是否fire

func (*Running) Count added in v1.20.5

func (m *Running) Count() int32

func (*Running) Done added in v1.6.6

func (m *Running) Done() <-chan struct{}

func (*Running) Run added in v1.6.6

func (m *Running) Run(fire bool, fn func(), exits ...func())

Run if fire=true, select Running.Done()

func (*Running) Wait added in v1.6.6

func (m *Running) Wait()

type RunningCheck added in v1.8.0

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

func (*RunningCheck) GoRunning added in v1.8.59

func (rc *RunningCheck) GoRunning(fn func(), exits ...func())

func (*RunningCheck) GoRunningV2 added in v1.8.59

func (rc *RunningCheck) GoRunningV2(running func(), fn func(), exits ...func())

func (*RunningCheck) IsRunning added in v1.8.0

func (rc *RunningCheck) IsRunning() bool

func (*RunningCheck) TryGoRunning deprecated added in v1.8.0

func (rc *RunningCheck) TryGoRunning(fn func(), exits ...func())

Deprecated: this function simply calls [GoRunning].

type Shell added in v1.0.58

type Shell struct {
}

func (*Shell) Run added in v1.6.21

func (s *Shell) Run(cmd string) Result

Run 阻塞式同步执行

func (*Shell) RunTimeout added in v1.20.37

func (s *Shell) RunTimeout(cmd string, second time.Duration) Result

RunTimeout 阻塞式超时同步执行

func (*Shell) Start added in v1.6.21

func (s *Shell) Start(args []string, config Config, env ...string) error

type Status added in v1.6.21

type Status int

type Task added in v1.8.68

type Task func() (any, error)

Jump to

Keyboard shortcuts

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