Skip to content

Commit

Permalink
apache: replace IncludeOptional with Include
Browse files Browse the repository at this point in the history
IncludeOptional is apache 2.4 only, use Include for apache 2.2
  • Loading branch information
sni committed Jul 20, 2018
1 parent fd95e06 commit b7951b9
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 33 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pack:
done

sed -i -e 's|###APACHE_MODULE_DIR###|$(MODULE_DIR)|g' $(DESTDIR)$(OMD_ROOT)/lib/omd/hooks/*
sed -i -e 's|###APACHE_INCLUDEOPT###|$(APACHE_INCLUDEOPT)|g' $(DESTDIR)$(OMD_ROOT)/lib/omd/hooks/*

# Repair packages that install with silly modes (such as Nagios)
chmod -R o+Xr $(DESTDIR)$(OMD_ROOT)
Expand Down Expand Up @@ -262,6 +263,7 @@ rpm:
-e 's/^Release:.*/Release: $(OMD_SERIAL)/' \
-e 's#@APACHE_CONFDIR@#$(APACHE_CONF_DIR)#g' \
-e 's#@APACHE_NAME@#$(APACHE_NAME)#g' \
-e 's#@APACHE_INCLUDEOPT@#$(APACHE_INCLUDEOPT)#g' \
omd.spec.in > omd.spec
rm -f $(SOURCE_TGZ)
test -d .git && $(MAKE) $(SOURCE_TGZ) || $(MAKE) $(SOURCE_TGZ)-snap
Expand Down
10 changes: 10 additions & 0 deletions Makefile.omd
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ endif
ifdef SKIP_PACKAGES
PACKAGES:=$(shell for p in $(PACKAGES); do skip=0; for s in $(SKIP_PACKAGES); do if [ "$$s" = "$$p" ]; then skip=1; fi; done; if [ $$skip -eq 0 ]; then echo $$p; fi; done)
endif

APACHE_VERSION = $(shell $(APACHE_BIN) -v | awk '/version/ {print $$3}' | awk -F/ '{print $$2}')
APACHE_VERSION_MAIN = $(word 1, $(subst ., ,$(APACHE_VERSION)))
APACHE_VERSION_SUB = $(word 2, $(subst ., ,$(APACHE_VERSION)))
APACHE_24_OR_NEWER = $(shell [ $(APACHE_VERSION_MAIN) -ge 2 -a $(APACHE_VERSION_SUB) -ge 4 ] && echo 1 || echo 0)
ifeq ($(APACHE_24_OR_NEWER),1)
APACHE_INCLUDEOPT = IncludeOptional
else
APACHE_INCLUDEOPT = Include
endif
6 changes: 3 additions & 3 deletions debian/postinst.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ case "$1" in
fi

if ! test -e $APACHE_OMD_CONF; then
echo "IncludeOptional /omd/apache/*.conf" > $APACHE_OMD_CONF
echo "###APACHE_INCLUDEOPT### /omd/apache/*.conf" > $APACHE_OMD_CONF

# -- enable conf include, when available
! test -x /usr/sbin/a2enconf || a2enconf zzz_omd
Expand All @@ -94,10 +94,10 @@ case "$1" in
a2ensite default-ssl
fi

ls -1 /etc/apache2/sites-available/default-ssl 2>/dev/null | \
ls -1 /etc/apache2/sites-available/default-ssl.conf 2>/dev/null | \
while read file; do
if ! grep /omd/apache/ $file >/dev/null 2>&1; then
sed -i -e 's|</VirtualHost>|\n IncludeOptional /omd/apache/*.include\n</VirtualHost>|g' $file
sed -i -e 's|</VirtualHost>|\n ###APACHE_INCLUDEOPT### /omd/apache/*.include\n</VirtualHost>|g' $file
fi
done
# -- default for init
Expand Down
6 changes: 6 additions & 0 deletions debian/postrm.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ case "$1" in
fi
! test -x /usr/sbin/a2disconf || a2disconf zzz_omd
rm -f $APACHE_OMD_CONF
ls -1 /etc/apache2/sites-available/default-ssl.conf 2>/dev/null | \
while read file; do
if ! grep /omd/apache/ $file >/dev/null 2>&1; then
sed -i -e '/Include.* \/omd\/apache/d' $file
fi
done
rm -f /omd
# Try to remove empty directories
if test -d /opt/omd/versions; then
Expand Down
1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ install: build

sed -e 's/###OMD_VERSION###/$(OMD_VERSION)/g' \
-e 's/###OMD_SERIAL###/$(OMD_SERIAL)/g' \
-e 's/###APACHE_INCLUDEOPT###/$(APACHE_INCLUDEOPT)/g' \
$(_PWD)/debian/postinst.in > $(_PWD)/debian/postinst
sed -e 's/###OMD_VERSION###/$(OMD_VERSION)/g' \
$(_PWD)/debian/preinst.in > $(_PWD)/debian/preinst
Expand Down
10 changes: 9 additions & 1 deletion omd.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fi
ls -1 /etc/apache2/vhosts.d/vhost-ssl-omd.conf /etc/httpd/conf.d/ssl.conf | \
while read file; do
if ! grep /omd/apache/ $file >/dev/null 2>&1; then
sed -i -e 's|</VirtualHost>|\n IncludeOptional /omd/apache/*.include\n</VirtualHost>|g' $file
sed -i -e 's|</VirtualHost>|\n @APACHE_INCLUDEOPT@ /omd/apache/*.include\n</VirtualHost>|g' $file
fi
done

Expand Down Expand Up @@ -219,6 +219,14 @@ else
rm -f @APACHE_CONFDIR@/zzz_omd.conf
rm -f /etc/apache2/vhosts.d/vhost-ssl-omd.conf
rm -f /omd
ls -1 /etc/apache2/vhosts.d/vhost-ssl-omd.conf /etc/httpd/conf.d/ssl.conf | \
while read file; do
if ! grep /omd/apache/ $file >/dev/null 2>&1; then
sed -i -e '/Include.* \/omd\/apache/d' $file
fi
done


# Try to remove empty directories
rmdir /opt/omd/sites 2>/dev/null || true
rmdir /opt/omd 2>/dev/null || true
Expand Down
1 change: 1 addition & 0 deletions packages/apache-omd/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod_fcgid-?.?.?
mod_rpaf-?.?
2 changes: 1 addition & 1 deletion packages/apache-omd/APACHE_TCP_PORT.hook
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ EOF
</Location>
</IfModule>
IncludeOptional $OMD_ROOT/etc/apache/*.include
###APACHE_INCLUDEOPT### $OMD_ROOT/etc/apache/system.d/*.conf
EOF
if [ "$PORT" != "$2" ] ; then
echo "Apache port $2 is in use. I've choosen $PORT instead." >&2
Expand Down
5 changes: 0 additions & 5 deletions packages/apache-omd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ DIR = $(NAME)-$(VERSION)
FCGI_FILE="mod_fcgid-2.3.9"
MOD_RPAF_VERSION="0.8"

APACHE_VERSION = $(shell $(APACHE_BIN) -v | awk '/version/ {print $$3}' | awk -F/ '{print $$2}')
APACHE_VERSION_MAIN = $(word 1, $(subst ., ,$(APACHE_VERSION)))
APACHE_VERSION_SUB = $(word 2, $(subst ., ,$(APACHE_VERSION)))
APACHE_24_OR_NEWER = $(shell [ $(APACHE_VERSION_MAIN) -ge 2 -a $(APACHE_VERSION_SUB) -ge 4 ] && echo 1 || echo 0)

APACHE_MODULES=modrpaf
APACHE_MODULES_INSTALL=modrpaf_install
APACHE_FCGID_PATH=$(MODULE_DIR)/$(APACHE_FCGID_MODULE)
Expand Down
36 changes: 17 additions & 19 deletions packages/apache-omd/WEB_ALIAS.hook
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,43 @@ case "$1" in
echo ""
;;
choices)
echo "([a-zA-Z0-9-]+)"
echo "([a-zA-Z0-9-_]+)"
;;
set)
ALIAS=$2
cat <<EOF > $OMD_ROOT/etc/apache/alias.include
. $OMD_ROOT/etc/omd/site.conf >/dev/null 2>&1
PROTO="http"
if [ $CONFIG_APACHE_MODE = "ssl" ]; then
PROTO="https"
fi
sed -i $OMD_ROOT/etc/grafana/grafana.ini -e 's/^root_url.*/root_url = %(protocol)s:\/\/%(domain)s\/'$OMD_SITE'\/grafana\//g'
rm -f $OMD_ROOT/etc/apache/thruk/thruk_local.d/omd_web_alias.conf
mkdir -p $OMD_ROOT/etc/apache/system.d
cat <<EOF > $OMD_ROOT/etc/apache/system.d/alias.conf
# This file is managed by 'omd config set WEB_ALIAS'.
# Better do not edit manually
EOF
if [ ! -z $ALIAS ]; then
cat <<EOF >> $OMD_ROOT/etc/apache/alias.include
#RewriteEngine on
#RewriteCond %{REQUEST_METHOD} GET
#RewriteRule ^/$OMD_SITE(.*) /$ALIAS\$1 [R=permanent,L,NE]
#RewriteRule ^/$ALIAS(.*) /$OMD_SITE\$1 [PT,L,NE]
#Alias /$OMD_SITE "$OMD_ROOT/var/www"
#<Directory "$OMD_ROOT/var/www">
# Options +SymLinksIfOwnerMatch
# AllowOverride All
# Order deny,allow
# Allow from all
#</Directory>
cat <<EOF >> $OMD_ROOT/etc/apache/system.d/alias.conf
RewriteEngine on
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^/$OMD_SITE(.*) /$ALIAS\$1 [R=permanent,L,NE]
<IfModule mod_proxy_http.c>
<Location /$ALIAS>
# Setting "retry=0" to prevent 60 second caching of problem states e.g. when
# the site apache is down and someone tries to access the page.
# "disablereuse=On" prevents the apache from keeping the connection which leads to
# wrong devlivered pages sometimes
ProxyPass https://127.0.0.1:5000/$OMD_SITE retry=0 disablereuse=On
ProxyPassReverse https://127.0.0.1:5000/$OMD_SITE
ProxyPass $PROTO://$CONFIG_APACHE_TCP_ADDR:$CONFIG_APACHE_TCP_PORT/$OMD_SITE retry=0 disablereuse=On
ProxyPassReverse $PROTO://$CONFIG_APACHE_TCP_ADDR:$CONFIG_APACHE_TCP_PORT/$OMD_SITE
</Location>
</IfModule>
EOF
cat <<EOF > $OMD_ROOT/etc/apache/thruk/thruk_local.d/omd_web_alias.conf
cookie_path = /$ALIAS
EOF
sed -i $OMD_ROOT/etc/grafana/grafana.ini -e 's/^root_url.*/root_url = %(protocol)s:\/\/%(domain)s\/'$ALIAS'\/grafana\//g'
fi
;;
depends)
Expand Down
6 changes: 3 additions & 3 deletions packages/apache-omd/WEB_REDIRECT.hook
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ case "$1" in
echo "on: redirect / to /$TARGET"
;;
set)
# just create an empty file
cat <<EOF > $OMD_ROOT/etc/apache/redirect.include
mkdir -p $OMD_ROOT/etc/apache/system.d
cat <<EOF > $OMD_ROOT/etc/apache/system.d/redirect.conf
# This file is managed by 'omd config set WEB_REDIRECT'.
# Better do not edit manually
EOF
Expand All @@ -35,7 +35,7 @@ EOF
echo "redirect is currently enabled for site: $CURRENT" >&2
echo "off"
else
cat <<EOF >>$OMD_ROOT/etc/apache/redirect.include
cat <<EOF >>$OMD_ROOT/etc/apache/system.d/redirect.conf
# redirect / to our site
RewriteEngine On
RewriteRule ^/$ /$OMD_SITE/ [R,L]
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/omd/omd
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ def create_apache_hook(sitename):
file("/omd/apache/%s.conf" % sitename, "w")\
.write("Include %s/etc/apache/mode.conf\n" % site_dir(sitename))
file("/omd/apache/%s.include" % sitename, "w")\
.write("IncludeOptional %s/etc/apache/*.include\n" % site_dir(sitename))
.write("Include %s/etc/apache/system.d/*.conf\n" % site_dir(sitename))

def delete_apache_hook(sitename):
hook_path = "/omd/apache/%s.conf" % sitename
Expand Down

0 comments on commit b7951b9

Please sign in to comment.