Re: [users@httpd] Script to upgrade httpd.conf 1.3.x to 2.x?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Jun 8, 2005, at 4:04 PM, Joshua Slive wrote:

Covalent had a script on their website at one point, but I can't find
it now.  Perhaps someone still has a copy?


I'll see if I can get it re-added. In the meantime:


#!/usr/bin/perl
# ====================================================================
# The Covalent Technologies License, Version 1.1
#
# Copyright (c) 2000-2001 Covalent Technologies.  All rights
# reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation andor other materials provided with the
#    distribution.
#
# 3. The end-user documentation included with the redistribution,
#    if any, must include the following acknowledgment:
#       "This product includes software developed by
#        Covalent Technologies (http://www.covalent.net/)."
#    Alternately, this acknowledgment may appear in the software itself,
#    if and wherever such third-party acknowledgments normally appear.
#
# 4. The names "Covalent" and "Covalent Technologies" must
#    not be used to endorse or promote products derived from this
#    software without prior written permission. For written
#    permission, please contact Covalent Technologies.
#
# 5. Products derived from this software may not be called "Covalent",
#    nor may "Covalent" appear in their name, without prior written
#    permission of Covalent Technologies.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED.  IN NO EVENT SHALL COVALENT TECHNOLOGIES OR
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# ====================================================================
#
# This software consists of voluntary contributions made by many
# individuals on behalf of Covalent Technologies.  For more
# information on Covalent Technologies, please see
# <http://www.covalent.net/>.
#
#
# FILE:      convconf.pl
#
# PURPOSE:
#
# Simple script to make an attempt at converting some of the obvious
# syntatical changes between 1.3 and 2.0's configuration files.
# This script will in most cases put the original line in a comment
# prefixed with (1.3), and will put additional comments for some
# new/changed directives prefixed with (2.0).
#

use strict;
use warnings;
use Getopt::Long;

# The filename extention put on backup files
my $bak = ".bak";

sub print_usage {
    print "usage: ".$0." [args...] [files...]\n".
" Pass in a filename to convert from apache 1.3 to 2.0 syntax.\n". " A backup of the file is created \'filename".$bak."\' and\n". " then the given file is processed inline. If no filename is\n". " specified, input is taken from stdin, the converted config\n".
          "    is produced on stdout, and no backup is made.\n".
          "        -v = increase verbosity\n".
          "        -h = print this help screen\n".
          "        -- = stop parsing command arguments\n";
}

my %deprecated_directives; # only print helpful comments once
my $verbose = 0;
my $help = 0;
my $output;

# if no args were specified, default to STDIN
@ARGV = ('-') unless @ARGV;

my $optsuccess = GetOptions('verbose!' => \$verbose,
                'help'     => \$help,
                'bak'      => \$bak);

if (!$optsuccess || $help) {
    print_usage();
    exit 1;
}

print STDERR "Verbosity at level $verbose.\n" if ($verbose > 0);

while ($ARGV = shift @ARGV) {
    if ($ARGV eq "-") {
        print STDERR "Opening STDIN for reading, STDOUT for writing.\n"
            if ($verbose > 1);
        unless (open ARGV, $ARGV) {
            print STDERR "Can't open $ARGV: $!\n";
            next;
        }
print STDERR "Sending default output to STDOUT.\n" if ($verbose > 1);
        select STDOUT;
    }
    elsif (!stat($ARGV)) {
        warn "Skipping input file $ARGV: $!\n";
        next;
    }
    elsif (stat("$ARGV$bak")) {
warn "Backup file $ARGV$bak already exists for $ARGV. Skipping!\n";
        next;
    }
    else {
        print STDERR "Renaming $ARGV to $ARGV$bak\n" if ($verbose > 1);
        unless (rename $ARGV, "$ARGV$bak") {
            print STDERR "Error saving backup file $ARGV$bak: $!\n";
            next;
        }
        print STDERR "Opening $ARGV for output.\n" if ($verbose > 1);
        unless (open OUTPUT, ">$ARGV") {
            print STDERR "Unable to open original file: $!\n";
            next;
        }
print STDERR "Opening $ARGV$bak for input.\n" if ($verbose > 1);
        unless (open ARGV, $ARGV.$bak) {
            print STDERR "Can't open $ARGV: $!\n";
            next
        }
        print STDERR "Sending default output to $ARGV.\n"
            if ($verbose > 1);
        select OUTPUT;
    }
    print STDERR "Done with input/output files.\n" if ($verbose > 1);

# The main loop
while (<ARGV>) {
    if (/^[ \t]*#/i) {
        # Just transcribe any commented lines
        print;
    }
elsif (/(.*)(ServerType|ClearModuleList|AddModule| MinSpareServers|MaxSpareServers)(.*)$/i) {
        # Take deprecated lines, print an error once, and then
        # print all the old lines under comments.
        if (!$deprecated_directives{$2}) {
            $deprecated_directives{$2} = 1;
            print "#\n";
            print "# (Covalent 2.0): $2 has been deprecated.\n";
        }
        print STDERR "Line $.: $2 has been deprecated.\n"
            if ($verbose > 0);
        print "# (1.3): ".$1.$2.$3."\n";
    }
elsif (/(.*)(MinSpareServers|MaxSpareServers|StartServers| MaxClients|MaxRequestsPerChild)(.*)/i) {
        # Remove old settings that are now handled by MPM settings.
        # Even if these don't change, it'll make it obvious to the
        # admins that there are other MPMs to play with.
        if (!$deprecated_directives{"MPM"}) {
            $deprecated_directives{"MPM"} = 1;
            if ($verbose > 0) {
print STDERR "Line $.: Inserting new MPM directives. \n";
                print STDERR <<END;
Note: [Covalent 2.0]: Apache 2.0 can take advantage of different MPMs
    each of which have slightly different runtime directives. See the
    comments inserted into the new config file for details.
END
            }
            print <<END;
#
# (Covalent 2.0): Apache 2.0 can take advantage of different MPMs
#        each of which have slightly different runtime directives.
# The following sections contain the default settings for each MPM.
#
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers         5
MinSpareServers      5
MaxSpareServers     10
MaxClients         150
MaxRequestsPerChild  0
</IfModule>

# threaded MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of server processes allowed to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process # MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule threaded.c>
StartServers         3
MaxClients           8
MinSpareThreads      5
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of server processes allowed to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process # MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker.c>
StartServers         3
MaxClients           8
MinSpareThreads      5
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

# perchild MPM
# NumServers: constant number of server processes
# StartThreads: initial number of worker threads in each server process
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# MaxThreadsPerChild: maximum number of worker threads in each server process
# MaxRequestsPerChild: maximum number of connections per server process
<IfModule perchild.c>
NumServers           5
StartThreads         5
MinSpareThreads      5
MaxSpareThreads     10
MaxThreadsPerChild  20
MaxRequestsPerChild  0
</IfModule>

# Windows MPM
# ThreadsPerChild: constant number of worker threads in the server process # MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_winnt.c>
ThreadsPerChild 250
MaxRequestsPerChild  0
</IfModule>

# (Covalent 2.0): End of new MPM configuration directives.

END
        }
        print "# (1.3): ".$1.$2.$3."\n";
print STDERR "Line $.: $2 has been deprecated.\n" if ($verbose > 0);
    }
    elsif (/(.*)(ScoreBoardFile)(.*)/i) {
        # The scoreboard should only be used in certain situations
        print "#\n";
        print "# (Covalent 2.0): The $2 directive is only used on "
              ."operating systems\n"
              ."#        with insufficient or unsupported "
              ."shared memory mechanisms.\n";
print STDERR "Line $.: Modifying $2 directive.\n" if ($verbose > 0);
        print STDERR "Note: [Covalent 2.0]: The $2 directive is only "
              ."used on operating\n"
              ."    systems with insufficient or unsupported "
              ."shared memory mechanisms.\n" if ($verbose > 0);
        print "<IfModule !mpm_winnt.c>\n";
        print "<IfModule !perchild.c>\n";
        print $1.$2.$3."\n";
        print "</IfModule>\n";
        print "</IfModule>\n";
    }
elsif (/(.*)(LoadModule)([ \t]+[_a-z]+module[ \t]+)libexec\/(.*)/ i) { # If modules used to be in "libexec/", now they are in "modules/"
        if (!$deprecated_directives{$2}) {
            $deprecated_directives{$2} = 1;
            print "#\n";
            print "# (Covalent 2.0): $2 has changed syntax. "
                  ."Modules are\n";
print "# now by default placed in the ServerRoot/ modules\n"; print "# directory (instead of the ServerRoot/ libexec\n";
            print "#        diretcory in 1.3).\n";
            print STDERR "Line $.: $2 has changed syntax, "
                ."attempting to convert.\n" if ($verbose > 0);
        }
        print $1.$2.$3."modules/".$4."\n";
    }
    elsif (/(.*)(Port)(.*)/i) {
# The Port directive has been replaced with the Listen directive.
        if (!$deprecated_directives{$2}) {
            $deprecated_directives{$2} = 1;
            print "#\n";
            print "# (Covalent 2.0): $2 has been deprecated.\n";
print "# It has been replaced with the Listen directive.\n";
            print STDERR "Line $.: $2 has been deprecated.\n"
                if ($verbose > 0);
        }
        print $1."Listen".$3."\n";
    }
    else {
        # This is a good line, just copy it over.
        print;
    }
}
}


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux