Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(netmap): using procd instead of pre-post commits #999

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Tbaile marked this conversation as resolved.
Show resolved Hide resolved
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.

Loading