You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=80
  4. USE_PROCD=1
  5. G_OPTS="daemon off;"
  6. NGINX_UTIL="/usr/bin/nginx-util"
  7. eval $("${NGINX_UTIL}" get_env)
  8. CONF=""
  9. nginx_init() {
  10. [ -z "${CONF}" ] || return # already called.
  11. [ -d /var/log/nginx ] || mkdir -p /var/log/nginx
  12. [ -d /var/lib/nginx ] || mkdir -p /var/lib/nginx
  13. rm -f "$(readlink "${UCI_CONF}")"
  14. ${NGINX_UTIL} init_lan
  15. if [ -e "${UCI_CONF}" ]
  16. then CONF="${UCI_CONF}"
  17. else CONF="${NGINX_CONF}"
  18. fi
  19. local message
  20. message="$(/usr/sbin/nginx -t -c "${CONF}" -g "${G_OPTS}" 2>&1)" ||
  21. {
  22. echo -e "${message}" | logger -t "nginx_init" -p "daemon.err"
  23. logger -s -t "nginx_init" -p "daemon.err" "NOT using conf file!"
  24. echo "show config to be used by: nginx -T -c '${CONF}'" >&2
  25. exit 1
  26. }
  27. logger -t "nginx_init" -p "daemon.info" "using ${CONF} (the test is ok)"
  28. }
  29. start_service() {
  30. nginx_init
  31. procd_open_instance
  32. procd_set_param command /usr/sbin/nginx -c "${CONF}" -g "${G_OPTS}"
  33. procd_set_param stdout 1
  34. procd_set_param stderr 1
  35. procd_set_param file "${CONF}" "${CONF_DIR}*.crt" "${CONF_DIR}*.key" \
  36. "${CONF_DIR}*.conf" "${CONF_DIR}*.locations"
  37. procd_set_param respawn
  38. procd_close_instance
  39. }
  40. reload_service() {
  41. nginx_init
  42. if [ "$(cat "/proc/$(cat "/var/run/nginx.pid")/cmdline")" = \
  43. "nginx: master process /usr/sbin/nginx -c ${CONF} -g ${G_OPTS}" ]
  44. then procd_send_signal nginx
  45. else restart
  46. fi
  47. }
  48. extra_command "relog" "Reopen log files (without reloading)"
  49. relog() {
  50. [ -d /var/log/nginx ] || mkdir -p /var/log/nginx
  51. procd_send_signal nginx '*' USR1
  52. }