Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Automatically symlink /var/run/*.sock sockets to /var/run/weave/*.sock #1696

Merged
merged 3 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -283,15 +284,16 @@ func (proxy *Proxy) listen(protoAndAddr string) (net.Listener, string, error) {
}

case "unix":
localAddr := filepath.Join("/host", addr)
// remove socket from last invocation
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
if err := os.Remove(localAddr); err != nil && !os.IsNotExist(err) {
return nil, "", err
}
listener, err = net.Listen(proto, addr)
listener, err = net.Listen(proto, localAddr)
if err != nil {
return nil, "", err
}
if err = copyOwnerAndPermissions(dockerSock, addr); err != nil {
if err = copyOwnerAndPermissions(dockerSock, localAddr); err != nil {
return nil, "", err
}

Expand Down
6 changes: 6 additions & 0 deletions test/650_proxy_env_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ weave_on $HOST1 stop
weave_on $HOST1 launch-proxy -H tcp://0.0.0.0:12375 -H unix:///var/run/weave/weave.sock
check

# Check we can use weave env/config with unix -Hs specified
weave_on $HOST1 stop
weave_on $HOST1 launch-proxy -H unix:///var/run/weave/weave.sock
assert_raises "run_on $HOST1 'eval \$(weave env) ; docker $CMD'"
assert_raises "run_on $HOST1 'docker \$(weave config) $CMD'"

end_suite
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

. ./config.sh

start_suite "Boot the proxy should only listen on client's interface"
start_suite "Various launch-proxy configurations"

# Booting it over unix socket listens on unix socket
run_on $HOST1 COVERAGE=$COVERAGE sudo -E weave launch-proxy
Expand All @@ -22,6 +22,11 @@ assert_raises "run_on $HOST1 sudo docker -H unix:///var/run/weave/weave.sock ps"
assert_raises "proxy docker_on $HOST1 ps"
weave_on $HOST1 stop-proxy

# Booting it with -H outside /var/run/weave, still works
socket="$(mktemp -d)/weave.sock"
weave_on $HOST1 launch-proxy -H unix://$socket
assert_raises "run_on $HOST1 sudo docker -H unix:///$socket ps" 0
weave_on $HOST1 stop-proxy

# Booting it over tls errors
assert_raises "DOCKER_CLIENT_ARGS='--tls' weave_on $HOST1 launch-proxy" 1
Expand Down
2 changes: 1 addition & 1 deletion test/gce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function hosts {
hosts="$hostname $hosts"
args="--add-host=$hostname:$(internal_ip $json $name) $args"
done
echo export SSH=ssh
echo export SSH=\"ssh -l vagrant\"
echo export HOSTS=\"$hosts\"
echo export ADD_HOST_ARGS=\"$args\"
rm $json
Expand Down
34 changes: 28 additions & 6 deletions weave
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ usage() {
exec_remote() {
docker $DOCKER_CLIENT_ARGS run --rm --privileged --net=host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run:/host/var/run \
-v /proc:/hostproc \
-e PROCFS=/hostproc \
-e DOCKERHUB_USER="$DOCKERHUB_USER" \
Expand Down Expand Up @@ -1266,17 +1267,36 @@ tls_arg() {
PROXY_ARGS="$PROXY_ARGS $1 /home/weave/tls/$3.pem"
}

# TODO: Handle relative paths for args
# TODO: Handle args with spaces
host_arg() {
PROXY_HOST="$1"
if [ "$PROXY_HOST" != "${PROXY_HOST#unix://}" ]; then
host=$(dirname ${PROXY_HOST#unix://})
if [ "$host" = "${host#/}" ]; then
echo "When launching the proxy, unix sockets must be specified as an absolute path." >&2
exit 1
fi
if [ "$host" = "/var/run" ]; then
host=/var/run/weave
PROXY_VAR_RUN_SYMLINKS="$PROXY_VAR_RUN_SYMLINKS $(basename ${PROXY_HOST#unix://})"
fi
PROXY_VOLUMES="$PROXY_VOLUMES -v $host:/host$host"
PROXY_ARGS="$PROXY_ARGS -H unix://$host/$(basename ${PROXY_HOST#unix://})"
else
PROXY_ARGS="$PROXY_ARGS -H $1"
fi
}

proxy_parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
-H)
PROXY_HOST="$2"
PROXY_ARGS="$PROXY_ARGS $1 $2"
host_arg "$2"
shift
;;
-H=*)
PROXY_HOST="${1#*=}"
PROXY_ARGS="$PROXY_ARGS $1"
host_arg "${1#*=}"
;;
-no-detect-tls|--no-detect-tls)
PROXY_TLS_DETECTION_DISABLED=1
Expand Down Expand Up @@ -1337,7 +1357,7 @@ proxy_args() {
PROXY_HOST="tcp://0.0.0.0:12375"
;;
esac
PROXY_ARGS="$PROXY_ARGS -H $PROXY_HOST"
host_arg "$PROXY_HOST"
fi
}

Expand Down Expand Up @@ -1542,7 +1562,6 @@ launch_proxy() {
PROXY_CONTAINER=$(docker run --privileged -d --name=$PROXY_CONTAINER_NAME --net=host \
$PROXY_VOLUMES \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/weave:/var/run/weave \
-v /proc:/hostproc \
-e PROCFS=/hostproc \
-e WEAVE_CIDR=none \
Expand All @@ -1552,6 +1571,9 @@ launch_proxy() {
--entrypoint=/home/weave/weaveproxy \
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS)
wait_for_status $PROXY_CONTAINER_NAME http_call_unix $PROXY_CONTAINER_NAME status.sock
for sock in $PROXY_VAR_RUN_SYMLINKS; do
ln -sf -T "/var/run/weave/$sock" "/host/var/run/$sock"

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

done
}

stop_proxy() {
Expand Down