Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #edit /etc/default/apache2 to change this.$
- HTCACHECLEAN_RUN=auto$
- HTCACHECLEAN_MODE=daemon$
- HTCACHECLEAN_SIZE=300M$
- HTCACHECLEAN_DAEMON_INTERVAL=120$
- HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_disk_cache$
- HTCACHECLEAN_OPTIONS=""$
- $
- APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD)$
- if [ -z "$APACHE_HTTPD" ] ; then$
- ^IAPACHE_HTTPD=/usr/sbin/apache2$
- fi$
- if [ ! -x $APACHE_HTTPD ] ; then$
- ^Iecho "No apache MPM package installed"$
- ^Iexit 0$
- fi$
- $
- . /lib/lsb/init-functions$
- $
- test -f /etc/default/rcS && . /etc/default/rcS$
- $
- if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then$
- ^I. /etc/default/apache2$DIR_SUFFIX$
- elif [ -f /etc/default/apache2 ] ; then$
- ^I. /etc/default/apache2$
- fi$
- $
- APACHE2CTL="$ENV /usr/sbin/apache2ctl"$
- HTCACHECLEAN="$ENV /usr/sbin/htcacheclean"$
- $
- PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)$
- if [ -z "$PIDFILE" ] ; then$
- ^Iecho ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2$
- ^Iexit 2$
- fi$
- $
- $
- check_htcacheclean() {$
- ^I[ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1$
- $
- ^I[ "$HTCACHECLEAN_RUN" = "yes" ] && return 0$
- $
- ^IMODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED)$
- ^I[ "$HTCACHECLEAN_RUN" = "auto" \$
- ^I -a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \$
- ^I^Ireturn 0$
- ^I$
- ^Ireturn 1$
- }$
- <Directory "/var/www/statys?tyki/">$
- $
- Options Indexes FollowSymLinks$
- $
- AllowOverride All$
- $
- Order allow,deny$
- $
- Allow from all$
- $
- </Directory>$
- start_htcacheclean() {$
- ^Iif [ ! -d "$HTCACHECLEAN_PATH" ] ; then$
- ^I^Iecho "... directory $HTCACHECLEAN_PATH does not exist!" >&2$
- ^I^Ireturn 1$
- ^Ifi^I$
- ^I$HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \$
- ^I^I^I-i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE$
- }$
- $
- stop_htcacheclean() {$
- ^Ipkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null || echo ...not running$
- }$
- $
- pidof_apache() {$
- ^I# if there is actually an apache2 process whose pid is in PIDFILE,$
- ^I# print it and return 0.$
- ^Iif [ -e "$PIDFILE" ]; then$
- ^I^Iif pidof apache2 | tr ' ' '\n' | grep -w $(cat $PIDFILE); then$
- ^I^I^Ireturn 0$
- ^I^Ifi$
- ^Ifi$
- ^Ireturn 1$
- }$
- $
- apache_stop() {$
- ^Iif $APACHE2CTL configtest > /dev/null 2>&1; then$
- ^I^I# if the config is ok than we just stop normaly$
- $APACHE2CTL stop 2>&1 | grep -v 'not running' >&2 || true$
- ^Ielse$
- ^I^I# if we are here something is broken and we need to try$
- ^I^I# to exit as nice and clean as possible$
- ^I^IPID=$(pidof_apache) || true$
- $
- ^I^Iif [ "${PID}" ]; then$
- ^I^I^I# in this case it is everything nice and dandy and we kill apache2$
- ^I^I^Iecho$
- ^I^I^Ilog_warning_msg "The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"$
- kill $PID$
- ^I^Ielif [ "$(pidof apache2)" ]; then$
- ^I^I^Iif [ "$VERBOSE" != no ]; then$
- echo " ... failed!"$
- ^I^I^I echo "You may still have some apache2 processes running. There are"$
- ^I^I^I echo "processes named 'apache2' which do not match your pid file,"$
- ^I^I^I echo "and in the name of safety, we've left them alone. Please review"$
- ^I^I^I echo "the situation by hand."$
- fi$
- return 1$
- ^I^Ifi$
- ^Ifi$
- }$
- $
- apache_wait_stop() {$
- ^I# running ?$
- ^IPIDTMP=$(pidof_apache) || true$
- ^Iif kill -0 "${PIDTMP:-}" 2> /dev/null; then$
- ^I PID=$PIDTMP$
- ^Ifi$
- $
- ^Iapache_stop$
- $
- ^I# wait until really stopped$
- ^Iif [ -n "${PID:-}" ]; then$
- ^I^Ii=0$
- ^I^Iwhile kill -0 "${PID:-}" 2> /dev/null; do$
- ^I^Iif [ $i = '60' ]; then$
- ^I^I^Ibreak;$
- ^I ^Ielse$
- ^I^I^Iif [ $i = '0' ]; then$
- ^I^I^Iecho -n " ... waiting "$
- ^I^I^Ielse$
- ^I ^I^Iecho -n "."$
- ^I^I ^Ifi$
- ^I^I^Ii=$(($i+1))$
- ^I^I^Isleep 1$
- ^I fi$
- ^I^I done$
- ^Ifi$
- }$
- $
- case $1 in$
- ^Istart)$
- ^I^Ilog_daemon_msg "Starting web server" "apache2"$
- ^I^Iif $APACHE2CTL start; then$
- ^I^I^Iif check_htcacheclean ; then$
- ^I^I^I^Ilog_progress_msg htcacheclean$
- ^I^I^I^Istart_htcacheclean || log_end_msg 1$
- ^I^I^Ifi$
- log_end_msg 0$
- else$
- log_end_msg 1$
- fi$
- ^I;;$
- ^Istop)$
- ^I^Iif check_htcacheclean ; then$
- ^I^I^Ilog_daemon_msg "Stopping web server" "htcacheclean"$
- ^I^I^Istop_htcacheclean$
- ^I^I^Ilog_progress_msg "apache2"$
- ^I^Ielse$
- ^I^I^Ilog_daemon_msg "Stopping web server" "apache2"$
- ^I^Ifi$
- ^I^Iif apache_wait_stop; then$
- log_end_msg 0$
- else$
- log_end_msg 1$
- fi$
- ^I;;$
- ^Igraceful-stop)$
- ^I^Iif check_htcacheclean ; then$
- ^I^I^Ilog_daemon_msg "Stopping web server" "htcacheclean"$
- ^I^I^Istop_htcacheclean$
- ^I^I^Ilog_progress_msg "apache2"$
- ^I^Ielse$
- ^I^I^Ilog_daemon_msg "Stopping web server" "apache2"$
- ^I^Ifi$
- ^I^Iif $APACHE2CTL graceful-stop; then$
- log_end_msg 0$
- else$
- log_end_msg 1$
- fi$
- ^I;;$
- ^Ireload | force-reload | graceful)$
- ^I^Iif ! $APACHE2CTL configtest > /dev/null 2>&1; then$
- $APACHE2CTL configtest || true$
- log_end_msg 1$
- exit 1$
- fi$
- log_daemon_msg "Reloading web server config" "apache2"$
- ^I^Iif pidof_apache > /dev/null ; then$
- if $APACHE2CTL graceful $2 ; then$
- log_end_msg 0$
- else$
- log_end_msg 1$
- fi$
- fi$
- ^I;;$
- ^Irestart)$
- ^I^Iif ! $APACHE2CTL configtest > /dev/null 2>&1; then$
- ^I^I $APACHE2CTL configtest || true$
- ^I^I log_end_msg 1$
- ^I^I exit 1$
- ^I^Ifi$
- ^I^Iif check_htcacheclean ; then$
- ^I^I^Ilog_daemon_msg "Restarting web server" "htcacheclean"$
- ^I^I^Istop_htcacheclean$
- ^I^I^Ilog_progress_msg apache2$
- ^I^Ielse$
- ^I^I^Ilog_daemon_msg "Restarting web server" "apache2"$
- ^I^Ifi$
- ^I^IPID=$(pidof_apache) || true$
- ^I^Iif ! apache_wait_stop; then$
- log_end_msg 1 || true$
- fi$
- ^I^Iif $APACHE2CTL start; then$
- ^I^I^Iif check_htcacheclean ; then$
- ^I^I^I^Istart_htcacheclean || log_end_msg 1$
- ^I^I^Ifi$
- log_end_msg 0$
- else$
- log_end_msg 1$
- fi$
- ^I;;$
- ^Istart-htcacheclean)$
- ^I^Ilog_daemon_msg "Starting htcacheclean"$
- ^I^Istart_htcacheclean || log_end_msg 1$
- ^I^Ilog_end_msg 0$
- ^I;;$
- ^Istop-htcacheclean)$
- ^I^Ilog_daemon_msg "Stopping htcacheclean"$
- ^I^I^Istop_htcacheclean$
- ^I^I^Ilog_end_msg 0$
- ^I;;$
- ^Istatus)$
- ^I^IPID=$(pidof_apache) || true$
- ^I^Iif [ -n "$PID" ]; then$
- ^I^I^Iecho "Apache2$DIR_SUFFIX is running (pid $PID)."$
- ^I^I^Iexit 0$
- ^I^Ielse$
- ^I^I^Iecho "Apache2$DIR_SUFFIX is NOT running."$
- ^I^I^Iif [ -e "$PIDFILE" ]; then$
- ^I^I^I^Iexit 1$
- ^I^I^Ielse$
- ^I^I^I^Iexit 3$
- ^I^I^Ifi$
- ^I^Ifi$
- ^I;;$
- ^I*)$
- ^I^Ilog_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}"$
- ^I^Iexit 1$
- ^I;;$
- esac$
Advertisement
Add Comment
Please, Sign In to add comment