mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Register built-in engine commands at runtime instead of compile-time
This allows selective loading of commands, and paves the way to dynamic plugins. Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
aed7fe1cda
commit
919665a20a
6 changed files with 45 additions and 21 deletions
|
@ -50,10 +50,6 @@ func ValidateHost(val string) (string, error) {
|
||||||
|
|
||||||
type HttpApiFunc func(eng *engine.Engine, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error
|
type HttpApiFunc func(eng *engine.Engine, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error
|
||||||
|
|
||||||
func init() {
|
|
||||||
engine.Register("serveapi", ServeApi)
|
|
||||||
}
|
|
||||||
|
|
||||||
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
||||||
conn, _, err := w.(http.Hijacker).Hijack()
|
conn, _, err := w.(http.Hijacker).Hijack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
40
builtins/builtins.go
Normal file
40
builtins/builtins.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package builtins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dotcloud/docker/engine"
|
||||||
|
|
||||||
|
"github.com/dotcloud/docker"
|
||||||
|
"github.com/dotcloud/docker/api"
|
||||||
|
"github.com/dotcloud/docker/networkdriver/lxc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Register(eng *engine.Engine) {
|
||||||
|
daemon(eng)
|
||||||
|
remote(eng)
|
||||||
|
}
|
||||||
|
|
||||||
|
// remote: a RESTful api for cross-docker communication
|
||||||
|
func remote(eng *engine.Engine) {
|
||||||
|
eng.Register("serveapi", api.ServeApi)
|
||||||
|
}
|
||||||
|
|
||||||
|
// daemon: a default execution and storage backend for Docker on Linux,
|
||||||
|
// with the following underlying components:
|
||||||
|
//
|
||||||
|
// * Pluggable storage drivers including aufs, vfs, lvm and btrfs.
|
||||||
|
// * Pluggable execution drivers including lxc and chroot.
|
||||||
|
//
|
||||||
|
// In practice `daemon` still includes most core Docker components, including:
|
||||||
|
//
|
||||||
|
// * The reference registry client implementation
|
||||||
|
// * Image management
|
||||||
|
// * The build facility
|
||||||
|
// * Logging
|
||||||
|
//
|
||||||
|
// These components should be broken off into plugins of their own.
|
||||||
|
//
|
||||||
|
func daemon(eng *engine.Engine) {
|
||||||
|
eng.Register("initserver", docker.InitServer)
|
||||||
|
eng.Register("init_networkdriver", lxc.InitDriver)
|
||||||
|
eng.Register("version", docker.GetVersion)
|
||||||
|
}
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
_ "github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/api"
|
"github.com/dotcloud/docker/api"
|
||||||
|
"github.com/dotcloud/docker/builtins"
|
||||||
"github.com/dotcloud/docker/dockerversion"
|
"github.com/dotcloud/docker/dockerversion"
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
flag "github.com/dotcloud/docker/pkg/mflag"
|
flag "github.com/dotcloud/docker/pkg/mflag"
|
||||||
|
@ -81,6 +81,8 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
// Load builtins
|
||||||
|
builtins.Register(eng)
|
||||||
// load the daemon in the background so we can immediately start
|
// load the daemon in the background so we can immediately start
|
||||||
// the http api so that connections don't fail while the daemon
|
// the http api so that connections don't fail while the daemon
|
||||||
// is booting
|
// is booting
|
||||||
|
|
|
@ -57,12 +57,6 @@ var (
|
||||||
currentInterfaces = make(map[string]*networkInterface)
|
currentInterfaces = make(map[string]*networkInterface)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
if err := engine.Register("init_networkdriver", InitDriver); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitDriver(job *engine.Job) engine.Status {
|
func InitDriver(job *engine.Job) engine.Status {
|
||||||
var (
|
var (
|
||||||
network *net.IPNet
|
network *net.IPNet
|
||||||
|
|
|
@ -34,14 +34,10 @@ func (srv *Server) Close() error {
|
||||||
return srv.runtime.Close()
|
return srv.runtime.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
engine.Register("initserver", jobInitServer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// jobInitApi runs the remote api server `srv` as a daemon,
|
// jobInitApi runs the remote api server `srv` as a daemon,
|
||||||
// Only one api server can run at the same time - this is enforced by a pidfile.
|
// Only one api server can run at the same time - this is enforced by a pidfile.
|
||||||
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
|
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
|
||||||
func jobInitServer(job *engine.Job) engine.Status {
|
func InitServer(job *engine.Job) engine.Status {
|
||||||
job.Logf("Creating server")
|
job.Logf("Creating server")
|
||||||
srv, err := NewServer(job.Eng, DaemonConfigFromJob(job))
|
srv, err := NewServer(job.Eng, DaemonConfigFromJob(job))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,11 +7,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func GetVersion(job *engine.Job) engine.Status {
|
||||||
engine.Register("version", jobVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
func jobVersion(job *engine.Job) engine.Status {
|
|
||||||
if _, err := dockerVersion().WriteTo(job.Stdout); err != nil {
|
if _, err := dockerVersion().WriteTo(job.Stdout); err != nil {
|
||||||
job.Errorf("%s", err)
|
job.Errorf("%s", err)
|
||||||
return engine.StatusErr
|
return engine.StatusErr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue