mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-09-29 14:21:32 +00:00
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>
67 lines
1.3 KiB
Go
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)
|
|
}
|