File: //scripts.20110531.215904.25158/update_apachectl
#!/usr/bin/perl
# cpanel - update_apachectl Copyright(c) 2010 cPanel, Inc.
# All Rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use strict;
use Cpanel::Usage ();
my $apachectl_file = '/usr/local/apache/bin/apachectl';
Cpanel::Usage::wrap_options( \@ARGV, \&usage, { 'file' => \$apachectl_file } );
if ( !-e $apachectl_file ) {
print "$apachectl_file missing.\n";
exit 1;
}
if ( open my $apachectl_fh, '+<', $apachectl_file ) {
local $/ = undef;
my $apachectl = readline($apachectl_fh);
if ( $apachectl =~ /^PORT=/m ) {
print "$apachectl_file is already updated.\n";
close $apachectl_fh;
exit 0;
}
unless ( $apachectl =~ /^STATUSURL=/m ) {
print "Could not find STATUSURL in $apachectl_file.\n";
exit 1;
}
my $new_statusurl = <<'EO_STATUSURL';
PORT="$(grep 'apache_port=' /var/cpanel/cpanel.config 2>/dev/null | sed -e 's/.*=\([.0-9]*:\)\{0,1\}//;' -e 's/[^0-9]*//g' 2>/dev/null)"
STATUSURL="http://localhost:${PORT:-80}/whm-server-status"
EO_STATUSURL
$apachectl =~ s/^STATUSURL=.*?$/$new_statusurl/m;
seek( $apachectl_fh, 0, 0 );
print $apachectl_fh $apachectl;
truncate( $apachectl_fh, tell($apachectl_fh) );
close $apachectl_fh;
print "Updated.\n";
exit 0;
}
else {
print "Unable to open $apachectl_file ready/write.\n";
exit 1;
}
sub usage {
print <<EO_USAGE;
update_apachectl [options]
This script updates apachectl to retrieve status information from
nonstandard ports as configured in WHM Tweak Settings
Options:
--help Brief help message
--file Location of the apachectl file (defaults to /usr/local/apache/bin/apachectl)
EO_USAGE
exit 0;
}