Files
linuxkit/pkg/runc/cmd/onboot/main.go
Justin Cormack eacce1d52e Use overlay for writeable containers
Previously we would sneakily remount as `rw` but of course you can't
really do that on a truly immutable filesystem.

See https://github.com/moby/tool/pull/129 for the `moby` side.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2017-07-31 13:48:23 +01:00

67 lines
1.3 KiB
Go

package main
import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
const (
runcBinary = "/usr/bin/runc"
onbootPath = "/containers/onboot"
shutdownPath = "/containers/onshutdown"
)
func main() {
// try to work out how we are being called
command := os.Args[0]
if len(os.Args) > 1 {
command = os.Args[1]
}
var path = onbootPath
switch {
case strings.Contains(command, "boot"):
path = onbootPath
case strings.Contains(command, "shutdown"):
path = shutdownPath
}
// do nothing if the path does not exist
if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
os.Exit(0)
}
// get files; note ReadDir already sorts them
files, err := ioutil.ReadDir(path)
if err != nil {
log.Fatalf("Cannot read files in %s: %v", path, err)
}
status := 0
for _, file := range files {
name := file.Name()
fullPath := filepath.Join(path, name)
if err := prepare(fullPath); err != nil {
log.Printf("Error preparing %s: %v", name, err)
status = 1
continue
}
cmd := exec.Command(runcBinary, "run", "--bundle", fullPath, name)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Printf("Error running %s: %v", name, err)
status = 1
} else {
// do not clean up on error to make debug easier
cleanup(fullPath)
}
}
os.Exit(status)
}