Module Init Notes
What should happen when someone installs an apache module? Certainly copy a .so file to the right place but what else. Should we
- enable the module? Debian-based OS have a concept of "modules available" vs. "modules enabled"
- restart apache? and if so, how? If installed in a docker image, then this step is unlikely to happen
What should happen when the module is un-installed?
CentOS Family
- Unable to find anything on RedHat or CentOS packaging
- Fedora Draft guidelines
- Fedora guidelines appears worthless
- CentOS 5 is apache 2.2, and CentOS 7 is apache 2.4,, but
- CentOS 6 has both
- Appears that CentOS Family, installs module, enables module but does not do anything with the apache server.
- On uninstall, the
.conffile that loads the module is removed and that's the end of that.
# rpm --query --fileprovide mod_passenger
/etc/httpd/conf.d/passenger.conf
/etc/httpd/conf.modules.d/passenger.conf
/usr/lib64/httpd/modules/mod_passenger.so
/usr/share/doc/mod_passenger-4.0.53
/usr/share/doc/mod_passenger-4.0.53/Users guide Apache.txt
# cat /etc/httpd/conf.modules.d/passenger.conf
LoadModule passenger_module modules/mod_passenger.so
# cat /etc/httpd/conf.d/passenger.conf
<IfModule mod_passenger.c>
PassengerRoot /usr/share/passenger//phusion_passenger/locations.ini
PassengerRuby /usr/bin/ruby
</IfModule>
# Deploying a Ruby on Rails application: an example
# Suppose you have a Rails application in /somewhere. Add a virtual host to
# your Apache configuration file and set its DocumentRoot to /somewhere/public:
#
# <VirtualHost *:80>
# ServerName www.yourhost.com
# Be sure to point to 'public'!
# DocumentRoot /somewhere/public
# <Directory /somewhere/public>
# Relax Apache security settings
# AllowOverride all
# MultiViews must be turned off
# Options -MultiViews
# </Directory>
# </VirtualHost>
Debian Family
- https://wiki.debian.org/Apache/PackagingFor24
- https://wiki.debian.org/Apache/PackagingModules
- Use passenger as test case
- apt-get update; apt-get install libapache2-mod-passenger
- pre/post install files are in
/var/lib/dpkg/info/libapache2-mod-passenger* - TLDR; pre-install enables module and restarts server while prerm disables module.
conf file layout:
# cat /var/lib/dpkg/info/libapache2-mod-passenger.conffiles
/etc/apache2/mods-available/passenger.conf
/etc/apache2/mods-available/passenger.load
# cat /etc/apache2/mods-available/passenger.load
LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so
# cat /etc/apache2/mods-available/passenger.conf
<IfModule mod_passenger.c>
PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
PassengerDefaultRuby /usr/bin/ruby
</IfModule>
Debian 10 -- buster
- 2.4.38 -- https://packages.debian.org/buster/apache2
- see ubuntu 14.04
Debian 9 -- stretch
- 2.4.25 -- https://packages.debian.org/stretch/apache2
- see ubuntu 14.04
Debian 8 -- jessie
- 2.4.10 -- https://packages.debian.org/jessie/apache2
- see ubuntu 14.04
Debian 7 -- wheezy
- 2.2.22 -- https://packages.debian.org/wheezy/apache2
- see ubuntu 12.04
Ubuntu 18.04 -- bionic
- 2.4.29 -- https://packages.ubuntu.com/bionic/apache2
- scripts are identical to ubuntu 14.04
Ubuntu 16.04 -- xenial
- 2.4.18 -- https://packages.ubuntu.com/xenial/apache2
- scripts are identical to ubuntu 14.04
Ubuntu 14.04 -- trusty
- 2.4.7 -- https://packages.ubuntu.com/trusty/apache2
- has 3 scripts,
preinst,prerm,postrm
Ubuntu 12.04 --
- 2.2.22
- Same as Debian 7
- install scripts are in
/var/lib/dpkg/info - on post-install: enable module, and reload server
- on pre-remove: disable module, do not reload server
ubuntu 12.04 mod-passenger sample
Taken from libapache2-mod-passenger.postinst
#!/bin/sh
set -e
if [ "$1" != "configure" ]; then
exit 0
fi
reload_apache()
{
if apache2ctl configtest 2>/dev/null; then
invoke-rc.d apache2 force-reload || true
else
echo "Your apache2 configuration is broken, so we're not restarting it for you."
fi
}
if [ -n "$2" ]; then
# we're upgrading. test if we're enabled, and if so, restart to reload the module.
if [ -e /etc/apache2/mods-enabled/passenger.load ]; then
reload_apache
fi
exit 0
fi
if [ -e /etc/apache2/apache2.conf ]; then
# Enable the module, but hide a2enmod's misleading message about apachectl
# and force-reload the thing ourselves.
a2enmod passenger >/dev/null || true
reload_apache
fi
exit 0
Taken from libapache2-mod-passenger.prerm
#!/bin/sh
set -e
if [ "$1" != "remove" -a "$1" != "purge" ]; then
exit 0
fi;
if [ -e /etc/apache2/apache2.conf ]; then
a2dismod passenger || true
fi
exit 0
ubuntu 12.04 mod-uwsgi sample
Taken from libapache2-mod-uwsgi.postinst
#!/bin/sh
# postinst script for libapache2-mod-uwsgi
#
# see: dh_installdeb(1)
set -e
apache_force_reload() {
if apache2ctl configtest 2>/dev/null; then
invoke-rc.d apache2 force-reload || true
else
echo "Your apache2 configuration is broken, please fix it and restart apache2 manually."
fi
}
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
if [ -z "$2" ]; then # installing package
if [ -e /etc/apache2/apache2.conf ]; then
a2enmod uwsgi >/dev/null || true
apache_force_reload
fi
else # upgrading package
if [ -e /etc/apache2/mods-enabled/uwsgi.load ]; then
apache_force_reload
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
Ubuntu 14.04
postinst
#!/bin/sh
# postinst script for libapache2-mod-uwsgi
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <prerm> `remove'
# * <old-prerm> `upgrade' <new-version>
# * <new-prerm> `failed-upgrade' <old-version>
# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
# * <deconfigured's-prerm> `deconfigure' `in-favour'
# <package-being-installed> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
if [ "$1" = "configure" ] ; then
if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
. /usr/share/apache2/apache2-maintscript-helper
apache2_invoke enmod uwsgi || exit 1
fi
fi
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
exit 0
#!/bin/sh
# prerm script for libapache2-mod-uwsgi
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <prerm> `remove'
# * <old-prerm> `upgrade' <new-version>
# * <new-prerm> `failed-upgrade' <old-version>
# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
# * <deconfigured's-prerm> `deconfigure' `in-favour'
# <package-being-installed> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
if [ "$1" = "purge" ] ; then
if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
. /usr/share/apache2/apache2-maintscript-helper
apache2_invoke dismod uwsgi || exit 1
fi
fi
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
exit 0
ubuntu 14.04 passenger
3 sections
postinst
#!/bin/sh
set -e
# Automatically added by dh_apache2
if true; then
if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
. /usr/share/apache2/apache2-maintscript-helper
for conf in passenger ; do
apache2_invoke enmod $conf || exit $?
done
fi
fi
# End automatically added section
prerm
#!/bin/sh
set -e
# Automatically added by dh_apache2
if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ] ; then
if true; then
if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
. /usr/share/apache2/apache2-maintscript-helper
for conf in passenger ; do
apache2_invoke dismod $conf || exit $?
done
fi
fi
fi
# End automatically added section
postrm
#!/bin/sh
set -e
# Automatically added by dh_apache2
if [ "$1" = "purge" ] ; then
if true; then
if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
. /usr/share/apache2/apache2-maintscript-helper
for conf in passenger ; do
apache2_invoke dismod $conf || exit $?
done
fi
fi
fi
# End automatically added section