Use httpd -S as a sanity check to make sure the config path is included.
| Project: | Provision |
| Version: | 5.x-0.1-alpha1 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
As discussed before, I think it's a very astute plan to have hm2 generate a virtual host for it's own main hosting site, and append that file onto the virtual host configuration.
Another issue I discovered while finishing up the import code, is that if the sites already exist , and have virtual hosts configured outside of hostmaster 2, we will end up creating duplicate virtual hosts and possibly breaking apache.
I think the only way to fix this properly will involve a command line install script, that can parse the apache configuration, see if the changes have already be made that we want to make, and add the entry / remove any additional virtual hosts that have been defined.
This script would likely need root privileges, and could also be used to set up the server user accounts and the like. To automate the installation.
It need not be written in php, infact, i think a shell script would probably be a safer solution. Hell, it could even be a autoconf/Makefile, if we really wanna go to that level. I'd only consider a makefile because it would be easier to integrate with package management software.
I'd need to do some research into driving install.php from the command line without a single existing drupal site, perhaps by creating a very small / simple bootstrap db dump. I don't know yet.

#1
Well. I realized people must have needed to parse apache config files with php :
Here's a php licensed PEAR class :
http://pear.php.net/package/Config
and i've attached a simple gpl licensed class for php. i found it on phpclasses, which is a terrible site and i won't force other people to sign up for it.
Using proc_open, we can even have the user enter their root password as part of a hosting setup / provision setup script.
This is related to http://drupal.org/node/273295
#4
#5
better title.
#6
I don't think we should parse httpd.conf. It's not that the file format is that complex in itself, it's that there's a lot of corner cases to cover. We will have to work *very* hard to make sure we avoid an error that is basically an operator error (provisionning virtual hosts outside of hostmaster). Once hostmaster is on a server, it should rightly expect to have every domain available to itself.
Of course it should check if it's allowed to host certain domains, e.g. allowing yahoo.com to be hosted on hostmaster is probably a bad idea, but this is a matter of policy and outside the scope of this issue here.
So my opinion is that we can *check* if a hostname is already defined in the apache configuration files in a crude grep-style way, but going further than that is a waste of time.
#7
We could use `httpd -S` to check what hostnames are taken:
VirtualHost configuration:wildcard NameVirtualHosts and _default_ servers:
*:* is a NameVirtualHost
default server marvin.anarcat.ath.cx (/etc/apache2/sites-enabled/000-default:2)
port * namevhost marvin.anarcat.ath.cx (/etc/apache2/sites-enabled/000-default:2)
port * namevhost anarcat.ath.cx (/etc/apache2/sites-enabled/0_anarcat.ath.cx.conf:1)
Syntax OK
The advantage is that this is the actual parsed configuration that's currently active. As a bonus, we check if we screwed up the config by declaring duplicate stuff or whatever.. ;)
#8
This needs to be added to hosting setup, to make sure the server is picking up all the changes we make.
#9
Here's a regular expression to extract this info :
<?phppreg_match_all('+port (\d*)\ namevhost\ ([\w\.]*)\ \((.*):\d+\)$+', $output, $matches);
?>
We have several problems with this however ..
A) its different between different distros. Debian has /usr/sbin/apache2 instead of httpd
B) The binary is unlikely to be in the path of our script user, since sbin is usually only in the root user's path on redhat based systems
C) There are permission issues relating to this, as the script user will need to be able to sudo the binary in most cases.
marking this as postponed for now, until we have a cleaner way to solve this.
#10
a) we should make that customizable per webserver, just like apachectl is
b) we could lookup a few paths in the verification of the webserver (/usr/s?bin/(apache|httpd)2?)
c) same as apachectl again: it (the above + -S) needs to be added to sudo
#11
Actually..
i found out that apachectl and apache2ctl have the same flags.
So we don't have to configure an additional binary.
ALSO, i found :
<?phpnotroot@ubuntu:~$ sudo apache2ctl -V
Server version: Apache/2.2.9 (Ubuntu)
Server built: Sep 19 2008 13:43:21
Servers Module Magic Number: 20051115:15
Server loaded: APR 1.2.12, APR-Util 1.2.12
Compiled using: APR 1.2.12, APR-Util 1.2.12
Architecture: 32-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT=""
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
-D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"
?>
m+-D SERVER_CONFIG_FILE=(.*)?$+'extracts the apache configuration file.#12
So apache.conf is not all: it may Include another file or a directory which then would include Aegir. That's how the INSTALL.txt tells people to setup Aegir anyways, and I think it's proper from a packaging point of view.
Basically, the apache.conf would be a start, then you need to parse each file for Include and recursively parse those to find your final include.