bpm

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultProcPrefix = "/proc"
)

Variables

This section is empty.

Functions

func GetNsPath

func GetNsPath(pid uint32, typ NsType) string

GetNsPath returns corresponding namespace path

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

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 NsType

type NsType string
const (
	MountNS NsType = "mnt"
	// uts namespace is not supported yet
	// UtsNS   NsType = "uts"
	IpcNS NsType = "ipc"
	NetNS NsType = "net"
	PidNS NsType = "pid"
)

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
}

func (*Process) Stopped

func (p *Process) Stopped() <-chan struct{}

type ProcessPair

type ProcessPair struct {
	Pid        int
	CreateTime int64
}

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.

Jump to

Keyboard shortcuts

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