dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way (possibly using HTML::Template) to pass httpd.conf to httpd as a stream instead of a file? I know I can wrap the httpd command with a build command, but I'm wondering if you can pass a stream instead of a filename ...

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: dynamic httpd.conf
by borisz (Canon) on Mar 01, 2004 at 17:00 UTC
    You can dynamicly rewrite your httpd.conf from PerlSections. Assuming you use mod_perl. See perldoc Apache::PerlSections
    Boris
Re: dynamic httpd.conf
by Fletch (Bishop) on Mar 01, 2004 at 16:50 UTC

    Not HTML::Template, but if you use mod_perl you can use <Perl></Perl> sections (and other things) to dynamically configure Apache.

Re: dynamic httpd.conf
by Abigail-II (Bishop) on Mar 01, 2004 at 16:12 UTC
    You could replace httpd.conf with a named pipe.

    Abigail

Re: dynamic httpd.conf
by matija (Priest) on Mar 01, 2004 at 16:27 UTC
    I don't think so. The apache man page says:
    -f config Execute the commands in the file config on startup. If config does not begin with a /, then it is taken to be a path relative to the ServerRoot. The default is conf/httpd.conf

    So even if you started it as httpd -f -, it would only try to open a file called /(serverroot)/-.

    You could replace httpd.conf with a named pipe, but you would have to be very carefull: if the process tried to re-read it's config (for instance, if it received a kill -HUP, and you weren't ready for that, apache would hang waiting for input...

Re: dynamic httpd.conf
by waswas-fng (Curate) on Mar 01, 2004 at 16:36 UTC
    dragonchild, what are you trying to do? For instance I have created a setup here that is managed by a perl script that generates the httpd.conf file from a database. The process runs a few times a day grabs the info from the DB and generates a httpd.conf, then sends the signal to httpd to reread config. There may be a way to do what you want that is a little different from that approach, but I need more info on what the actual goal is.


    -Waswas
      I have four copies of the same application. One is prod, one is test, and two are the developer instances. The httpd.conf is almost exactly the same, save for about 8 values. I was trying to be cute and not have to wrap the httpd command in a process to generate the appropriate httpd.conf in the appropriate place before calling httpd, but it doesn't look like I'll be able to.

      Thanks!

      ------
      We are the carpenters and bricklayers of the Information Age.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        Most people start httpd by running the apachectl command, which is just a shell script. You can edit it or replace it with something that runs some perl code, generates httpd.conf in a temp file, and then passes that with httpd -f.
Re: dynamic httpd.conf
by techy (Scribe) on Mar 01, 2004 at 22:53 UTC
    dragonchild,

    As mentioned previously, with mod_perl you can use <Perl> sections, etc. to do this. If mod_perl is not available, another option is to use environment variables and <IfDefine> sections. You can then set these environment variables from the apachectl, with the -D option. for example:

    HTTPD="/path/to/httpd -f ... -DFOO"

    The FOO can also be set in the apachectl by an environment variable, etc. Then inside the httpd.conf:
    <IfDefine FOO> specific conf for FOO or... Include conf/FOO_conf.conf </IfDefine>

    Other sections could also be added for <IfDefine BAR>, etc. Hope this helps!

    techy