Page MenuHomeDevCentral

D102.id241.diff
No OneTemporary

D102.id241.diff

diff --git a/roles/mailserver/systemd-unit/files/lxc-container-mailserver-start b/roles/mailserver/systemd-unit/files/lxc-container-mailserver-start
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/systemd-unit/files/lxc-container-mailserver-start
@@ -0,0 +1,30 @@
+#!/bin/sh
+#Let systemd launch a lxc mail container through /usr/lib/systemd/system/lxc-containers.service
+#Start a lxc container, and create iptable rules
+
+IPTABLES="/usr/sbin/iptables"
+LXC_START="/usr/bin/lxc-start"
+CONTAINER_NAME="mailserver"
+HOST_INTERFACE="ens192"
+HOST_IP="212.129.32.223"
+CONTAINER_IP="10.0.3.8"
+PORTS="25 110 143 465 587"
+DOCKER_PORTS="25 143 465 587"
+
+$LXC_START -n $CONTAINER_NAME -d
+
+#Web rules
+for WEB_PORT in $PORTS
+do
+ $IPTABLES -t nat -I PREROUTING -i $HOST_INTERFACE -p TCP -d $HOST_IP/32 --dport $WEB_PORT -j DNAT --to-destination $CONTAINER_IP:$WEB_PORT
+done
+
+#Need 80 port for main nginx
+$IPTABLES -t nat -I PREROUTING -i $HOST_INTERFACE -p TCP -d $HOST_IP/32 --dport 21080 -j DNAT --to-destination $CONTAINER_IP:80
+
+
+#Docker rules
+for WEB_PORT in $DOCKER_PORTS
+do
+ $IPTABLES -t nat -I PREROUTING -i docker0 -p TCP -d $HOST_IP/32 --dport $WEB_PORT -j DNAT --to-destination $CONTAINER_IP:$WEB_PORT
+done
diff --git a/roles/mailserver/systemd-unit/files/lxc-container-mailserver-stop b/roles/mailserver/systemd-unit/files/lxc-container-mailserver-stop
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/systemd-unit/files/lxc-container-mailserver-stop
@@ -0,0 +1,31 @@
+#!/bin/sh
+#Let systemd stop the lxc mail container through /usr/lib/systemd/system/lxc-containers.service
+#Stop the lxc container, and create iptable rules
+
+IPTABLES="/usr/sbin/iptables"
+LXC_STOP="/usr/bin/lxc-stop"
+CONTAINER_NAME="mailserver"
+HOST_INTERFACE="ens192"
+HOST_IP="212.129.32.223"
+CONTAINER_IP="10.0.3.8"
+PORTS="25 110 143 465 587"
+DOCKER_PORTS="25 143 465 587"
+
+#Web rules
+for WEB_PORT in $PORTS
+do
+ $IPTABLES -t nat -D PREROUTING -i $HOST_INTERFACE -p TCP -d $HOST_IP/32 --dport $WEB_PORT -j DNAT --to-destination $CONTAINER_IP:$WEB_PORT
+done
+
+#Need 80 port for main nginx
+$IPTABLES -t nat -D PREROUTING -i $HOST_INTERFACE -p TCP -d $HOST_IP/32 --dport 21080 -j DNAT --to-destination $CONTAINER_IP:80
+
+
+#Docker rules
+for WEB_PORT in $DOCKER_PORTS
+do
+ $IPTABLES -t nat -D PREROUTING -i docker0 -p TCP -d $HOST_IP/32 --dport $WEB_PORT -j DNAT --to-destination $CONTAINER_IP:$WEB_PORT
+done
+
+$LXC_STOP -n $CONTAINER_NAME
+
diff --git a/roles/mailserver/systemd-unit/files/lxc-container-mailserver.service b/roles/mailserver/systemd-unit/files/lxc-container-mailserver.service
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/systemd-unit/files/lxc-container-mailserver.service
@@ -0,0 +1,11 @@
+[Unit]
+Description= lxc mailserver container
+
+[Service]
+Type=simple
+RemainAfterExit=yes
+ExecStart=/usr/lib/systemd/system/lxc-container-mailserver-start
+ExecStop=/usr/lib/systemd/system/lxc-container-mailserver-stop
+
+[Install]
+WantedBy=multi-user.target

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 08:44 (20 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2307872
Default Alt Text
D102.id241.diff (2 KB)

Event Timeline