Documentation
¶
Overview ¶
Package containerinit is shared by monolith-init, the PID 1 of container VMs (cmd/monolith-init), and the daemon that runs them: the container's process spec and the logic that turns an image's config into a process (command, user, environment, PATH lookup, signals). Their API is the Agent ttRPC service in agentpb. It has no Linux-only code, so it's tested on the Mac.
Index ¶
- Constants
- func Command(entrypoint, cmd []string, overrideEntrypoint *string, args []string) []string
- func Getenv(env []string, key string) (string, bool)
- func LinuxSignal(s string) (int, error)
- func LookPath(root, dir, file, pathEnv string) (string, int, error)
- func MergeEnv(base []string, overrides ...string) []string
- func ProcessEnv(spec Spec, home string) []string
- func ResolvConf(pnp string) string
- type Cred
- type Spec
Constants ¶
const ( ExitInitError = 125 // the init itself failed (mounts, bad spec) ExitNotExecutable = 126 ExitNotFound = 127 )
Exit codes the init reports when the process can't run, as Docker does.
const DefaultPath = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
DefaultPath is used when the image sets no PATH.
const VsockPort = 1025
VsockPort is the vsock port the init serves the Agent API on.
Variables ¶
This section is empty.
Functions ¶
func Command ¶
Command combines an image's entrypoint and cmd with the user's overrides the way `docker run` does: --entrypoint replaces the entrypoint and drops the image's cmd; arguments after the image replace the cmd.
func LinuxSignal ¶
LinuxSignal parses a signal as images and `docker kill` give it ("SIGQUIT", "QUIT", "3") into its Linux number.
func LookPath ¶
LookPath finds file the way execvp does, in the filesystem at root: a name with a slash is used as is (relative to dir), otherwise each PATH entry is tried. It returns the path inside root and the exit code to report if it fails (127 not found, 126 not executable).
func MergeEnv ¶
MergeEnv appends overrides to base; a later KEY replaces an earlier one in place. An override without "=" (e.g. "-e FOO") is skipped here; the caller fills it from its own environment.
func ProcessEnv ¶
ProcessEnv is the environment the process gets: the spec's, plus PATH, HOSTNAME, HOME and (with a terminal) TERM unless already set.
func ResolvConf ¶
ResolvConf turns the kernel's DHCP results (/proc/net/pnp) into resolv.conf: its nameserver, domain and search lines.
Types ¶
type Cred ¶
type Cred struct {
UID, GID uint32
Groups []uint32 // supplementary groups from /etc/group
Home string
}
Cred is who the process runs as.
func ResolveUser ¶
ResolveUser resolves a Docker-style user ("", "name", "uid", "name:group", "uid:gid") against the passwd and group files of the filesystem at root, as runc does: a numeric user that isn't in passwd is still allowed, with gid 0 and home "/".
type Spec ¶
type Spec struct {
Args []string `json:"args"` // command and arguments; Args[0] is looked up in PATH
Env []string `json:"env,omitempty"` // KEY=VALUE, image env then user overrides
Workdir string `json:"workdir,omitempty"` // default "/"
User string `json:"user,omitempty"` // "", "name", "uid", "name:group" or "uid:gid"
Hostname string `json:"hostname,omitempty"`
TTY bool `json:"tty,omitempty"` // run on a terminal (the console), stdin attached
}
Spec describes the container's process. It's saved in the container's config and sent to the init in agentpb.StartRequest.