X-Git-Url: http://git.pld-linux.org/?a=blobdiff_plain;f=lighttpd.init;h=aaf4d5fae66946360f8b500221b0320f8a21e928;hb=d409489;hp=d13505de991de46e8cf97474018bdd152eb92e7b;hpb=cb1656fe2e7f6cc0bbd68c738b39a7de86615ab2;p=packages%2Flighttpd.git diff --git a/lighttpd.init b/lighttpd.init old mode 100644 new mode 100755 index d13505d..aaf4d5f --- a/lighttpd.init +++ b/lighttpd.init @@ -10,67 +10,215 @@ # Source function library . /etc/rc.d/init.d/functions +upstart_controlled + # Get network config . /etc/sysconfig/network # Get service config [ -f /etc/sysconfig/lighttpd ] && . /etc/sysconfig/lighttpd +DAEMON=/usr/sbin/lighttpd +ANGEL_DAEMON=/usr/sbin/lighttpd-angel +CONFIGFILE=/etc/lighttpd/lighttpd.conf + # Check that networking is up. if is_yes "${NETWORKING}"; then if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then - # nls "ERROR: Networking is down. %s can't be run." - msg_network_down lighttpd + msg_network_down "Lighttpd Web Server" exit 1 fi else exit 0 fi -RETVAL=0 -# See how we were called. -case "$1" in - start) - # Check if the service is already running? - if [ ! -f /var/lock/subsys/lighttpd ]; then - msg_starting lighttpd - daemon lighttpd -f /etc/lighttpd/lighttpd.conf $HTTPD_OPTS +configtest() { + # check for deprecated config options that cause bad side effects + # TODO: should remove the deprecated options in pld after some time being warned out + local out + out=$(env SHELL=/bin/sh $DAEMON -f $CONFIGFILE $HTTPD_OPTS -p 2>&1 | grep -oE '(url.rewrite|url.rewrite-final)[[:space:]]') + if [ -n "$out" ]; then + # make it unique, format nicely + out=$(echo "$out" | sort -u | xargs | sed -e 's/ /, /g') + echo >&2 "WARNING: found deprecated '$out', convert to 'url.rewrite-final' recommented, See http://redmine.lighttpd.net/issues/2379" + fi + + env SHELL=/bin/sh $DAEMON -t -f $CONFIGFILE $HTTPD_OPTS +} + +# wrapper for configtest +checkconfig() { + local details=${1:-0} + + if [ $details = 1 ]; then + # run config test and display report (status action) + show "Checking %s configuration" "Lighttpd Web Server"; busy + local out + out=$(configtest 2>&1) RETVAL=$? - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/lighttpd + if [ $RETVAL = 0 ]; then + ok + else + fail + fi + [ "$out" ] && echo >&2 "$out" else - msg_already_running lighttpd + # run config test and abort with nice message if failed + # (for actions checking status before action). + configtest >/dev/null 2>&1 + RETVAL=$? + if [ $RETVAL != 0 ]; then + show "Checking %s configuration" "Lighttpd Web Server"; fail + nls 'Configuration test failed. See details with %s "checkconfig"' $0 + exit $RETVAL + fi fi - ;; - stop) - # Stop daemons. +} + +start() { + # Check if the service is already running? if [ -f /var/lock/subsys/lighttpd ]; then - msg_stopping lighttpd - killproc lighttpd - rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1 + msg_already_running "Lighttpd Web Server" + return + fi + + checkconfig + msg_starting "Lighttpd Web Server"; busy + if is_yes "${LIGHT_ANGEL}"; then + daemon --fork --pidfile /var/run/lighttpd-angel.pid --makepid \ + env SHELL=/bin/sh $ANGEL_DAEMON -D -f $CONFIGFILE $HTTPD_OPTS + else - msg_not_running lighttpd + env SHELL=/bin/sh $DAEMON -f $CONFIGFILE $HTTPD_OPTS fi - ;; - status) - status lighttpd RETVAL=$? + if [ $RETVAL -eq 0 ]; then + ok + touch /var/lock/subsys/lighttpd + else + fail + fi +} + +stop() { + # Stop daemons. + if [ ! -f /var/lock/subsys/lighttpd ]; then + msg_not_running "Lighttpd Web Server" + return + fi + + msg_stopping "Lighttpd Web Server" + killproc --pidfile /var/run/lighttpd.pid lighttpd + rm -f /var/lock/subsys/lighttpd >/dev/null 2>&1 + rm -f /var/run/lighttpd*.pid >/dev/null 2>&1 +} + +restart() { + local pid + + # short circuit to safe reload if pid exists and is alive + if is_yes "${LIGHT_ANGEL}"; then + if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd-angel lighttpd-angel.pid) && checkpid $pid; then + reload + return + fi + else + if [ -f /var/lock/subsys/lighttpd ] && pid=$(pidofproc lighttpd lighttpd.pid) && checkpid $pid; then + reload + return + fi + fi + + checkconfig + stop + start +} + +reload() { + # TODO: check if process is running. Start it in this case. + if [ ! -f /var/lock/subsys/lighttpd ]; then + msg_not_running "Lighttpd Web Server" + RETVAL=7 + return + fi + + checkconfig 1 + msg_reloading "Lighttpd Web Server" + + if is_yes "${LIGHT_ANGEL}"; then + # sending HUP signal to angel will make lighttpd close all listening + # sockets and wait for client connections to terminate. After that new + # child will be started + killproc lighttpd-angel -HUP + else + # sending INT signal will make lighttpd close all listening sockets and + # wait for client connections to terminate. + killproc --pidfile /var/run/lighttpd.pid lighttpd -INT + env SHELL=/bin/sh lighttpd -f $CONFIGFILE $HTTPD_OPTS + fi + RETVAL=$? +} + +condrestart() { + if [ ! -f /var/lock/subsys/lighttpd ]; then + msg_not_running "Lighttpd Web Server" + RETVAL=$1 + return + fi + + checkconfig + stop + start +} + +flush-logs() { + if [ ! -f /var/lock/subsys/lighttpd ]; then + msg_not_running "Lighttpd Web Server" + RETVAL=7 + return + fi + + show "Rotating %s logs" lighttpd + # send HUP to main lighttpd (not angel) process to rotate logs: + killproc --pidfile /var/run/lighttpd.pid lighttpd -HUP + RETVAL=$? +} + +RETVAL=0 +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop ;; restart) - $0 stop - $0 start + restart + ;; + try-restart) + condrestart 0 ;; reload|force-reload|graceful) - if [ -f /var/lock/subsys/lighttpd ]; then - msg_reloading lighttpd - killproc lighttpd -HUP - RETVAL=$? - else - msg_not_running lighttpd - RETVAL=7 + reload + ;; + flush-logs) + flush-logs + ;; + checkconfig|configtest) + checkconfig 1 + ;; + show-config) + env SHELL=/bin/sh $DAEMON -p -f $CONFIGFILE $HTTPD_OPTS + ;; + status) + if is_yes "${LIGHT_ANGEL}"; then + status lighttpd-angel || RETVAL=$? fi + status lighttpd || RETVAL=$? ;; *) - msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|status}" + msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|configtest|flush-logs|show-config|status}" exit 3 ;; esac