Introduce support for migration of old uci conf template to new version.
Uci conf template are saved in config backup. This cause problem on config
restore as old config template might have compatibility problem with new
nginx implementation.
Add logic to migrate the template script at runtime to correctly align
to latest change from nginx and nginx-util.
Fixes: 65a676ed56
("nginx: introduce support for dynamic modules")
Fixes: #20904
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
98 lines
2.2 KiB
Bash
98 lines
2.2 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
# Copyright (C) 2015 OpenWrt.org
|
|
|
|
START=80
|
|
|
|
USE_PROCD=1
|
|
|
|
G_OPTS="daemon off;"
|
|
|
|
NGINX_UTIL="/usr/bin/nginx-util"
|
|
UCI_CONF_TEMPLATE="/etc/nginx/uci.conf.template"
|
|
LATEST_UCI_CONF_VERSION="1.1"
|
|
|
|
eval $("${NGINX_UTIL}" get_env)
|
|
|
|
CONF=""
|
|
|
|
nginx_check_luci_template() {
|
|
UCI_CONF_VERSION="$(sed -nr 's/# UCI_CONF_VERSION=(.*)/\1/p' $UCI_CONF_TEMPLATE)"
|
|
|
|
# No need to migrate already latest version
|
|
if [ "$UCI_CONF_VERSION" = "$LATEST_UCI_CONF_VERSION" ]; then
|
|
return
|
|
fi
|
|
|
|
if [ -z "$UCI_CONF_VERSION" ]; then
|
|
echo "" >> $UCI_CONF_TEMPLATE
|
|
echo "include module.d/*.module;" >> $UCI_CONF_TEMPLATE
|
|
echo "# UCI_CONF_VERSION=1.1" >> $UCI_CONF_TEMPLATE
|
|
fi
|
|
}
|
|
|
|
nginx_init() {
|
|
[ -z "${CONF}" ] || return # already called.
|
|
|
|
[ -d /var/log/nginx ] || mkdir -p /var/log/nginx
|
|
[ -d /var/lib/nginx ] || mkdir -p /var/lib/nginx
|
|
|
|
rm -f "$(readlink "${UCI_CONF}")"
|
|
${NGINX_UTIL} init_lan
|
|
|
|
if [ -f $UCI_CONF_TEMPLATE ]; then
|
|
nginx_check_luci_template
|
|
fi
|
|
|
|
if [ -e "${UCI_CONF}" ]
|
|
then CONF="${UCI_CONF}"
|
|
else CONF="${NGINX_CONF}"
|
|
fi
|
|
|
|
local message
|
|
message="$(/usr/sbin/nginx -t -c "${CONF}" -g "${G_OPTS}" 2>&1)" ||
|
|
{
|
|
echo -e "${message}" | logger -t "nginx_init" -p "daemon.err"
|
|
logger -s -t "nginx_init" -p "daemon.err" "NOT using conf file!"
|
|
echo "show config to be used by: nginx -T -c '${CONF}'" >&2
|
|
exit 1
|
|
}
|
|
|
|
logger -t "nginx_init" -p "daemon.info" "using ${CONF} (the test is ok)"
|
|
}
|
|
|
|
|
|
start_service() {
|
|
nginx_init
|
|
|
|
procd_open_instance
|
|
procd_set_param command /usr/sbin/nginx -c "${CONF}" -g "${G_OPTS}"
|
|
procd_set_param stdout 1
|
|
procd_set_param stderr 1
|
|
procd_set_param file "${CONF}" "${CONF_DIR}*.crt" "${CONF_DIR}*.key" \
|
|
"${CONF_DIR}*.conf" "${CONF_DIR}*.locations"
|
|
procd_set_param respawn
|
|
procd_close_instance
|
|
}
|
|
|
|
|
|
reload_service() {
|
|
nginx_init
|
|
|
|
if [ "$(cat "/proc/$(cat "/var/run/nginx.pid")/cmdline")" = \
|
|
"nginx: master process /usr/sbin/nginx -c ${CONF} -g ${G_OPTS}" ]
|
|
then procd_send_signal nginx
|
|
else restart
|
|
fi
|
|
}
|
|
|
|
|
|
service_triggers() {
|
|
procd_add_raw_trigger acme.renew 5000 /etc/init.d/nginx reload
|
|
}
|
|
|
|
|
|
extra_command "relog" "Reopen log files (without reloading)"
|
|
relog() {
|
|
[ -d /var/log/nginx ] || mkdir -p /var/log/nginx
|
|
procd_send_signal nginx '*' USR1
|
|
}
|