Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Guidance on updating apache config files

by thanos1983 (Parson)
on Mar 16, 2017 at 22:53 UTC ( [id://1184937] : note . print w/replies, xml ) Need Help??


in reply to Guidance on updating apache config files

Hello nysus,

Have you checked the Apache::ConfigFile module? Seems to be exactly what you want to do.

From the Description of the documentation:

This module parses the Apache httpd.conf, or any compatible config fil +e, and provides methods for you to access the values from the config +file.

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: Guidance on updating apache config files
by davido (Cardinal) on Mar 17, 2017 at 05:32 UTC

    Apache::ConfigFile does seem adequate for parsing, which is usually the hardest part. Its write method is documented in the POD as not working, but it probably wouldn't be too hard to just use a template approach to producing a correct file.

    Now here's some advice that I've learned from a real adventure in debugging: Use proper locking that holds the lock from the time you read until the time you're done writing and have closed the output handle. Keep a copy of the original. Validate the newly written file with apachectl configtest and verify Syntax OK, and roll back to the original using the same sort of vigilance if it fails validation. Anything less can eventually get you a corrupted httpd.conf someday.


    Dave

      Good advice. I didn't consider these things.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re^2: Guidance on updating apache config files
by nysus (Parson) on Mar 17, 2017 at 12:27 UTC

    I have a bit, yes. It's got some quirks to it that I don't like trying to compile in files included by the config files it processes. I'm also looking to something more general purpose that I might be able to adapt to other situations.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks