package spawn

import "github.com/docker/docker/engine/spawn"

Index

Functions

func Init

func Init(f engine.Installer) error

Init checks if the current process has been created by Spawn.

If no, it returns nil and the original program can continue unmodified.

If no, it hijacks the process to run as a child worker controlled by its parent over a beam connection, with f exposed as a remote service. In this case Init never returns.

The hijacking process takes place as follows:

NOTE: Init must be called at the beginning of the same program calling Spawn. This is because Spawn approximates a "fork" by re-executing the current binary - where it expects spawn.Init to intercept the control flow and execute the worker code.

func Spawn

func Spawn() (*engine.Engine, error)

Spawn starts a new Engine in a child process and returns a proxy Engine through which it can be controlled.

The commands available on the child engine are determined by an earlier call to Init. It is important that Init be called at the very beginning of the current program - this allows it to be called as a re-execution hook in the child process.

Long story short, if you want to expose `myservice` in a child process, do this:

func main() {
    spawn.Init(myservice)
    [..]
    child, err := spawn.Spawn()
    [..]
    child.Job("dosomething").Run()
}

Source Files

spawn.go

Directories

PathSynopsis
engine/spawn/subengine
Version
v0.12.0
Published
Jun 6, 2014
Platform
js/wasm
Imports
6 packages
Last checked
1 minute ago

Tools for package owners.