ginit

package module
v0.0.0-...-913244f Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2017 License: MIT Imports: 16 Imported by: 0

README

ginit

fit

CircleCI Godoc

ginit is a high(er) level library for initializing Linux. The goal of ginit is to make it possible to launch PID 1 processes in Go and initialize a Linux OS without writing shell scripts or relying on existing /sbin/init implementations. Ginit is intended for consumption by mesanine and also Linuxkit. This library will be majorly refactored several times before becoming stable!

Documentation

Overview

ginit is a high(er) level library for Linux. It is intended for consumption by mesanine and also Linuxkit. This library will be majorly refactored several times before becoming stable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(args ScriptArgs) error

Call executes the script parameters copying the existing environment into the command. Call blocks until the command is finished and stdout/stderr have been synchronized with OnStdout/OnSterr functions.

func CopyFileInfo

func CopyFileInfo(info os.FileInfo, path string) error

CopyFileInfo takes an os.FileInfo and applies it to a file at the given path.

func Exec

func Exec(exe string, args ...string) error

Exec does an execve with provided arguments it appends the executable to the front of the arguments and copies the existing environment.

func Hostname

func Hostname(prefix string) (string, error)

Hostname generates a hostname based on the prefix and the first valid MAC address from sysfs.

func Init

func Init(children ...Handler) error

Init launches an "origin" signal handler propagating any signal it receives to it's children. If any child returns an error it will be passed back to the caller. Assuming the calling program is running as PID 1, the caller can print an informative message and then exit causing a kernel panic. If we receive SIGUSR1, SIGUSR2, or SIGTERM we trigger a halt, poweroff, or restart command with a syscall to the kernel. Resources: https://github.com/mirror/busybox/tree/master/init https://github.com/torvalds/linux/blob/master/kernel/reboot.c

func IsMemFS

func IsMemFS(path string) (bool, error)

Check if a filesystem is memory based i.e. tempfs or ramfs

func IsRoot

func IsRoot() bool

func Mount

func Mount(args MountArgs, opts ...MountOption) error

Mount performs the unix.Mount syscall

func MustMount

func MustMount(args MountArgs, opts ...MountOption)

MustMount performs a unix.Mount syscall and panics on failure.

func SwitchRoot

func SwitchRoot(opts SwitchOptions) error

Most of this code comes from Linuxkit's init package: https://github.com/linuxkit/linuxkit/blob/master/pkg/init/cmd/init/init.go

func Unmount

func Unmount(path string) error

Unmount unmounts a file system at the specified path

Types

type Controller

type Controller struct {
	Name       string
	Hierarchy  int
	NumCgroups int
	Enabled    bool
}

Controller represents a cgroup system controller see http://man7.org/linux/man-pages/man7/cgroups.7.html

func ReadControllers

func ReadControllers() ([]Controller, error)

ReadControllers returns Cgroup controllers listed at /proc/cgroups Modified from https://github.com/opencontainers/runc/blob/master/libcontainer/cgroups/utils.go

type Handler

type Handler interface {
	Signal(os.Signal) error
}

Handler responds to an os.Signal in some meaningful way.

type KeyFS

type KeyFS struct {
	Base string
}

KeyFS implements a simple structure for interacting with "key" based filesystems like procfs and sysfs.

func (KeyFS) Find

func (k KeyFS) Find(dir, name string, follow bool) ([]string, error)

Find traverses the path below the Base path and optionally follows one level of symbolic link. For example, to find the mac addresses of all network devices you could do: Find("/class/net", "address", true) And it will return an array of resolved devices at /sys/devices/pci...

func (KeyFS) Read

func (k KeyFS) Read(key string) ([]byte, error)

Read reads from the given key

func (KeyFS) Write

func (k KeyFS) Write(key string, value []byte) error

Write writes to the given key

type MountArgs

type MountArgs struct {
	Source string
	Target string
	FSType string
	Flags  uintptr
	// mount -o options
	// TODO: Make strongly typed.
	Data   string
	Before func() error
}

MountArgs hold arguments for making unix.Mount syscalls.

func Bind

func Bind(path string, readOnly bool) MountArgs

Bind returns arguments for perofmring a Bind mount.

func Overlay

func Overlay(lower, target string) MountArgs

Overlay returns options for performing an OverlayFS mount.

func TmpFS

func TmpFS(path string, percentage int) MountArgs

TmpFS return options for performing a tmpfs mount at the given path percentage must be between 0 and 100 or we will panic. If it is zero we do not specify any flags.

type MountOption

type MountOption func(MountArgs) MountArgs

Option is a functional option to modify MountArgs.

func Data

func Data(data string) MountOption

Data changes the MountArgs Data prarameter.

func Mkdir

func Mkdir(mode os.FileMode) MountOption

Mkdir creates the target directory if it is missing before performing a mount operation.

type ScriptArgs

type ScriptArgs struct {
	Cmd  string
	Args []string
	// OnStdout is passed each line
	// the script writes to stdout
	OnStdout func(string)
	// OnStderr is passed each line
	// the script writes to stderr
	OnStderr func(string)
}

type SwitchOptions

type SwitchOptions struct {
	BufSize int
	RootDev uint64
	NewRoot string
}

func NewSwitchOptions

func NewSwitchOptions(path string) (*SwitchOptions, error)

Jump to

Keyboard shortcuts

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