Files
linuxkit/pkg/runc/cmd/onboot/main.go
Justin Cormack cb2ca4ef66 Switch runc and containerd startup to be entirely Go
At present they use a small shared function called "prepare"
that does the read-write remounts, that I will switch to doing overlay
mounts soon.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2017-07-26 16:32:09 +01:00

64 lines
1.2 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
}
}
os.Exit(status)
}