system

package
v1.9.24 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: Zlib Imports: 20 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")
)

Functions

func AfterQuit added in v1.8.56

func AfterQuit(second time.Duration)

func AsyncExec added in v1.8.68

func AsyncExec(cmd string) <-chan CmdResult

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 CreateTmpShellFile added in v1.1.11

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

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

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 GetPublicIPIf added in v1.8.48

func GetPublicIPIf() net.IP

func GetPublicIPWithUrl added in v1.1.3

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

func GetResolveIP added in v0.5.39

func GetResolveIP() (net.IP, error)

func GetResolveIPIf added in v1.8.48

func GetResolveIPIf() net.IP

func GetResolveIPV2 added in v0.5.39

func GetResolveIPV2() (net.IP, error)

func GetResolveIPV3 added in v1.4.13

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

func GetResolveIPs added in v1.8.48

func GetResolveIPs(filter func(ip net.IP) bool) ([]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 IsPublicIP

func IsPublicIP(IP net.IP) 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 PortsUsed added in v1.4.23

func PortsUsed(ports []int) []bool

func PublicIPValid added in v0.7.0

func PublicIPValid() bool

func Quit

func Quit(code int)

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 SelfExternalIP added in v1.1.3

func SelfExternalIP(lan bool) string

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

func StripArgs added in v1.0.58

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

func Wait added in v1.9.8

func Wait(second 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) Run added in v1.6.21

func (*Cmd) Run(cmd string, timeout time.Duration) CmdResult

Run 超时同步执行, 等待结果返回 Deprecated: this function simply calls SyncExec.

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 CmdResult added in v1.1.19

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

func SyncExec added in v1.1.11

func SyncExec(cmd string, timeout time.Duration) CmdResult

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

func (CmdResult) Error added in v1.1.19

func (r CmdResult) Error() string

func (CmdResult) Result added in v1.1.19

func (r CmdResult) Result() string

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 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 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      time.Duration `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 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 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) 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) CmdResult

Run 阻塞式同步执行

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