Service units for web applications

Stephen Gallagher sgallagh at redhat.com
Tue Feb 25 19:55:11 UTC 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

So, I have an interesting problem to solve. I have a package that
installs a web application[1] that is run automatically with
httpd.service. The package can be deployed for one or more "sites" on
the system (which may be different apache virtual hosts or just
different paths on the same virtual host).

On version upgrades, there is a helper script that needs to be run for
each "site" of this package on the system to make sure that its
database is updated with the latest schema changes.

Originally, this helper script would have to be run manually for each
site after the package was upgraded (and if you forgot, the
application might not function correctly until you did so).

I worked with upstream and added a new feature that allows updating
all sites on the current system from a single command (getting the
list of installed sites from a data file in a known location). I added
this script to the %post of the RPM package so it would be run
automatically on package upgrade.

One problem with this approach is that it will force the database
upgrade for all sites on the system, regardless of whether the httpd
service is running (or currently serving that site), which could lead
to unexpected behavior. The other issue with this approach is that it
doesn't necessarily play nice with OSTree, since %post only gets
executed on the OSTree host and not on the clients.

I'd much rather be able to add the database upgrade script to a
per-site service unit, so that it would only be invoked as an
ExecStartPre command. This way, it would only be invoked if the
service was actually being launched on the system.

There are actually two pieces to this that I'd like to see (and
hopefully have someone tell me are already possible):

 1. The ability to add new ExecStartPre commands to the httpd service
    when installing new sites.
 2. The ability to enable and disable specific apache sites from
    systemctl. Basically, I'd like to have a symlink added or removed
    from /etc/httpd/conf.d based on whether httpd-mysite.service was
    enabled or disabled.

The ultimate goal here would be for me to be able to install a
reviewboard-sitename.conf file to e.g. /etc/systemd/httpd/ and have it
symlinked into /etc/httpd.conf.d when the service was enabled. This
service file could then be PartOf=httpd.service and run ExecStartPre
to invoke the upgrade script.

So, am I on track here, and if so: how can I do this?


[1] The package is Review Board, a Django application.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlMM9R8ACgkQeiVVYja6o6NWLwCeM54Uc0gJKPFsprmvbwKoYQ0G
2nYAn0vSLoeHDlIWwCYeotXPYydiQ+7H
=W5Y9
-----END PGP SIGNATURE-----


More information about the devel mailing list