Initial commit
[clearscm.git] / clearadm / clearagent.pl
1 #!/usr/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: clearagent.pl,v $
6
7 Daemon process to run commands on current host in response to requests from 
8 other hosts.
9
10 =head1 VERSION
11
12 =over
13
14 =item Author
15
16 Andrew DeFaria <Andrew@ClearSCM.com>
17
18 =item Revision
19
20 $Revision: 1.11 $
21
22 =item Created:
23
24 Mon Dec 13 09:13:27 EST 2010
25
26 =item Modified:
27
28 $Date: 2011/02/02 18:43:53 $
29
30 =back
31
32 =head1 SYNOPSIS
33
34  Usage clearagent.pl: [-u|sage] [-ve|rbose] [-deb|ug]
35
36  Where:
37    -u|sage:         Displays usage
38  
39    -ve|rbose:       Be verbose
40    -de|bug:         Output debug messages
41    
42    -da|emon:        Run in daemon mode (Default)
43    -m|ultithreaded: Multithread requests (Default)
44    -p|idfile:       File to be created with the pid written to it (Default: 
45                     clearagent.pid). Note: pidfile is only written if -daemon
46                     is specified.
47    
48 =head1 DESCRIPTION
49
50 This script normally runs as a daemon and accepts requests from other hosts to
51 execute commands locally and send back the results.
52
53 =cut
54
55 use strict;
56 use warnings;
57
58 use Getopt::Long;
59 use FindBin;
60
61 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
62
63 use Clearadm;
64 use Clearexec;
65 use Display;
66 use Utils;
67
68 my $VERSION  = '$Revision: 1.11 $';
69   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
70   
71 my $pidfile = "$Clearexec::CLEAROPTS{CLEAREXEC_RUNDIR}/$FindBin::Script.pid";
72
73 # Augment PATH with $Clearadm::CLEAROPTS{CLEARADM_BASE}
74 $ENV{PATH} .= ":$Clearadm::CLEAROPTS{CLEARADM_BASE}";
75
76 my $clearexec;
77
78 # Main
79 my $multithreaded = $Clearexec::CLEAROPTS{CLEAREXEC_MULTITHREADED};
80 my $daemon        = 1;
81
82 GetOptions (
83   'usage'           => sub { Usage },
84   'verbose'         => sub { set_verbose },
85   'debug'           => sub { set_debug },
86   'daemon!'         => \$daemon,
87   'multithreaded!'  => \$multithreaded,
88   'pidfile=s'       => \$pidfile,
89 ) or Usage "Invalid parameter";
90
91 Usage 'Extraneous options: ' . join ' ', @ARGV
92   if @ARGV;
93
94 $clearexec = Clearexec->new;
95
96 $clearexec->setMultithreaded ($multithreaded);
97
98 my $logfile = "$Clearexec::CLEAROPTS{CLEAREXEC_LOGDIR}/$FindBin::Script.log";
99
100 EnterDaemonMode $logfile, $logfile, $pidfile
101   if $daemon;
102   
103 display "$FindBin::Script V$VERSION started at " . localtime;
104
105 $clearexec->startServer;
106
107 verbose "Server running";
108
109 =pod
110
111 =head1 CONFIGURATION AND ENVIRONMENT
112
113 DEBUG: If set then $debug is set to this level.
114
115 VERBOSE: If set then $verbose is set to this level.
116
117 TRACE: If set then $trace is set to this level.
118
119 =head1 DEPENDENCIES
120
121 =head2 Perl Modules
122
123 L<FindBin>
124
125 L<Getopt::Long|Getopt::Long>
126
127 =head2 ClearSCM Perl Modules
128
129 =begin man 
130
131  Clearexec
132  Display
133  Utils
134
135 =end man
136
137 =begin html
138
139 <blockquote>
140 <a href="http://clearscm.com/php/cvs_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
141 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a><br>
142 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Utils.pm">Utils</a><br>
143 </blockquote>
144
145 =end html
146
147 =head1 BUGS AND LIMITATIONS
148
149 There are no known bugs in this script
150
151 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
152
153 =head1 LICENSE AND COPYRIGHT
154
155 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
156
157 =cut