Skip to content

Commit

Permalink
refactor(netmap): using procd instead of pre-post commits (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile authored Jan 7, 2025
1 parent 091d93d commit 2c99b60
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
15 changes: 11 additions & 4 deletions packages/ns-netmap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ endef
define Build/Compile
endef

define Package/ns-netmap/postinst
#!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then
/etc/init.d/ns-netmap enable
/etc/init.d/ns-netmap restart
fi
exit 0
endef

define Package/ns-netmap/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/usr/libexec/ns-api/pre-commit
$(INSTALL_DIR) $(1)/usr/libexec/ns-api/post-commit
$(INSTALL_BIN) ./files/ns-netmap $(1)/usr/sbin/ns-netmap
$(INSTALL_CONF) ./files/config $(1)/etc/config/netmap
$(INSTALL_BIN) ./files/generate-netmap.py $(1)/usr/libexec/ns-api/pre-commit/
$(INSTALL_BIN) ./files/reload-netmap.py $(1)/usr/libexec/ns-api/post-commit/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/ns-netmap.init $(1)/etc/init.d/ns-netmap
endef

$(eval $(call BuildPackage,ns-netmap))
16 changes: 0 additions & 16 deletions packages/ns-netmap/files/generate-netmap.py

This file was deleted.

12 changes: 9 additions & 3 deletions packages/ns-netmap/files/ns-netmap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#

import os
import subprocess
import sys
import ipaddress
from euci import EUci
from nethsec import utils
Expand Down Expand Up @@ -79,9 +81,13 @@ def generate_rules():
df.close()

def main():
setup()
cleanup()
generate_rules()
if len(sys.argv) > 1 and sys.argv[1] == "cleanup":
cleanup()
else:
setup()
cleanup()
generate_rules()
subprocess.run(['/etc/init.d/firewall', 'reload'])

if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions packages/ns-netmap/files/ns-netmap.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh /etc/rc.common

#
# Copyright (C) 2025 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-2.0-only
#

START=99
USE_PROCD=1

start_service() {
# Main service
procd_open_instance
procd_set_param command /usr/sbin/ns-netmap
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}

stop_service() {
# Destroy nft table
/usr/sbin/ns-netmap cleanup
}

service_triggers()
{
procd_add_reload_trigger netmap
}
15 changes: 0 additions & 15 deletions packages/ns-netmap/files/reload-netmap.py

This file was deleted.

0 comments on commit 2c99b60

Please sign in to comment.