From 4f54fdaf434155c6ad6862768025a02b2e79036c Mon Sep 17 00:00:00 2001 From: trendless Date: Mon, 15 Jun 2026 19:06:15 -0600 Subject: [PATCH 1/3] dnsmasq coexistence --- conf/dnsmasq.conf | 2 ++ conf/systemd.service | 2 ++ doc/PRE_UPGRADE.d/15.2.0~ynh1.md | 1 + scripts/install | 39 +++++++++++++++++++++++++++++--- scripts/remove | 4 ++++ scripts/restore | 7 ++++++ scripts/upgrade | 3 +++ 7 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 conf/dnsmasq.conf create mode 100644 doc/PRE_UPGRADE.d/15.2.0~ynh1.md diff --git a/conf/dnsmasq.conf b/conf/dnsmasq.conf new file mode 100644 index 0000000..8b5d5cf --- /dev/null +++ b/conf/dnsmasq.conf @@ -0,0 +1,2 @@ +listen-address=127.0.0.1 +bind-interfaces \ No newline at end of file diff --git a/conf/systemd.service b/conf/systemd.service index e608a57..99702d8 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -13,6 +13,8 @@ RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dns-server Environment=DNS_SERVER_LOG_FOLDER_PATH=/var/log/__APP__/dns +CapabilityBoundingSet=CAP_NET_BIND_SERVICE +AmbientCapabilities=CAP_NET_BIND_SERVICE [Install] WantedBy=multi-user.target diff --git a/doc/PRE_UPGRADE.d/15.2.0~ynh1.md b/doc/PRE_UPGRADE.d/15.2.0~ynh1.md new file mode 100644 index 0000000..ecbbc9f --- /dev/null +++ b/doc/PRE_UPGRADE.d/15.2.0~ynh1.md @@ -0,0 +1 @@ +After upgrading, you must add your ynh server's local IP address(es) to `DNS Server Local End Points`: https://__DOMAIN__/#settingsTabPaneGeneral and then restart __APP__. \ No newline at end of file diff --git a/scripts/install b/scripts/install index 39fe304..64f6fb8 100755 --- a/scripts/install +++ b/scripts/install @@ -26,8 +26,14 @@ ynh_config_add_systemd mkdir -p "/var/log/$app/dns" chown -R "$app:$app" "/var/log/$app" +ynh_hide_warnings yunohost firewall allow Both 53 + yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/$app/$app.log" --needs_exposed_ports="53" +ynh_config_add --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app.conf" + +ynh_systemctl --service="dnsmasq" --action="restart" + #================================================= # ADD A CRON JOB #================================================= @@ -37,15 +43,42 @@ chmod 644 "/etc/cron.d/$app" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression "Starting $app's systemd service..." - -ynh_systemctl --service="$app" --action="restart" --log_path=systemd --wait_until="was started successfully" +ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="was started successfully" #================================================= # LINK LOGS #================================================= ln -sf $(ls -t /var/log/$app/dns/*.log | head -n 1) /var/log/$app/$app.log +#================================================= +# SET LOCAL ENDPOINT IP(S) +#================================================= +gateway_v4=$(ip -4 route show default | awk '{print $3}' | head -n1) +ipv4=$(ip -4 route get "$gateway_v4" 2>/dev/null | grep -oP 'src \K\S+') + +gateway_v6=$(ip -6 route show default | awk '{print $3}' | head -n1) +if [ -n "$gateway_v6" ]; then + ipv6=$(ip -6 route get "$gateway_v6" 2>/dev/null | grep -oP 'src \K\S+' | grep -v '^fe80') +else + ipv6="" +fi + +if [ -n "$ipv6" ]; then + endpoints="$ipv4:53,[$ipv6]:53" +else + endpoints="$ipv4:53" +fi + +mytoken1=$(curl -s "http://127.0.0.1:5380/api/user/createToken?user=admin&pass=admin&tokenName=mytoken1" | jq -r '.token') +curl -s "http://localhost:5380/api/settings/set?dnsServerLocalEndPoints=$endpoints&Token=$mytoken1" + +#================================================= +# RESTART SYSTEMD SERVICE +#================================================= +ynh_script_progression "Starting $app's systemd service..." + +ynh_systemctl --service="$app" --action="restart" --log_path=systemd --wait_until="was started successfully" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 0e8c640..639c656 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,6 +16,8 @@ if ynh_hide_warnings yunohost service status "$app" >/dev/null; then yunohost service remove "$app" fi +ynh_hide_warnings yunohost firewall disallow Both 53 + ynh_config_remove_systemd ynh_config_remove_nginx @@ -24,6 +26,8 @@ ynh_safe_rm "/var/log/$app" ynh_safe_rm "/etc/cron.d/$app" +ynh_safe_rm "/etc/dnsmasq.d/$app.conf" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index ff6bc9a..c7b6282 100755 --- a/scripts/restore +++ b/scripts/restore @@ -29,14 +29,21 @@ ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/var/log/$app" +ynh_hide_warnings yunohost firewall allow Both 53 + ynh_restore "/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet yunohost service add "$app" --description="Technitium DNS Server" --log="/var/log/$app/$app.log" --needs_exposed_ports=53 +ynh_config_add --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app.conf" + +ynh_systemctl --service="dnsmasq" --action="restart" + #================================================= # ADD A CRON JOB #================================================= ynh_config_add --template="logsymlink.cron" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2342651..5f436ef 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -30,6 +30,9 @@ if ynh_app_upgrading_from_version_before_or_equal_to 14.3.0~ynh1; then chown -R "$app:$app" "/var/log/$app" ln -sf "/var/log/$app/dns" "$data_dir/logs" ln -sf $(ls -t /var/log/$app/dns/*.log | head -n 1) /var/log/$app/$app.log + ynh_config_add --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app.conf" + ynh_systemctl --service="dnsmasq" --action="restart" + ynh_hide_warnings yunohost firewall allow Both 53 fi #================================================= From 84c3f7ab1a797f96c13053455011c52785e49b09 Mon Sep 17 00:00:00 2001 From: trendless Date: Mon, 15 Jun 2026 19:22:01 -0600 Subject: [PATCH 2/3] ipv6 tweak --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 64f6fb8..d1fb0ed 100755 --- a/scripts/install +++ b/scripts/install @@ -58,7 +58,7 @@ ipv4=$(ip -4 route get "$gateway_v4" 2>/dev/null | grep -oP 'src \K\S+') gateway_v6=$(ip -6 route show default | awk '{print $3}' | head -n1) if [ -n "$gateway_v6" ]; then - ipv6=$(ip -6 route get "$gateway_v6" 2>/dev/null | grep -oP 'src \K\S+' | grep -v '^fe80') + ipv6=$(ip -6 route get "$gateway_v6" 2>/dev/null | grep -oP 'src \K\S+' | grep -v '^fe80' || true) else ipv6="" fi From 1d625c7a0c4da2f3326cf447238df7496f532714 Mon Sep 17 00:00:00 2001 From: trendless Date: Mon, 15 Jun 2026 19:23:11 -0600 Subject: [PATCH 3/3] update remove --- scripts/remove | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/remove b/scripts/remove index 639c656..b9133e5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -22,8 +22,6 @@ ynh_config_remove_systemd ynh_config_remove_nginx -ynh_safe_rm "/var/log/$app" - ynh_safe_rm "/etc/cron.d/$app" ynh_safe_rm "/etc/dnsmasq.d/$app.conf"