2015-06-27 09:15:48 +08:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
|
|
|
_ "github.com/opencontainers/runc/libcontainer/nsenter"
|
2016-06-07 02:45:46 +08:00
|
|
|
"github.com/urfave/cli"
|
2016-05-14 06:49:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
if len(os.Args) > 1 && os.Args[1] == "init" {
|
|
|
|
runtime.GOMAXPROCS(1)
|
|
|
|
runtime.LockOSThread()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var initCommand = cli.Command{
|
|
|
|
Name: "init",
|
|
|
|
Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`,
|
2016-06-08 05:42:54 +08:00
|
|
|
Action: func(context *cli.Context) error {
|
2016-05-14 06:49:45 +08:00
|
|
|
factory, _ := libcontainer.New("")
|
|
|
|
if err := factory.StartInitialization(); err != nil {
|
|
|
|
// as the error is sent back to the parent there is no need to log
|
|
|
|
// or write it to stderr because the parent process will handle this
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
panic("libcontainer: container init failed to exec")
|
|
|
|
},
|
|
|
|
}
|