1#! /bin/sh 2# Copyright (c) 1995-2002 SuSE Linux AG, Nuernberg, Germany. 3# All rights reserved. 4# 5# Author: Kurt Garloff <[email protected]> 6# 7# /etc/init.d/FOO 8# 9# and symbolic its link 10# 11# /(usr/)sbin/rcFOO 12# 13# LSB compliant service control script; see http://www.linuxbase.org/spec/ 14# 15# System startup script for some example service or daemon FOO (template) 16# 17### BEGIN INIT INFO 18# Provides: FOO 19# Required-Start: $remote_fs $syslog 20# Required-Stop: $remote_fs $syslog 21# Default-Start: 3 5 22# Default-Stop: 0 1 2 6 23# Description: Start FOO to allow XY and provide YZ 24# continued on second line by '#<TAB>' 25### END INIT INFO 26# 27# Note on Required-Start: It does specify the init script ordering, 28# not real dependencies. Depencies have to be handled by admin 29# resp. the configuration tools (s)he uses. 30 31# Source SuSE config (if still necessary, most info has been moved) 32test -r /etc/rc.config && . /etc/rc.config 33 34# Check for missing binaries (stale symlinks should not happen) 35LIGHTTPD_BIN=/usr/sbin/lighttpd 36test -x $LIGHTTPD_BIN || exit 5 37 38# Check for existence of needed config file and read it 39LIGHTTPD_CONFIG=/etc/sysconfig/lighttpd 40test -r $LIGHTTPD_CONFIG || exit 6 41. $LIGHTTPD_CONFIG 42 43# Shell functions sourced from /etc/rc.status: 44# rc_check check and set local and overall rc status 45# rc_status check and set local and overall rc status 46# rc_status -v ditto but be verbose in local rc status 47# rc_status -v -r ditto and clear the local rc status 48# rc_failed set local and overall rc status to failed 49# rc_failed <num> set local and overall rc status to <num><num> 50# rc_reset clear local rc status (overall remains) 51# rc_exit exit appropriate to overall rc status 52# rc_active checks whether a service is activated by symlinks 53. /etc/rc.status 54 55# First reset status of this service 56rc_reset 57 58# Return values acc. to LSB for all commands but status: 59# 0 - success 60# 1 - generic or unspecified error 61# 2 - invalid or excess argument(s) 62# 3 - unimplemented feature (e.g. "reload") 63# 4 - insufficient privilege 64# 5 - program is not installed 65# 6 - program is not configured 66# 7 - program is not running 67# 68# Note that starting an already running service, stopping 69# or restarting a not-running service as well as the restart 70# with force-reload (in case signalling is not supported) are 71# considered a success. 72 73case "$1" in 74 start) 75 echo -n "Starting lighttpd" 76 ## Start daemon with startproc(8). If this fails 77 ## the echo return value is set appropriate. 78 79 # NOTE: startproc returns 0, even if service is 80 # already running to match LSB spec. 81 startproc $LIGHTTPD_BIN -f $LIGHTTPD_CONF_PATH 82 83 # Remember status and be verbose 84 rc_status -v 85 ;; 86 stop) 87 echo -n "Shutting down lighttpd" 88 ## Stop daemon with killproc(8) and if this fails 89 ## set echo the echo return value. 90 91 killproc -TERM $LIGHTTPD_BIN 92 93 # Remember status and be verbose 94 rc_status -v 95 ;; 96 try-restart) 97 ## Stop the service and if this succeeds (i.e. the 98 ## service was running before), start it again. 99 ## Note: try-restart is not (yet) part of LSB (as of 0.7.5) 100 $0 status >/dev/null && $0 restart 101 102 # Remember status and be quiet 103 rc_status 104 ;; 105 restart) 106 ## Stop the service and regardless of whether it was 107 ## running or not, start it again. 108 $0 stop 109 $0 start 110 111 # Remember status and be quiet 112 rc_status 113 ;; 114 force-reload|reload) 115 ## Like force-reload, but if daemon does not support 116 ## signalling, do nothing (!) 117 118 # If it supports signalling: 119 echo -n "Reload service LIGHTTPD" 120 killproc -INT $LIGHTTPD_BIN 121 $0 start 122 touch /var/run/lighttpd.pid 123 rc_status -v 124 125 ## Otherwise if it does not support reload: 126 #rc_failed 3 127 #rc_status -v 128 ;; 129 status) 130 echo -n "Checking for service LIGHTTPD: " 131 ## Check status with checkproc(8), if process is running 132 ## checkproc will return with exit status 0. 133 134 # Return value is slightly different for the status command: 135 # 0 - service running 136 # 1 - service dead, but /var/run/ pid file exists 137 # 2 - service dead, but /var/lock/ lock file exists 138 # 3 - service not running 139 140 # NOTE: checkproc returns LSB compliant status values. 141 checkproc $LIGHTTPD_BIN 142 rc_status -v 143 ;; 144 probe) 145 ## Optional: Probe for the necessity of a reload, 146 ## print out the argument which is required for a reload. 147 148 test /etc/lighttpd/lighttpd.conf -nt /var/run/lighttpd.pid && echo reload 149 ;; 150 *) 151 echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 152 exit 1 153 ;; 154esac 155rc_exit 156