Skip to content

Commit

Permalink
Add openwrt init script and custom node init
Browse files Browse the repository at this point in the history
  • Loading branch information
svpcom committed Sep 20, 2024
1 parent 697e4f5 commit 971f783
Showing 5 changed files with 55 additions and 5 deletions.
4 changes: 3 additions & 1 deletion openwrt/net/wfb-ng/Makefile
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=wfb-ng
PKG_VERSION:=24.9.2
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_LICENSE:=GPL-3.0-only
PKG_LICENSE_FILES:=LICENSE

@@ -42,6 +42,8 @@ define Package/wfb-ng/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/wfb_rx $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/wfb_tx $(1)/usr/bin/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/wfb-ng.init $(1)/etc/init.d/wfb-ng
endef

$(eval $(call BuildPackage,wfb-ng))
26 changes: 26 additions & 0 deletions openwrt/net/wfb-ng/files/wfb-ng.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh /etc/rc.common

START=99
STOP=10

USE_PROCD=1
NAME=wfb-ng

SYSUPGRADE_CONF="/etc/sysupgrade.conf"
WFB_INIT="/usr/sbin/wfb-ng.sh"

if [ -f $SYSUPGRADE_CONF ] && [ -x $WFB_INIT ] && ! grep -q $WFB_INIT $SYSUPGRADE_CONF
then
echo $WFB_INIT >> $SYSUPGRADE_CONF
fi

start_service() {
if [ -x $WFB_INIT ]; then
procd_open_instance wfb-ng
procd_set_param command $WFB_INIT
procd_set_param respawn
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
fi
}
20 changes: 18 additions & 2 deletions wfb_ng/cluster.py
Original file line number Diff line number Diff line change
@@ -108,6 +108,10 @@ def get_allocator(node):
trap _cleanup EXIT
{% if custom_init_script != None %}
{{ custom_init_script }}
{% endif %}
iw reg set {{ settings.common.wifi_region }}
{% for wlan in wlans %}
@@ -136,8 +140,10 @@ def get_allocator(node):
{% endif %}
{% endfor %}
{% if ssh_mode %}
# Will fail in case of connection loss
(sleep 1; exec cat > /dev/null) &
{% endif %}
echo "WFB-ng init done"
wait -n
@@ -146,7 +152,11 @@ def get_allocator(node):

script_template = env.from_string(script_template)

def gen_cluster_scripts(cluster_nodes):
def gen_cluster_scripts(cluster_nodes, ssh_mode=False):
"""
cluster_nodes: node_name -> service_map
"""

res = {}

for node, node_attrs in cluster_nodes.items():
@@ -164,13 +174,19 @@ def gen_cluster_scripts(cluster_nodes):
settings.cluster.nodes[node],
settings.common.__dict__)

custom_init_script = search_attr('custom_init_script',
settings.cluster.nodes[node],
settings.cluster.__dict__)

if not isinstance(txpower, dict):
txpower = dict((wlan, txpower) for wlan in wlans)

res[node] = script_template.render(wlans=wlans,
ht_mode=bandwidth_map[max_bw],
services=node_attrs,
txpower=txpower,
channel=channel)
channel=channel,
ssh_mode=ssh_mode,
custom_init_script=custom_init_script)

return res
8 changes: 7 additions & 1 deletion wfb_ng/conf/master.cfg
Original file line number Diff line number Diff line change
@@ -53,7 +53,11 @@ temp_overheat_warning = 60 # [*C] (8812eu only) Overheat warning threshold.

nodes = {
# required host attrs: 'wlans'
# optional host attrs (will override defaults): 'ssh', 'server_address', 'wifi_txpower', 'wifi_channel', 'ssh_user', 'ssh_port', 'ssh_key'
# optional host attrs (will override defaults):
# 'ssh', 'server_address', 'wifi_txpower',
# 'wifi_channel', 'ssh_user', 'ssh_port', 'ssh_key'
# 'custom_init_script'
#
# If ssh_user or ssh_port is set to None then node will not be automatically initialized in ssh mode.
# If ssh_key is None, then ssh_agent will be used.

@@ -68,6 +72,8 @@ nodes = {
ssh_user = 'root'
ssh_port = 22
ssh_key = None # Path to ssh private key. If None then it will try to use ssh-agent
custom_init_script = None # Do some custom command inside of node init script before wfb-ng start
# You can specify any bash snippet here

server_address = None # Set to IP address which is reachable from all cluster nodes
base_port_server = 10000 # UDP ports allocated on server
2 changes: 1 addition & 1 deletion wfb_ng/server.py
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ def _ssh_exited(x, node):
if is_cluster:
services, cluster_nodes = parse_cluster_services(profiles)
if cluster_mode == 'ssh':
for node, setup_script in gen_cluster_scripts(cluster_nodes).items():
for node, setup_script in gen_cluster_scripts(cluster_nodes, ssh_mode=True).items():
ssh_user = search_attr('ssh_user',
settings.cluster.nodes[node],
settings.cluster.__dict__)

0 comments on commit 971f783

Please sign in to comment.