#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/www-servers/nginx/files/nginx,v 1.3 2005/05/29 14:30:28 voxus Exp $

opts="${opts} reload configtest"

depend() {
	need net
	use dns logger
}

start() {
	configtest || return 1
	ebegin "Starting nginx"
	start-stop-daemon --start --pidfile /var/run/nginx.pid \
		--exec /usr/sbin/nginx -- -c /etc/nginx/nginx.conf
	eend $? "Failed to start nginx"
}

stop() {
	configtest || return 1
	ebegin "Stopping nginx"
	start-stop-daemon --stop --pidfile /var/run/nginx.pid
	eend $? "Failed to stop nginx"
	rm -f /var/run/nginx.pid
}

reload() {
	configtest || return 1
	ebegin "Refreshing nginx' configuration"
	kill -HUP `cat /var/run/nginx.pid` &>/dev/null
	eend $? "Failed to reload nginx"
}

configtest() {
	ebegin "Checking nginx' configuration"
	/usr/sbin/nginx -c /etc/nginx/nginx.conf -t
	eend $? "failed, please correct errors above"
}
