user 7 år sedan
förälder
incheckning
7484d2fcaa
3 ändrade filer med 60 tillägg och 2 borttagningar
  1. 12 2
      Makefile
  2. 25 0
      add_public_route
  3. 23 0
      remove_public_route

+ 12 - 2
Makefile

@@ -7,7 +7,7 @@ LOCAL_STAGING_DIR ?= /tmp/staging
 LOCAL_PLEX_DIR ?= /tmp/plex
 MEDIA_DIR ?= /tmp/media
 
-default: build
+default: init build run
 
 init:
 	bash init_container
@@ -31,7 +31,17 @@ daemon:
 stop:
 	docker stop $(ID)
 
-rm: stop
+public:
+	bash add_public_route $(ID) $(PUBLIC_IP) $(PUBLIC_IFACE)
+	docker exec $(ID) ipfs config Addresses.Swarm --json '[ "/ip4/0.0.0.0/tcp/40001" ]'
+	docker restart $(ID)
+
+private:
+	bash remove_public_route $(ID) $(PUBLIC_IP) $(PUBLIC_IFACE)
+	docker exec $(ID) ipfs config Addresses.Swarm --json '[ "/ip4/127.0.0.1/tcp/40001" ]'
+	docker restart $(ID)
+
+rm: private stop
 	docker rm $(ID)
 
 ps:

+ 25 - 0
add_public_route

@@ -0,0 +1,25 @@
+#!/bin/bash
+
+set -e
+set -x
+
+base="$( cd "$(dirname "$0")" ; pwd -P )"
+
+id="$1"
+public_ip="$2"
+public_iface="$3"
+
+if [ -z "$public_iface" ]; then
+    echo >&2 "usage: $0 ctid public_ip public_iface"
+    exit 1
+fi
+
+$base/remove_public_route "$id" "$public_ip" "$public_iface" || true
+
+docker_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $id)
+
+if [ -n "$docker_ip" ]; then
+    iptables -t nat -A PREROUTING -d $public_ip/32 -i $public_iface -j DNAT --to-destination $docker_ip
+fi
+
+exit 0

+ 23 - 0
remove_public_route

@@ -0,0 +1,23 @@
+#!/bin/bash
+
+set -e
+set -x
+
+base="$( cd "$(dirname "$0")" ; pwd -P )"
+
+id="$1"
+public_ip="$2"
+public_iface="$3"
+
+if [ -z "$public_iface" ]; then
+    echo >&2 "usage: $0 ctid public_ip public_iface"
+    exit 1
+fi
+
+docker_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $id)
+
+if [ -n "$docker_ip" ]; then
+    iptables -t nat -D PREROUTING -d $public_ip/32 -i $public_iface -j DNAT --to-destination $docker_ip || true
+fi
+
+exit 0