Documentation ¶
Index ¶
- Constants
- func GetNsPath(pid uint32, typ NsType) string
- type BackgroundProcessManager
- func (m *BackgroundProcessManager) GetIdentifiers() []string
- func (m *BackgroundProcessManager) GetPipes(uid string) (Pipes, bool)
- func (m *BackgroundProcessManager) GetUID(pair ProcessPair) (string, bool)
- func (m *BackgroundProcessManager) KillBackgroundProcess(ctx context.Context, uid string) error
- func (m *BackgroundProcessManager) Shutdown(ctx context.Context)
- func (m *BackgroundProcessManager) StartProcess(ctx context.Context, cmd *ManagedCommand) (*Process, error)
- type CommandBuilder
- func (b *CommandBuilder) Build(ctx context.Context) *ManagedCommand
- func (b *CommandBuilder) EnableLocalMnt() *CommandBuilder
- func (b *CommandBuilder) EnablePause() *CommandBuilder
- func (b *CommandBuilder) SetContext(ctx context.Context) *CommandBuilder
- func (b *CommandBuilder) SetEnv(key, value string) *CommandBuilder
- func (b *CommandBuilder) SetIdentifier(id string) *CommandBuilder
- func (b *CommandBuilder) SetNS(pid uint32, typ NsType) *CommandBuilder
- func (b *CommandBuilder) SetNSOpt(options []nsOption) *CommandBuilder
- func (b *CommandBuilder) SetOOMScoreAdj(scoreAdj int) *CommandBuilder
- func (b *CommandBuilder) SetStderr(stderr io.ReadWriteCloser) *CommandBuilder
- func (b *CommandBuilder) SetStdin(stdin io.ReadWriteCloser) *CommandBuilder
- func (b *CommandBuilder) SetStdout(stdout io.ReadWriteCloser) *CommandBuilder
- type ManagedCommand
- type NsType
- type Pipes
- type Process
- type ProcessPair
Constants ¶
const (
DefaultProcPrefix = "/proc"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BackgroundProcessManager ¶
type BackgroundProcessManager struct {
// contains filtered or unexported fields
}
BackgroundProcessManager manages all background processes
func StartBackgroundProcessManager ¶
func StartBackgroundProcessManager(registry prometheus.Registerer, rootLogger logr.Logger) *BackgroundProcessManager
StartBackgroundProcessManager creates a background process manager
func (*BackgroundProcessManager) GetIdentifiers ¶
func (m *BackgroundProcessManager) GetIdentifiers() []string
GetIdentifiers finds all identifiers in BPM
func (*BackgroundProcessManager) GetPipes ¶
func (m *BackgroundProcessManager) GetPipes(uid string) (Pipes, bool)
func (*BackgroundProcessManager) GetUID ¶
func (m *BackgroundProcessManager) GetUID(pair ProcessPair) (string, bool)
func (*BackgroundProcessManager) KillBackgroundProcess ¶
func (m *BackgroundProcessManager) KillBackgroundProcess(ctx context.Context, uid string) error
KillBackgroundProcess sends SIGTERM to process
func (*BackgroundProcessManager) Shutdown ¶
func (m *BackgroundProcessManager) Shutdown(ctx context.Context)
func (*BackgroundProcessManager) StartProcess ¶
func (m *BackgroundProcessManager) StartProcess(ctx context.Context, cmd *ManagedCommand) (*Process, error)
StartProcess manages a process in manager
type CommandBuilder ¶
type CommandBuilder struct {
// contains filtered or unexported fields
}
CommandBuilder builds a exec.Cmd for daemon
func DefaultProcessBuilder ¶
func DefaultProcessBuilder(cmd string, args ...string) *CommandBuilder
DefaultProcessBuilder returns the default process builder
func (*CommandBuilder) Build ¶
func (b *CommandBuilder) Build(ctx context.Context) *ManagedCommand
Build builds the command the ctx argument passes the context information to this function e.g. the corresponding resource name.
func (*CommandBuilder) EnableLocalMnt ¶
func (b *CommandBuilder) EnableLocalMnt() *CommandBuilder
func (*CommandBuilder) EnablePause ¶
func (b *CommandBuilder) EnablePause() *CommandBuilder
EnablePause enables pause for process
func (*CommandBuilder) SetContext ¶
func (b *CommandBuilder) SetContext(ctx context.Context) *CommandBuilder
SetContext sets context for process
func (*CommandBuilder) SetEnv ¶
func (b *CommandBuilder) SetEnv(key, value string) *CommandBuilder
SetEnv sets the environment variables of the process
func (*CommandBuilder) SetIdentifier ¶
func (b *CommandBuilder) SetIdentifier(id string) *CommandBuilder
SetIdentifier sets the identifier of the process
The identifier is used to identify the process in BPM, to confirm only one identified process is running. If one identified process is already running, new processes with the same identifier will be blocked by lock.
func (*CommandBuilder) SetNS ¶
func (b *CommandBuilder) SetNS(pid uint32, typ NsType) *CommandBuilder
SetNS sets the namespace of the process
func (*CommandBuilder) SetNSOpt ¶
func (b *CommandBuilder) SetNSOpt(options []nsOption) *CommandBuilder
SetNSOpt sets the namespace of the process
func (*CommandBuilder) SetOOMScoreAdj ¶
func (b *CommandBuilder) SetOOMScoreAdj(scoreAdj int) *CommandBuilder
SetOOMScoreAdj sets the oom_score_adj for a process oom_score_adj ranges from -1000 to 1000
func (*CommandBuilder) SetStderr ¶
func (b *CommandBuilder) SetStderr(stderr io.ReadWriteCloser) *CommandBuilder
SetStderr sets stderr for process
func (*CommandBuilder) SetStdin ¶
func (b *CommandBuilder) SetStdin(stdin io.ReadWriteCloser) *CommandBuilder
SetStdin sets stdin for process
func (*CommandBuilder) SetStdout ¶
func (b *CommandBuilder) SetStdout(stdout io.ReadWriteCloser) *CommandBuilder
SetStdout sets stdout for process
type ManagedCommand ¶
type ManagedCommand struct { *exec.Cmd // If the identifier is not nil, process manager should make sure no other // process with this identifier is running when executing this command Identifier *string }
ManagedCommand is a process which can be managed by backgroundProcessManager
type Pipes ¶
type Pipes struct { Stdin io.WriteCloser Stdout io.ReadCloser }
pipes that will be connected to the command's stdin/stdout
type Process ¶
type Process struct { Uid string // TODO: remove in v3.x // store create time, to keep compatible with v2.x Pair ProcessPair Cmd *ManagedCommand Pipes Pipes // contains filtered or unexported fields }
type ProcessPair ¶
ProcessPair is an identifier for process Keep compatible with v2.x TODO: remove in v3.x
Currently, the bpm locate managed processes by both PID and create time, because the OS may reuse PID, we must check the create time to avoid locating the wrong process.
However, the two-step locating is messy and the create time may be imprecise (we have fixed a [relevant bug](https://github.com/shirou/gopsutil/pull/1204)). In future version, we should completely remove the two-step locating and identify managed processes by UID only.