cmdx

package module
v0.0.0-...-c6a0258 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDone    = errors.New("done")
	ErrStop    = errors.New("user stop")
	ErrRestart = errors.New("user restart")
	ErrStatus  = errors.New("error status")
)

Functions

func Elapsed

func Elapsed(t ...time.Time) time.Duration

func Rotate

func Rotate(options RotateOptions) io.WriteCloser

Types

type Env

type Env []string

func (Env) Compact

func (e Env) Compact() Env

func (Env) Del

func (e Env) Del(keys ...string) Env

func (Env) Set

func (e Env) Set(k, v string) Env

func (Env) Sets

func (e Env) Sets(env ...string) Env

type Logger

type Logger struct {
	*RotateOptions `json:",inline" yaml:",inline"`
	Stderr         *RotateOptions `json:"stderr,omitempty" yaml:"stderr,omitempty"`
	Stdout         *RotateOptions `json:"stdout,omitempty" yaml:"stdout,omitempty"`
}

type LoggerFactory

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

func (LoggerFactory) Close

func (f LoggerFactory) Close() error

func (LoggerFactory) Create

func (f LoggerFactory) Create(options ...*RotateOptions) io.Writer

type Option

type Option func(*Options)

func WithOptions

func WithOptions(options Options) Option

type Options

type Options struct {
	Execute      string        `json:"execute,omitempty" yaml:"execute,omitempty"`
	Args         []string      `json:"args,omitempty" yaml:"args,omitempty"`
	Dir          string        `json:"dir,omitempty" yaml:"dir,omitempty"`
	Env          []string      `json:"env,omitempty" yaml:"env,omitempty"`
	RestartDelay time.Duration `json:"restart_delay,omitempty" yaml:"restart_delay,omitempty"`
	Logger       *Logger       `json:"logger,omitempty" yaml:"logger,omitempty"`

	PreStart []func(c *exec.Cmd) error `json:"-" yaml:"-"`
}

type Result

type Result struct {
	Command string

	Restart func()
	Stop    func()
	Wait    func()

	Status Status // status
	Pid    int    // pid
	Exit   int    // exit code
	Err    error  // error

	StartTs int64
	StopTs  int64

	Changed <-chan Status
}

func Run

func Run(ctx context.Context, options ...Option) *Result

type RotateOptions

type RotateOptions struct {
	Path       string `json:"path,omitempty" yaml:"path,omitempty"`               // 文件路径
	Std        string `json:"std,omitempty" yaml:"std,omitempty"`                 // 标准输出
	MaxSize    int64  `json:"max_size,omitempty" yaml:"max_size,omitempty"`       // 单文件最大大小
	MaxBackups int    `json:"max_backups,omitempty" yaml:"max_backups,omitempty"` // 最大备份文件数量
}

type Status

type Status int

Status is a status code.

const (
	StatusUnknown    Status = iota // unknown
	StatusStarting                 // starting
	StatusRunning                  // running
	StatusRestarting               // restarting
	StatusStopping                 // stopping
	StatusStopped                  // stopped
)

func (Status) String

func (s Status) String() string

String returns the string representation of the status code.

Jump to

Keyboard shortcuts

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