From 764ce78c1df1e49295233ad498e66f7e89fbdbab Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 10 Oct 2013 10:53:38 +0200 Subject: [PATCH 1/3] Move SysInit to a submodule This allows docker-init to not import the main docker module, which means it won't e.g. pick up any sqlite dependencies. --- docker-init/docker-init.go | 16 ++++++++++++++++ docker/docker.go | 3 ++- runtime_test.go | 3 ++- sysinit.go => sysinit/sysinit.go | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 docker-init/docker-init.go rename sysinit.go => sysinit/sysinit.go (99%) diff --git a/docker-init/docker-init.go b/docker-init/docker-init.go new file mode 100644 index 000000000..0c363f4ac --- /dev/null +++ b/docker-init/docker-init.go @@ -0,0 +1,16 @@ +package main + +import ( + "github.com/dotcloud/docker/sysinit" +) + +var ( + GITCOMMIT string + VERSION string +) + +func main() { + // Running in init mode + sysinit.SysInit() + return +} diff --git a/docker/docker.go b/docker/docker.go index 750d63c06..deae9b616 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "github.com/dotcloud/docker" + "github.com/dotcloud/docker/sysinit" "github.com/dotcloud/docker/utils" "io/ioutil" "log" @@ -22,7 +23,7 @@ var ( func main() { if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" { // Running in init mode - docker.SysInit() + sysinit.SysInit() return } // FIXME: Switch d and D ? (to be more sshd like) diff --git a/runtime_test.go b/runtime_test.go index 1abbcc51e..ee77b4f51 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -3,6 +3,7 @@ package docker import ( "bytes" "fmt" + "github.com/dotcloud/docker/sysinit" "github.com/dotcloud/docker/utils" "io" "log" @@ -77,7 +78,7 @@ func init() { // Hack to run sys init during unit testing if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" { - SysInit() + sysinit.SysInit() return } diff --git a/sysinit.go b/sysinit/sysinit.go similarity index 99% rename from sysinit.go rename to sysinit/sysinit.go index 34f1cbdac..2c433d7d4 100644 --- a/sysinit.go +++ b/sysinit/sysinit.go @@ -1,4 +1,4 @@ -package docker +package sysinit import ( "flag" From 7591a69108562caba00d888ab6ff481a63fbb23c Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 10 Sep 2013 20:15:23 +0200 Subject: [PATCH 2/3] Add a separate docker-init binary This may be used for the .dockerinit case if the main binary is not statically linked. Conflicts: docker-init/docker-init.go From 34365ececa870ba370529d12870dbfe72efb5bdd Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 17 Oct 2013 23:39:57 -0600 Subject: [PATCH 3/3] Rename all cases of "docker-init" to "dockerinit" for consistency --- container.go | 2 +- docker-init/docker-init.go => dockerinit/dockerinit.go | 0 lxc_template.go | 2 +- sysinit/sysinit.go | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename docker-init/docker-init.go => dockerinit/dockerinit.go (100%) diff --git a/container.go b/container.go index 7d85aef0a..7b5229067 100644 --- a/container.go +++ b/container.go @@ -951,7 +951,7 @@ func (container *Container) releaseNetwork() { container.NetworkSettings = &NetworkSettings{} } -// FIXME: replace this with a control socket within docker-init +// FIXME: replace this with a control socket within dockerinit func (container *Container) waitLxc() error { for { output, err := exec.Command("lxc-info", "-n", container.ID).CombinedOutput() diff --git a/docker-init/docker-init.go b/dockerinit/dockerinit.go similarity index 100% rename from docker-init/docker-init.go rename to dockerinit/dockerinit.go diff --git a/lxc_template.go b/lxc_template.go index 0e2dfafd4..3faea04c5 100644 --- a/lxc_template.go +++ b/lxc_template.go @@ -92,7 +92,7 @@ lxc.mount.entry = devpts {{$ROOTFS}}/dev/pts devpts newinstance,ptmxmode=0666,no #lxc.mount.entry = varlock {{$ROOTFS}}/var/lock tmpfs size=1024k,nosuid,nodev,noexec 0 0 lxc.mount.entry = shm {{$ROOTFS}}/dev/shm tmpfs size=65536k,nosuid,nodev,noexec 0 0 -# Inject docker-init +# Inject dockerinit lxc.mount.entry = {{.SysInitPath}} {{$ROOTFS}}/.dockerinit none bind,ro 0 0 # In order to get a working DNS environment, mount bind (ro) the host's /etc/resolv.conf into the container diff --git a/sysinit/sysinit.go b/sysinit/sysinit.go index 2c433d7d4..2e80327e8 100644 --- a/sysinit/sysinit.go +++ b/sysinit/sysinit.go @@ -86,7 +86,7 @@ func executeProgram(name string, args []string) { // up the environment before running the actual process func SysInit() { if len(os.Args) <= 1 { - fmt.Println("You should not invoke docker-init manually") + fmt.Println("You should not invoke dockerinit manually") os.Exit(1) } var u = flag.String("u", "", "username or uid")