summaryrefslogtreecommitdiffstats
path: root/core/modules/dnbd3-proxy-mode
diff options
context:
space:
mode:
authorJonathan Bauer2017-10-13 12:23:07 +0200
committerJonathan Bauer2017-10-13 12:23:07 +0200
commit5fa13c9b6c44046630e178b95e4f79027af5192c (patch)
tree15afd3269be872dc6d8792dfe02a9a35068c0c93 /core/modules/dnbd3-proxy-mode
parent[dnbd3] build and copy dnbd3-server (diff)
downloadmltk-5fa13c9b6c44046630e178b95e4f79027af5192c.tar.gz
mltk-5fa13c9b6c44046630e178b95e4f79027af5192c.tar.xz
mltk-5fa13c9b6c44046630e178b95e4f79027af5192c.zip
[dnbd3-proxy-mode] new module for netbooted dnbd3 ...
... proxy
Diffstat (limited to 'core/modules/dnbd3-proxy-mode')
-rw-r--r--core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.service10
-rw-r--r--core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target2
-rw-r--r--core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/dnbd3-proxy.service10
-rw-r--r--core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/setup-dnbd3-proxy.service7
-rw-r--r--core/modules/dnbd3-proxy-mode/data/etc/systemd/system/setup-dnbd3-proxy.service7
-rwxr-xr-xcore/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy97
-rw-r--r--core/modules/dnbd3-proxy-mode/module.build13
-rw-r--r--core/modules/dnbd3-proxy-mode/module.conf2
8 files changed, 148 insertions, 0 deletions
diff --git a/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.service b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.service
new file mode 100644
index 00000000..5c401615
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=DNBD3 proxy server
+After=network.target multi-user.target setup-dnbd3-proxy.service
+
+[Service]
+User=dnbd3
+ExecStart=/opt/openslx/bin/dnbd3-server -n -c /etc/dnbd3
+Restart=always
+RestartSec=1
+TimeoutStopSec=10
diff --git a/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target
new file mode 100644
index 00000000..bc3f5c61
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target
@@ -0,0 +1,2 @@
+[Unit]
+Description=DNBD3 server running
diff --git a/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/dnbd3-proxy.service b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/dnbd3-proxy.service
new file mode 100644
index 00000000..5c401615
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/dnbd3-proxy.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=DNBD3 proxy server
+After=network.target multi-user.target setup-dnbd3-proxy.service
+
+[Service]
+User=dnbd3
+ExecStart=/opt/openslx/bin/dnbd3-server -n -c /etc/dnbd3
+Restart=always
+RestartSec=1
+TimeoutStopSec=10
diff --git a/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/setup-dnbd3-proxy.service b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/setup-dnbd3-proxy.service
new file mode 100644
index 00000000..194db999
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/dnbd3-proxy.target.requires/setup-dnbd3-proxy.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Setup DNBD3 proxy server
+After=network.target multi-user.target
+
+[Service]
+Type=oneshot
+ExecStart=/opt/openslx/scripts/systemd-setup_dnbd3_proxy
diff --git a/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/setup-dnbd3-proxy.service b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/setup-dnbd3-proxy.service
new file mode 100644
index 00000000..194db999
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/data/etc/systemd/system/setup-dnbd3-proxy.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Setup DNBD3 proxy server
+After=network.target multi-user.target
+
+[Service]
+Type=oneshot
+ExecStart=/opt/openslx/scripts/systemd-setup_dnbd3_proxy
diff --git a/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy
new file mode 100755
index 00000000..72d6dccc
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-setup_dnbd3_proxy
@@ -0,0 +1,97 @@
+#!/bin/ash
+# This scripts runs as root and prepares the configuration
+# for the dnbd3 server (...)
+
+# Creates the DNBD3 server configuration under DNBD3_CONF_DIR
+DNBD3_CONF_DIR="/etc/dnbd3"
+if ! mkdir -p "${DNBD3_CONF_DIR}"; then
+ slxlog -s -e "dnbd3-setup" "Failed to create '${DNBD3_CONF_DIR}'."
+ exit 1
+fi
+
+# Checks if the persistent partition (MBR-ID 45 / GPT-LABEL OpenSLX-ID45)
+# is present, exits if not.
+DNBD3_BASE_DIR="/opt/openslx/persistent"
+if grep -q '^/dev/.* '"${DNBD3_BASE_DIR}"' .*rw' /proc/mounts \
+ && [ -k "${DNBD3_BASE_DIR}/data" ]; then
+ # setup_partitions creates a data folder in ID45
+ DNBD3_BASE_DIR="${DNBD3_BASE_DIR}/data"
+else
+ # try /tmp fallback
+ DNBD3_BASE_DIR="/tmp"
+ if ! grep -q '^/dev/.* '"${DNBD3_BASE_DIR}"' .*rw' /proc/mounts ; then
+ # no sane fallback possible, exit 1
+ slxlog -s -e "dnbd3-setup" \
+ "Neither the persistent part (ID45) nor /tmp are available for dnbd3-server!"
+ exit 1
+ fi
+fi
+# now try to create the actual folder used by the server
+DNBD3_DATA_DIR="${DNBD3_BASE_DIR}/dnbd3"
+if ! mkdir -p "${DNBD3_DATA_DIR}"; then
+ i=0
+ while [ $i -lt 10 ]; do
+ mkdir -p "${DNBD3_BASE_DIR}/dnbd3.$i" && \
+ DNBD3_DATA_DIR="${DNBD3_BASE_DIR}/dnbd3.$i" && break
+ done
+fi
+if [ ! -d "${DNBD3_DATA_DIR}" ]; then
+ slxlog -s -e "dnbd3-setup" "Failed to create '${DNBD3_BASE_DIR}.0-$i]'!"
+ exit 1
+fi
+
+if ! chown dnbd3:dnbd3 "${DNBD3_DATA_DIR}"; then
+ slxlog -s -e "dnbd3-setup" "Failed to chown '${DNBD3_DATA_DIR}' to dnbd3."
+ exit 1
+fi
+
+# Done with sanity checks, now create configs: server.conf & alt-servers
+# Using the information given by the server in /opt/openslx/config
+. /opt/openslx/config
+
+DNBD3_PORT=5003
+# Refer to http://git.openslx.org/dnbd3.git/tree/conf for configuration options
+cat << EOF > "${DNBD3_CONF_DIR}/server.conf"
+[dnbd3]
+listenPort=${DNBD3_PORT}
+basePath=${DNBD3_DATA_DIR}
+serverPenalty=100000
+clientPenalty=0
+isProxy=true
+backgroundReplication=false
+removeMissingImages=false
+uplinkTimeout=1250
+clientTimeout=15000
+
+[logging]
+consoleMask=ERROR WARNING
+EOF
+
+# helper to echo given list of IPs to ${DNBD3_CONF_DIR}/alt-servers
+# optionally takes a single char prefix as first param and
+# adds it to the IP (for private dnbd3 servers)
+# Also sets FOUND_SAT if satellite IP was seen
+add_alt_server() {
+ local PRE=
+ [ "x$1" = "x-" ] && PRE='-' && shift
+ for ALT in $@; do
+ echo "${PRE}${ALT}" >> "${DNBD3_CONF_DIR}/alt-servers"
+ [ "x${ALT}" = "x${SLX_PXE_SERVER_IP}" ] && FOUND_SAT="oui"
+ done
+ return 0
+}
+
+FOUND_SAT=
+add_alt_server ${SLX_DNBD3_PUBLIC}
+add_alt_server '-' ${SLX_DNBD3_PRIVATE}
+[ -z "${FOUND_SAT}" ] && add_alt_server ${SLX_KCL_SERVERS}
+
+# now create iptables helper rules
+DNBD3_IPTABLES_CONF="/opt/openslx/iptables/rules.d/99-dnbd3"
+ehco '#!/bin/ash' >> "${DNBD3_IPTABLES_CONF}"
+for CIDR in ${SLX_DNBD3_WHITELIST}; do
+ echo -n "iptables -w -w -I ipt-helper-INPUT 1 -i br0"
+ echo "-p tcp \! -s ${CIDR} --dport ${DNBD3_PORT} -j DROP"
+done >> "${DNBD3_IPTABLES_CONF}"
+
+# TODO set DNBD3_SERV0R issue warning for ttys
diff --git a/core/modules/dnbd3-proxy-mode/module.build b/core/modules/dnbd3-proxy-mode/module.build
new file mode 100644
index 00000000..a2c0bd22
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/module.build
@@ -0,0 +1,13 @@
+#!/bin/bash
+fetch_source() {
+ :
+}
+
+build() {
+ :
+}
+
+post_copy() {
+ add_group "dnbd3"
+ USER="dnbd3" GROUP="dnbd3" add_user
+}
diff --git a/core/modules/dnbd3-proxy-mode/module.conf b/core/modules/dnbd3-proxy-mode/module.conf
new file mode 100644
index 00000000..3ba16fc0
--- /dev/null
+++ b/core/modules/dnbd3-proxy-mode/module.conf
@@ -0,0 +1,2 @@
+#!/bin/bash
+# Nothing - static module