Merge plugin into weaver
This simplifies the following: - plugin-v2 does not need to start "plugin" as a separate process, thus Docker is able to properly restart plugin-v2 in a case of any child process failing. - No need for weaveplugin container. plugin is enabled by default when running "weave launch". when starting only the router, you should pass "--plugin" parameter to enable it. The env var WEAVE_NO_PLUGIN is no more.
This commit is contained in:
1 parent
8c917eeb17
commit
1f42a9d2f9
11 files changed
+93
-194
No files matched your search
+10
-30
@@ -8,25 +8,23 @@ HTTP_ADDR=${WEAVE_HTTP_ADDR:-127.0.0.1:6784}
|
||||
STATUS_ADDR=${WEAVE_STATUS_ADDR:-0.0.0.0:6782}
|
||||
HOST_ROOT=${HOST_ROOT:-/host}
|
||||
WEAVE_DIR="/host/var/lib/weave"
|
||||
LOG_FILE_WEAVER="$WEAVE_DIR/weaver.log"
|
||||
LOG_FILE_PLUGIN="$WEAVE_DIR/plugin.log"
|
||||
|
||||
mkdir $WEAVE_DIR || true
|
||||
|
||||
echo "Starting launch.sh" >>$LOG_FILE_WEAVER
|
||||
echo "Starting launch.sh"
|
||||
|
||||
# Check if the IP range overlaps anything existing on the host
|
||||
/usr/bin/weaveutil netcheck $IPALLOC_RANGE weave
|
||||
|
||||
SWARM_PEERS=$(/usr/bin/weaveutil swarm-manager-peers 2>>$LOG_FILE_WEAVER)
|
||||
! /usr/bin/weaveutil is-swarm-manager 2>>$LOG_FILE_WEAVER || IS_SWARM_MANAGER=1
|
||||
SWARM_MANAGER_PEERS=$(/usr/bin/weaveutil swarm-manager-peers)
|
||||
! /usr/bin/weaveutil is-swarm-manager || IS_SWARM_MANAGER=1
|
||||
# Prevent from restoring from a persisted peers list
|
||||
rm -f "/restart.sentinel"
|
||||
|
||||
/home/weave/weave --local create-bridge \
|
||||
--proc-path=/host/proc \
|
||||
--weavedb-dir-path=$WEAVE_DIR \
|
||||
--force >>$LOG_FILE_WEAVER 2>&1
|
||||
--proc-path=/host/proc \
|
||||
--weavedb-dir-path=$WEAVE_DIR \
|
||||
--force
|
||||
|
||||
BRIDGE_OPTIONS="--datapath=datapath"
|
||||
if [ "$(/home/weave/weave --local bridge-type)" = "bridge" ]; then
|
||||
@@ -42,36 +40,18 @@ fi
|
||||
|
||||
if [ -z "$IPALLOC_INIT" ]; then
|
||||
if [ $IS_SWARM_MANAGER == "1" ]; then
|
||||
IPALLOC_INIT="consensus=$(echo $SWARM_PEERS | wc -l)"
|
||||
IPALLOC_INIT="consensus=$(echo $SWARM_MANAGER_PEERS | wc -l)"
|
||||
else
|
||||
IPALLOC_INIT="observer"
|
||||
fi
|
||||
fi
|
||||
|
||||
/home/weave/weaver $EXTRA_ARGS --port=6783 $BRIDGE_OPTIONS \
|
||||
exec /home/weave/weaver $EXTRA_ARGS --port=6783 $BRIDGE_OPTIONS \
|
||||
--http-addr=$HTTP_ADDR --status-addr=$STATUS_ADDR --docker-api='' --no-dns \
|
||||
--ipalloc-range=$IPALLOC_RANGE \
|
||||
--ipalloc-init $IPALLOC_INIT \
|
||||
--nickname "$(hostname)" \
|
||||
--log-level=debug \
|
||||
--db-prefix="$WEAVE_DIR/weave" \
|
||||
$(echo $SWARM_PEERS | tr '\n' ' ') \
|
||||
>>$LOG_FILE_WEAVER 2>&1 &
|
||||
WEAVE_PID=$!
|
||||
|
||||
# Wait for weave process to become responsive
|
||||
while true; do
|
||||
curl $HTTP_ADDR/status >/dev/null 2>&1 && break
|
||||
if ! kill -0 $WEAVE_PID >/dev/null 2>&1; then
|
||||
echo Weave process has died >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# TODO(mp) docker api?
|
||||
/home/weave/plugin $EXTRA_ARGS --log-level=debug --meshsocket='' --docker-api='' >>$LOG_FILE_PLUGIN 2>&1 &
|
||||
|
||||
echo "End of launch.sh" >>$LOG_FILE_WEAVER
|
||||
|
||||
wait $WEAVE_PID
|
||||
--plugin \
|
||||
$(echo $SWARM_MANAGER_PEERS | tr '\n' ' ')
|
||||
@@ -1,3 +0,0 @@
|
||||
FROM DOCKERHUB_USER/weaveARCH_EXT
|
||||
ADD ./plugin /home/weave/
|
||||
ENTRYPOINT ["/home/weave/plugin"]
|
||||
@@ -1,156 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libnetwork/ipamapi"
|
||||
weaveapi "github.com/weaveworks/weave/api"
|
||||
"github.com/weaveworks/weave/common"
|
||||
"github.com/weaveworks/weave/common/docker"
|
||||
weavenet "github.com/weaveworks/weave/net"
|
||||
ipamplugin "github.com/weaveworks/weave/plugin/ipam"
|
||||
netplugin "github.com/weaveworks/weave/plugin/net"
|
||||
"github.com/weaveworks/weave/plugin/skel"
|
||||
)
|
||||
|
||||
var version = "unreleased"
|
||||
|
||||
var Log = common.Log
|
||||
|
||||
func main() {
|
||||
var (
|
||||
justVersion bool
|
||||
dockerAPI string
|
||||
address string
|
||||
meshAddress string
|
||||
logLevel string
|
||||
noMulticastRoute bool
|
||||
|
||||
defaultDockerHost = "unix:///var/run/docker.sock"
|
||||
)
|
||||
|
||||
if val := os.Getenv("DOCKER_HOST"); val != "" {
|
||||
defaultDockerHost = val
|
||||
}
|
||||
|
||||
flag.BoolVar(&justVersion, "version", false, "print version and exit")
|
||||
flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
|
||||
flag.StringVar(&dockerAPI, "docker-api", defaultDockerHost, "Docker API endpoint")
|
||||
flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen")
|
||||
flag.StringVar(&meshAddress, "meshsocket", "/run/docker/plugins/weavemesh.sock", "socket on which to listen in mesh mode")
|
||||
flag.BoolVar(&noMulticastRoute, "no-multicast-route", false, "deprecated (this is now the default)")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if justVersion {
|
||||
fmt.Printf("weave plugin %s\n", version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
common.SetLogLevel(logLevel)
|
||||
|
||||
weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR"), Log)
|
||||
|
||||
var dockerClient *docker.Client
|
||||
var err error
|
||||
if dockerAPI != "" {
|
||||
// API 1.21 is the first version that supports docker network commands
|
||||
dockerClient, err = docker.NewVersionedClient(dockerAPI, "1.21")
|
||||
if err != nil {
|
||||
Log.Fatalf("unable to connect to docker: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
Log.Println("Weave plugin", version, "Command line options:", os.Args[1:])
|
||||
if noMulticastRoute {
|
||||
Log.Warning("--no-multicast-route option has been removed; multicast is off by default")
|
||||
}
|
||||
if dockerClient == nil {
|
||||
Log.Info("Running without Docker API connection")
|
||||
} else {
|
||||
Log.Info(dockerClient.Info())
|
||||
}
|
||||
|
||||
err = run(dockerClient, weave, address, meshAddress)
|
||||
if err != nil {
|
||||
Log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddress string) error {
|
||||
endChan := make(chan error, 1)
|
||||
if address != "" {
|
||||
globalListener, err := listenAndServe(dockerClient, weave, address, endChan, "global", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(address)
|
||||
defer globalListener.Close()
|
||||
}
|
||||
if meshAddress != "" {
|
||||
meshListener, err := listenAndServe(dockerClient, weave, meshAddress, endChan, "local", true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(meshAddress)
|
||||
defer meshListener.Close()
|
||||
}
|
||||
|
||||
statusListener, err := weavenet.ListenUnixSocket("/home/weave/status.sock")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go serveStatus(statusListener)
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
select {
|
||||
case sig := <-sigChan:
|
||||
Log.Debugf("Caught signal %s; shutting down", sig)
|
||||
return nil
|
||||
case err := <-endChan:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, endChan chan<- error, scope string, withIpam bool) (net.Listener, error) {
|
||||
name := strings.TrimSuffix(path.Base(address), ".sock")
|
||||
d, err := netplugin.New(dockerClient, weave, name, scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var i ipamapi.Ipam
|
||||
if withIpam {
|
||||
i = ipamplugin.NewIpam(weave)
|
||||
}
|
||||
|
||||
listener, err := weavenet.ListenUnixSocket(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
Log.Printf("Listening on %s for %s scope", address, scope)
|
||||
|
||||
go func() {
|
||||
endChan <- skel.Listen(listener, d, i)
|
||||
}()
|
||||
|
||||
return listener, nil
|
||||
}
|
||||
|
||||
func serveStatus(listener net.Listener) {
|
||||
server := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "ok")
|
||||
})}
|
||||
if err := server.Serve(listener); err != nil {
|
||||
Log.Fatalf("ListenAndServeStatus failed: %s", err)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
weavetest "github.com/weaveworks/weave/testing"
|
||||
)
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
weavetest.TrimTestArgs()
|
||||
main()
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/weaveworks/weave/nameserver"
|
||||
weavenet "github.com/weaveworks/weave/net"
|
||||
"github.com/weaveworks/weave/net/address"
|
||||
"github.com/weaveworks/weave/plugin"
|
||||
weave "github.com/weaveworks/weave/router"
|
||||
)
|
||||
|
||||
@@ -150,6 +151,10 @@ func main() {
|
||||
discoveryEndpoint string
|
||||
token string
|
||||
advertiseAddress string
|
||||
pluginSocket string
|
||||
pluginMeshSocket string
|
||||
noMulticastRoute bool
|
||||
enablePlugin bool
|
||||
|
||||
defaultDockerHost = "unix:///var/run/docker.sock"
|
||||
)
|
||||
@@ -195,6 +200,11 @@ func main() {
|
||||
mflag.StringVar(&token, []string{"-token"}, "", "token for peer discovery")
|
||||
mflag.StringVar(&advertiseAddress, []string{"-advertise-address"}, "", "address to advertise for peer discovery")
|
||||
|
||||
mflag.BoolVar(&enablePlugin, []string{"-plugin"}, false, "enable Docker plugin")
|
||||
mflag.StringVar(&pluginSocket, []string{"-plugin-socket"}, "/run/docker/plugins/weave.sock", "plugin socket on which to listen")
|
||||
mflag.StringVar(&pluginMeshSocket, []string{"-plugin-mesh-socket"}, "/run/docker/plugins/weavemesh.sock", "plugin socket on which to listen in mesh mode")
|
||||
mflag.BoolVar(&noMulticastRoute, []string{"-no-multicast-route"}, false, "deprecated (this is now the default)")
|
||||
|
||||
// crude way of detecting that we probably have been started in a
|
||||
// container, with `weave launch` --> suppress misleading paths in
|
||||
// mflags error messages.
|
||||
@@ -396,6 +406,11 @@ func main() {
|
||||
go listenAndServeHTTP(statusAddr, statusMux)
|
||||
}
|
||||
|
||||
if enablePlugin {
|
||||
// TODO(mp) do not pass pluginMeshSocket if plugin-v2 is in use
|
||||
go plugin.Start(httpAddr, dockerAPI, pluginSocket, pluginMeshSocket, noMulticastRoute)
|
||||
}
|
||||
|
||||
signals.SignalHandlerLoop(common.Log, router)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user