2013-10-10 04:53:38 -04:00
|
|
|
package sysinit
|
2013-02-13 17:01:44 -05:00
|
|
|
|
|
|
|
import (
|
2013-02-13 20:24:35 -05:00
|
|
|
"flag"
|
2013-02-13 17:01:44 -05:00
|
|
|
"fmt"
|
2014-04-17 17:43:01 -04:00
|
|
|
"github.com/dotcloud/docker/daemon/execdriver"
|
|
|
|
_ "github.com/dotcloud/docker/daemon/execdriver/lxc"
|
|
|
|
_ "github.com/dotcloud/docker/daemon/execdriver/native"
|
2013-02-13 17:01:44 -05:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2014-01-15 16:57:07 -05:00
|
|
|
func executeProgram(args *execdriver.InitArgs) error {
|
|
|
|
dockerInitFct, err := execdriver.GetInitFunc(args.Driver)
|
2013-02-13 20:24:35 -05:00
|
|
|
if err != nil {
|
2014-01-13 21:36:59 -05:00
|
|
|
panic(err)
|
2013-02-13 20:24:35 -05:00
|
|
|
}
|
2014-01-13 21:36:59 -05:00
|
|
|
return dockerInitFct(args)
|
2013-02-13 20:24:35 -05:00
|
|
|
}
|
|
|
|
|
2013-02-13 17:01:44 -05:00
|
|
|
// Sys Init code
|
|
|
|
// This code is run INSIDE the container and is responsible for setting
|
|
|
|
// up the environment before running the actual process
|
|
|
|
func SysInit() {
|
|
|
|
if len(os.Args) <= 1 {
|
2013-10-18 01:39:57 -04:00
|
|
|
fmt.Println("You should not invoke dockerinit manually")
|
2013-02-13 17:01:44 -05:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2014-01-20 19:05:07 -05:00
|
|
|
var (
|
|
|
|
// Get cmdline arguments
|
|
|
|
user = flag.String("u", "", "username or uid")
|
|
|
|
gateway = flag.String("g", "", "gateway address")
|
|
|
|
ip = flag.String("i", "", "ip address")
|
|
|
|
workDir = flag.String("w", "", "workdir")
|
|
|
|
privileged = flag.Bool("privileged", false, "privileged mode")
|
|
|
|
mtu = flag.Int("mtu", 1500, "interface mtu")
|
|
|
|
driver = flag.String("driver", "", "exec driver")
|
2014-02-24 15:21:13 -05:00
|
|
|
pipe = flag.Int("pipe", 0, "sync pipe fd")
|
|
|
|
console = flag.String("console", "", "console (pty slave) path")
|
2014-02-25 15:41:31 -05:00
|
|
|
root = flag.String("root", ".", "root path for configuration files")
|
2014-01-20 19:05:07 -05:00
|
|
|
)
|
2013-02-13 20:24:35 -05:00
|
|
|
flag.Parse()
|
2013-02-20 20:45:46 -05:00
|
|
|
|
2014-01-15 16:57:07 -05:00
|
|
|
args := &execdriver.InitArgs{
|
2014-01-13 21:36:59 -05:00
|
|
|
User: *user,
|
|
|
|
Gateway: *gateway,
|
|
|
|
Ip: *ip,
|
|
|
|
WorkDir: *workDir,
|
|
|
|
Privileged: *privileged,
|
|
|
|
Args: flag.Args(),
|
|
|
|
Mtu: *mtu,
|
|
|
|
Driver: *driver,
|
2014-02-24 15:21:13 -05:00
|
|
|
Console: *console,
|
|
|
|
Pipe: *pipe,
|
2014-02-25 15:41:31 -05:00
|
|
|
Root: *root,
|
2013-12-02 13:58:45 -05:00
|
|
|
}
|
|
|
|
|
2013-12-02 17:21:29 -05:00
|
|
|
if err := executeProgram(args); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2013-02-13 17:01:44 -05:00
|
|
|
}
|