From 643d8eaf52c6c54f4bc98c9f1bec7de41bf97213 Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 16 Aug 2023 20:23:08 +0200 Subject: [PATCH 1/3] fix dhcp cleanup --- conf/ynh-hotspot | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index 546d283..f6ba832 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -158,7 +158,7 @@ start_dhcpd() { sed "s|__IP4_DNS__|${ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf sed "s|__IP4_NAT_PREFIX__|${ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv4-ssid${i}.pid fi # Run DHCPv6 server @@ -171,7 +171,7 @@ start_dhcpd() { sed "s|__IP6_DNS__|${ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf sed "s|__IP6_NET__|${ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf - dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 + dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0 -x /run/dnsmasq/dnsmasq-dhcpv6-ssid${i}.pid fi } @@ -249,13 +249,13 @@ stop_dhcpd() { if is_dhcpd6_running ${i}; then echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv6-ssid*.conf + rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid*.conf fi if is_dhcpd4_running ${i}; then echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.d/dhcpdv4-ssid*.conf + rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid*.conf fi } From c1246b49632d35e8dfb0b1c618399f151896d89f Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 16 Aug 2023 20:35:58 +0200 Subject: [PATCH 2/3] make use of pid files --- conf/ynh-hotspot | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index f6ba832..d3c732b 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -73,13 +73,13 @@ is_forwarding_set() { is_dhcpd6_running() { local i=${1} - ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid" ]] } is_dhcpd4_running() { local i=${1} - ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid" ]] } is_hostapd_running() { @@ -248,14 +248,14 @@ stop_dhcpd() { if is_dhcpd6_running ${i}; then echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" - kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid*.conf + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid) + rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf fi if is_dhcpd4_running ${i}; then echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" - kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }') - rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid*.conf + kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid) + rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf fi } From dceb955917ed04c7b7a0aa641417b2978478e9ef Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 16 Aug 2023 21:04:42 +0200 Subject: [PATCH 3/3] ensure process from pid is running and remove pid file --- conf/ynh-hotspot | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index d3c732b..8883f2f 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -73,13 +73,13 @@ is_forwarding_set() { is_dhcpd6_running() { local i=${1} - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid" ]] + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid") > /dev/null } is_dhcpd4_running() { local i=${1} - [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid" ]] + [[ -e "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid" ]] && ps -p $(cat "/run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid") > /dev/null } is_hostapd_running() { @@ -249,12 +249,14 @@ stop_dhcpd() { if is_dhcpd6_running ${i}; then echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)" kill $(cat /run/dnsmasq/dnsmasq-dhcpdv6-ssid${i}.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv6-ssid${1}.pid rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf fi if is_dhcpd4_running ${i}; then echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)" kill $(cat /run/dnsmasq/dnsmasq-dhcpdv4-ssid${i}.pid) + rm -f /run/dnsmasq/dnsmasq-dhcpdv4-ssid${1}.pid rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf fi }