...

Package linux

import "golang.conradwood.net/go-easyops/linux"
Overview
Index

Overview ▾

Package linux provides methods to execute commands on linux

Constants

const (
    INITPID        = 1
    STATUS_RUNNING = 1
    STATUS_STOPPED = 2
)
const (
    READ_MILLIS = 5000
)

Variables

var (
    LogExe = flag.Bool("ge_debug_exe", false, "debug execution of third party binaries")
)

func Copy

func Copy(srcFile, dstFile string) error

func CopyDir

func CopyDir(srcDir, dest string) error
func CopySymLink(source, dest string) error

func CreateIfNotExists

func CreateIfNotExists(dir string, perm os.FileMode) error

func CreateStandardAdjacentCgroup

func CreateStandardAdjacentCgroup() (string, error)

if caller is in cgroup "/LINUXCOM/ancestor/me", new cgrop will be "/LINUXCOM/ancestor/com_1"

func CreateStandardCgroup

func CreateStandardCgroup(dir string) error

func DirSize

func DirSize(dir string) (uint64, error)

if dir is the name of a directory, it will recursively calculate the size. if it is a file, it will stat it and return the filesize

func Exists

func Exists(filePath string) bool

func MyCgroup

func MyCgroup() (string, error)

type ComInstance

type ComInstance interface {
    Wait(ctx context.Context) error    // waits for main command to exit. might leave fork'ed children running
    WaitAll(ctx context.Context) error // waits for all children to exit as well
    Signal(signal syscall.Signal) error
    GetCommand() Command
}

type Command

type Command interface {
    SigInt() error  // -2
    SigKill() error // -9
    SetStdinWriter(r io.Writer)
    SetStdoutReader(r io.Reader)
    SetStderrReader(r io.Reader)
    IsRunning() bool
    SetDebug(bool)
    Start(ctx context.Context, com ...string) (ComInstance, error)
}

func NewCommand

func NewCommand() Command

type LinePrefixPipe

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

func NewLinePrefixPipe

func NewLinePrefixPipe(r io.Reader) *LinePrefixPipe

func (*LinePrefixPipe) Read

func (l *LinePrefixPipe) Read([]byte) (int, error)

type Linux

type Linux interface {
    SafelyExecute(cmd []string, stdin io.Reader) (string, error)
    SafelyExecuteWithDir(cmd []string, dir string, stdin io.Reader) (string, error)
    MyIP() string
    SetMaxRuntime(time.Duration)
    SetRunForever() // incompatible with setmaxruntime
    SetAllowConcurrency(bool)
    SetEnvironment([]string)
    AddFileDescriptor(fd int)
}

func New

func New() Linux

func NewWithContext

func NewWithContext(ctx context.Context) Linux

type Loadavg

type Loadavg struct {
}

func (*Loadavg) GetCPULoad

func (g *Loadavg) GetCPULoad(ctx context.Context, req *common.Void) (*common.CPULoad, error)

type ProcessState

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

func AllPids

func AllPids() ([]*ProcessState, error)

func PidStatus

func PidStatus(pid int) *ProcessState

func (*ProcessState) Binary

func (ps *ProcessState) Binary() string

func (*ProcessState) Cgroup

func (ps *ProcessState) Cgroup() string

func (*ProcessState) Children

func (ps *ProcessState) Children() ([]*ProcessState, error)

func (*ProcessState) ParentPid

func (ps *ProcessState) ParentPid() int

func (*ProcessState) Pid

func (ps *ProcessState) Pid() int

func (*ProcessState) Status

func (ps *ProcessState) Status() STATUS

func (*ProcessState) String

func (ps *ProcessState) String() string

type STATUS

type STATUS int

func (STATUS) String

func (s STATUS) String() string