Removed /usr/local from CDPATH
[clearscm.git] / clearadm / clearagent.pl
1 #!/usr/bin/env 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 use Sys::Hostname;
61
62 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
63
64 use Clearadm;
65 use Clearexec;
66 use Display;
67 use Utils;
68
69 my $VERSION  = '$Revision: 1.11 $';
70   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
71   
72 my $pidfile = "$Clearexec::CLEAROPTS{CLEAREXEC_RUNDIR}/$FindBin::Script.pid";
73
74 # Augment PATH with $Clearadm::CLEAROPTS{CLEARADM_BASE}
75 $ENV{PATH} .= ":$Clearadm::CLEAROPTS{CLEARADM_BASE}";
76
77 my $clearexec;
78
79 # Main
80 my $multithreaded = $Clearexec::CLEAROPTS{CLEAREXEC_MULTITHREADED};
81 my $daemon        = 1;
82
83 GetOptions(
84   'usage'           => sub { Usage },
85   'verbose'         => sub { set_verbose },
86   'debug'           => sub { set_debug },
87   'daemon!'         => \$daemon,
88   'multithreaded!'  => \$multithreaded,
89   'pidfile=s'       => \$pidfile,
90 ) or Usage "Invalid parameter";
91
92 Usage 'Extraneous options: ' . join ' ', @ARGV
93   if @ARGV;
94
95 $clearexec = Clearexec->new;
96
97 $clearexec->setMultithreaded($multithreaded);
98
99 my $logfile  = "$Clearexec::CLEAROPTS{CLEAREXEC_LOGDIR}/$FindBin::Script";
100    $logfile =~ s/\.pl$//;
101    $logfile .= '.' . hostname() . '.log';
102
103 EnterDaemonMode $logfile, $logfile, $pidfile if $daemon;
104   
105 display "$FindBin::Script V$VERSION started at " . localtime;
106
107 $clearexec->startServer;
108
109 verbose "Server running";
110
111 =pod
112
113 =head1 CONFIGURATION AND ENVIRONMENT
114
115 DEBUG: If set then $debug is set to this level.
116
117 VERBOSE: If set then $verbose is set to this level.
118
119 TRACE: If set then $trace is set to this level.
120
121 =head1 DEPENDENCIES
122
123 =head2 Perl Modules
124
125 L<FindBin>
126
127 L<Getopt::Long|Getopt::Long>
128
129 =head2 ClearSCM Perl Modules
130
131 =begin man 
132
133  Clearexec
134  Display
135  Utils
136
137 =end man
138
139 =begin html
140
141 <blockquote>
142 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
143 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
144 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
145 </blockquote>
146
147 =end html
148
149 =head1 BUGS AND LIMITATIONS
150
151 There are no known bugs in this script
152
153 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
154
155 =head1 LICENSE AND COPYRIGHT
156
157 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
158
159 =cut