CVS: ispman/bin ispman-agent,1.55,1.56
Atif Ghaffar <[email protected]>
| Newsgroups | gmane.comp.isp.ispman.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ispman/ispman/bin
In directory sc8-pr-cvs1:/tmp/cvs-serv11450
Modified Files:
ispman-agent
Log Message:
Removed all the 5.006 stuff.
Replaced the package name with ISPMan instead of ISPMan::Agent
Making sure that 1.0 is in sync.
keeping log_file and pid_file config options but they are looked up using Config instead of ispman->getConf
ISPMan modules are only loaded once a fork is done if ispman-agent is using forked method.
Added log_message routine that uses Log::FileSimple for clean logging.
open_log is now obsolete
Added a test statement where if Config->{'TEST'} is defined then the agent will sleep only 2 x agentFrequency instead of 60 x
Please do not again make drastic changes on HEAD and leave them strayed.
Index: ispman-agent
===================================================================
RCS file: /cvsroot/ispman/ispman/bin/ispman-agent,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -r1.55 -r1.56
*** ispman-agent 31 Jul 2003 15:12:41 -0000 1.55
--- ispman-agent 8 Oct 2003 00:15:12 -0000 1.56
***************
*** 7,33 ****
# example /opt/ispman/bin/ispman-agent nodetach
! $| = 1;
! require 5.006; # perl 5.6.0 or newer required (since we now use our)
!
! package ISPMan::Agent;
! #use strict; # Can't be used till i fix $message=&{$job}; call
! use warnings;
!
BEGIN {
! use FindBin;
! unshift @INC, ($FindBin::Bin , "$FindBin::Bin/../lib", "$FindBin::Bin/../conf");
! use Exporter();
! our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
! $VERSION = 0.01;
! @ISA = qw(Exporter AutoLoader);
! @EXPORT = qw();
! @EXPORT_OK = qw();
! %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
}
- our @EXPORT_OK;
! END { } # module clean-up code here (global destructor)
! use lib qw(%%installDir%%/lib %%installDir%%/conf);
use Data::Dumper;
--- 7,30 ----
# example /opt/ispman/bin/ispman-agent nodetach
! package ISPMan;
BEGIN {
! use FindBin; unshift @INC, ($FindBin::Bin , "$FindBin::Bin/../lib", "$FindBin::Bin/../conf");
}
! $|++;
!
!
!
! #use strict;
! use vars qw(
! $VERSION @ISA @EXPORT @EXPORT_OK $TEST
! $name $hostname $hostnames $ispman $domains $log
! );
! require Exporter;
!
! @ISA = qw(Exporter AutoLoader);
! @EXPORT = qw();
! $VERSION = '0.01';
use Data::Dumper;
***************
*** 36,69 ****
use POSIX qw(tmpnam setsid);
use Sys::Hostname;
- use ISPMan;
- use ISPMan::Utils;
- our $ispman=ISPMan->new();
! my $name = $0 || "ispman-agent";
! my $install_dir = $ispman->getConf("installDir");
- # If you dont have Sys::Hostname, you probably cant run ispman anyway,
- our $hostname = hostname(); # find hostname using Sys::Hostname. -End-Of-Story-
! my @hostnames;
! if ($ispman->getConf("hostnames")) {
! @hostnames = split(/\s*,\s*/, $ispman->getConf("hostnames"));
! }
push @hostnames, $hostname;
! my $pid_file = $ispman->getConf("pid_file") ||
! join "/", ($install_dir, "var/$hostname.ispman-agent.pid");
! # Test to make sure it's not a blank value, if blank assume default
! if ($pid_file eq "") {
! $pid_file = join "/", ($install_dir, "var/$hostname.ispman-agent.pid");
! }
! my $log_file = $ispman->getConf("log_file") ||
! join "/", ($install_dir, "var/$hostname.ispman-agent.log");
! # Test to make sure it's not a blank value, if blank assume default
! if ($log_file eq "") {
! $log_file = join "/", ($install_dir, "var/$hostname.ispman-agent.log");
! }
my ($pid, $job);
--- 33,76 ----
use POSIX qw(tmpnam setsid);
use Sys::Hostname;
+ use Log::FileSimple;
! require "ispman.conf";
!
!
!
! $name="ispman-agent";
! $install_dir=$Config->{'installDir'};
! $TEST=$Config->{'TEST'};
!
!
!
! $hostname=hostname(); # find hostname using Sys::Hostname. -End-Of-Story-
! #If you dont have Sys::Hostname, you probably cant run ispman anyway,
!
!
! ######## Additional hostnames by which this agent will ################
! ######## recognize processes for this host. ################
! ##########################################################################
! # If you want this host to be known by multiple names, define them in ispman.conf on this host.
! # This can happen after a machine upgrade etc or merger etc.
! # for example if the hostname is zhisp01 but your mailhost is/was set to mailhost1
! # and your webhost is/was set to webhost 1
! # you may define mailhost1 and webhost1 as additional hostnames for this machine
! # Example: $Config->{'hostnames'}="mailhost1 webhost1";
! # this scenario should never arise on a clean system
! #
! # Note that the primary hostname of this node will always be whay Sys::Hostname
! # will find
! # Use the script ispman.myhostname to see how ispman-agent will see the hostname
!
! @hostnames=split(/\s*,\s*/, $Config->{'hostnames'});
push @hostnames, $hostname;
! my $pid_file = ($Config->{"pid_file"}=~/\S/)? $Config->{"pid_file"} : join "/", ($Config->{"installDir"}, "var/$hostname.ispman-agent.pid");
! my $log_file = ($Config->{"log_file"}=~/\S/)? $Config->{"log_file"} : join "/", ($Config->{"installDir"}, "var/$hostname.ispman-agent.log");
my ($pid, $job);
***************
*** 96,100 ****
$SIG{TERM} = sub {
unlink $pid_file;
! exit(0)
};
--- 103,107 ----
$SIG{TERM} = sub {
unlink $pid_file;
! exit(0);
};
***************
*** 105,109 ****
}
! if ($ARGV[1] && lc($ARGV[1]) =~ "nodetach") {
open_log();
} else {
--- 112,149 ----
}
!
! sub open_log {
! # obsolete. Do nothing.
!
! }
!
!
! sub init_log {
! $log = new Log::FileSimple(
! name => 'ispman-agent',
! file => $log_file,
! mask => -1,
! autoflush => 1,
! );
! }
!
!
!
! sub daemonize {
! open_log;
! defined(my $pid = fork) or die "Can't fork: $!";
! if ($pid) {
! open ("PID", ">$pid_file");
! print PID "$pid\n";
! close("PID");
! print "Process forked. ";
! print "pid is $pid\nUsing pidfile $pid_file\n";
! setsid or die "Can't start a new session: $!";
! exit 0; # I am the parent
! }
! }
!
!
! if ($ARGV[0] eq "nodetach"){
open_log();
} else {
***************
*** 111,131 ****
}
! ### Get some config options
! my $agentFrequency = $ispman->getConf("agentFrequency") || 1;
! my $ldapBaseDN = $ispman->getConf('ldapBaseDN');
! # gets rid of warnings of using once
! our ($namedConfFile, $namedConfHeaderFile, $namedConfFooterFile);
$namedConfFile = $ispman->getConf('namedConfFile');
$namedConfHeaderFile = $ispman->getConf('namedConfHeaderFile');
$namedConfFooterFile = $ispman->getConf('namedConfFooterFile');
! our $namedDir = join "/", ($ispman->getConf('namedDir'),
! $ispman->getConf('namedIspmanSubDir'));
! our $namedRevDir = join "/", ($namedDir,
! $ispman->getConf('namedRevDir'));
! our $namedPriDir = join "/", ($namedDir,
! $ispman->getConf('namedPriDir'));
! our $namedSecDir = join "/", ($namedDir,
! $ispman->getConf('namedSecDir'));
! ### Clean the options
$namedDir =~ s!//!/!g;
$namedRevDir =~ s!//!/!g;
--- 151,177 ----
}
!
!
!
!
!
!
!
! require ISPMan;
! import ISPMan;
!
! $ispman=ISPMan->new();
!
! $agentFrequency=$ispman->getConf("agentFrequency") || 1;
! $ldapBaseDN=$ispman->getConf('ldapBaseDN');
$namedConfFile = $ispman->getConf('namedConfFile');
$namedConfHeaderFile = $ispman->getConf('namedConfHeaderFile');
$namedConfFooterFile = $ispman->getConf('namedConfFooterFile');
!
! $namedDir=join "/", ($ispman->getConf('namedDir'), $ispman->getConf('namedIspmanSubDir'));
! $namedRevDir=join "/", ($namedDir, $ispman->getConf('namedRevDir'));
! $namedPriDir=join "/", ($namedDir, $ispman->getConf('namedPriDir'));
! $namedSecDir=join "/", ($namedDir, $ispman->getConf('namedSecDir'));
!
$namedDir =~ s!//!/!g;
$namedRevDir =~ s!//!/!g;
***************
*** 136,145 ****
# Jobs are ordered by priority. #1 goes first.
# Default priority is 100.
! my %jobPriorities = ('createMailbox' => 1);
! my $c = 0;
! while (++$c){
! my $processes = $ispman->getProcessesForHost(\@hostnames);
! my ($processHash, $domain, $params, $process);
my $message = "";
--- 182,204 ----
# Jobs are ordered by priority. #1 goes first.
# Default priority is 100.
! %jobPriorities = ('createMailbox' => 1);
!
! sub jobPriority{
! my $job = shift;
! return( defined($jobPriorities{$job}) ?
! $jobPriorities{$job} : 100 );
! }
!
! while (true){
! $ispman=ISPMan->new();
! #if (!$ispman || !$ispman->ldap_ping()){
! # print "Creating new connection";
! # $ispman=ISPMan->new() || (print "Could not create an ISPMan instance" && die);
! #}
!
! $processes=$ispman->getProcessesForHost(\@hostnames);
! my $processHash;
! my ($domain, $params, $process);
my $message = "";
***************
*** 152,163 ****
}
! print Dumper($processHash) if $processHash;
for $domain (keys %$processHash) {
for $job(sort {jobPriority($a) <=> jobPriority($b)} keys %{$processHash->{$domain}}) {
for $params(keys %{$processHash->{$domain}{$job}}) {
! print "Doing $job on $domain with parameters $params\n";
!
! ### FIXME Can't do this in strict subs
$message = &{$job}($domain, $params);
if ($message==1) {
--- 211,221 ----
}
! #Only Dump the process data if debug is more than 2
! print Dumper($processHash) if $processHash && $ispman->{'Config'}{'debug'}>2;
for $domain (keys %$processHash) {
for $job(sort {jobPriority($a) <=> jobPriority($b)} keys %{$processHash->{$domain}}) {
for $params(keys %{$processHash->{$domain}{$job}}) {
! log_message("Doing $job on $domain with parameters $params\n");
$message = &{$job}($domain, $params);
if ($message==1) {
***************
*** 169,221 ****
}
}
- sleep (60 * $agentFrequency);
- }
- ### STARTING SUBS ###
! sub open_log {
! chdir '/' or die "Can't chdir to /: $!";
! open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
! open STDOUT, ">> $log_file " or die "Can't write to $log_file: $!";
! open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
! }
! sub daemonize {
! open_log();
! defined(my $pid = fork) or die "Can't fork: $!";
! if ($pid) {
! open ("PID", ">$pid_file");
! print PID "$pid\n";
! close("PID");
! print "Process forked. ";
! print "pid is $pid\nUsing pidfile $pid_file\n";
! setsid or die "Can't start a new session: $!";
! exit(0); # I am the parent
! }
}
- sub jobPriority {
- my $job = shift;
- return (defined($jobPriorities{$job}) ?
- $jobPriorities{$job} : 100 );
}
- sub AUTOLOAD {
- my ($AUTOLOAD) = shift;
- my $error = "";
- $error .= "Function $AUTOLOAD is missing. Called by ";
- $error .= join " ", caller;
- return $error;
- }
- sub DESTROY {
- close("STDERR");
- }
-
- ### START PROCESSES SUBS ###
sub modifyDomain {
my $domain = shift;
! print "Modifying $domain\n";
my $module = "$install_dir/lib/dns.lib";
--- 227,247 ----
}
}
! if ($TEST){
! log_message("Sleeping for " ,2 * $agentFrequency, " seconds");
! sleep (2 * $agentFrequency);
! } else {
! sleep (60 * $agentFrequency);
}
}
sub modifyDomain {
my $domain = shift;
! log_message( "Modifying $domain\n" );
my $module = "$install_dir/lib/dns.lib";
***************
*** 267,271 ****
my $module = "$install_dir/lib/create_home_directory.lib";
do $module;
!
my $user_info = $ispman->getUserInfo($user);
&create_home_directory_handler($user_info->{'homeDirectory'}, $user_info->{'uidNumber'}, $user_info->{'gidNumber'});
--- 293,297 ----
my $module = "$install_dir/lib/create_home_directory.lib";
do $module;
!
my $user_info = $ispman->getUserInfo($user);
&create_home_directory_handler($user_info->{'homeDirectory'}, $user_info->{'uidNumber'}, $user_info->{'gidNumber'});
***************
*** 319,323 ****
sub makeCanonicalMaps {
my ($domain, $params) = @_;
! my ($home_directory, $owner, $group) = split(",", $params);
my $module = "$install_dir/lib/smtp.lib";
--- 345,350 ----
sub makeCanonicalMaps {
my ($domain, $params) = @_;
! # Atif. 2003-10-07: Where did this come from?
! # my ($home_directory, $owner, $group) = split(",", $params);
my $module = "$install_dir/lib/smtp.lib";
***************
*** 439,443 ****
return 1;
}
-
sub NotifyUsers {
my ($domain, $params) = @_;
--- 466,469 ----
***************
*** 450,453 ****
--- 476,500 ----
}
+
+
+ sub AUTOLOAD {
+ my $error="";
+ $error.= "Function $AUTOLOAD is missing. Called by ";
+ $error.= join " ", caller;
+ return $error;
+ }
+
+ sub log_message {
+ $message=join " " , @_;
+ unless ( $log && ref($log) eq "Log::FileSimple"){
+ init_log();
+ }
+ $log->log( message => $message);
+ }
+
+
+ sub DESTROY {
+ close("STDERR");
+ }
__END__
***************
*** 467,470 ****
--- 514,528 ----
ispman-agent stop
+ to start in foreground
+ ispman-agent nodetach
+ This is useful if you are running ispman-agent under daemontool's supervisor
+ Highly recommended
+
+ to force restart after a crash
+ ispman-agent forcerestart
+ This will remove the existing PID file and start ispman-agent instance.
+
+
+
=head1 DESCRIPTION
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf