Skip to content

Commit

Permalink
nginx: update init script to publish services over mdns
Browse files Browse the repository at this point in the history
update init script to announce http related services over mdns

Signed-off-by: Mohd Husaam Mehdi <[email protected]>
  • Loading branch information
mhusaam committed Mar 27, 2024
1 parent 5aee095 commit c2d3576
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion net/nginx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=nginx
PKG_VERSION:=1.25.3
PKG_RELEASE:=2
PKG_RELEASE:=3

PKG_SOURCE:=nginx-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://nginx.org/download/
Expand Down
37 changes: 37 additions & 0 deletions net/nginx/files/nginx.init
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,40 @@ nginx_init() {
logger -t "nginx_init" -p "daemon.info" "using ${CONF} (the test is ok)"
}

add_mdns() {
local cfg="$1"
local port enabled mdns service

config_get enabled "$cfg" enabled
config_get mdns "$cfg" mdns
config_get port "$cfg" listen

port=$(echo "$port" | head -n1 | awk '{print $1;}')

if [ "${mdns}" == "0" ] || [ "${mdns}" == "false" ]; then
return
fi

if [ "${enabled}" != "0" ] && [ "${enabled}" != "false" ] && [ -n "${port}" ]; then
[ "${port}" == "80" ] && service="http"
[ "${port}" == "8080" ] && service="http-alt"
[ "${port}" == "443" ] && service="https"
[ "${port}" == "8443" ] && service="pcsync-https"

procd_add_mdns_service "$service" "tcp" "$port" "daemon=nginx"
fi
}

configure_mdns() {
procd_open_data
json_add_object "mdns"

config_load nginx
config_foreach add_mdns server

json_close_object
procd_close_data
}

start_service() {
nginx_init
Expand All @@ -86,6 +120,9 @@ start_service() {
procd_set_param file "${CONF}" "${CONF_DIR}*.crt" "${CONF_DIR}*.key" \
"${CONF_DIR}*.conf" "${CONF_DIR}*.locations"
procd_set_param respawn

configure_mdns

procd_close_instance
}

Expand Down

0 comments on commit c2d3576

Please sign in to comment.