#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org

START=80

USE_PROCD=1

start_service() {
	[ -d /var/lib/nginx ] || mkdir -p /var/lib/nginx
	chown -R nobody:nogroup /var/lib/nginx

	procd_open_instance
	procd_set_param command /usr/sbin/nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
	procd_set_param file /etc/nginx/nginx.conf
	procd_set_param respawn
	procd_close_instance
}

service_triggers() {
	procd_add_reload_interface_trigger loopback
	procd_add_reload_interface_trigger lan
}

reload_service() {
	[ -d /var/lib/nginx ] || mkdir -p /var/lib/nginx

	procd_send_signal nginx
}

extra_command "relog" "Reopen log files (without reloading)"
relog() {
	[ -d /var/log/nginx ] || mkdir -p /var/log/nginx
	procd_send_signal nginx '*' USR1
}
