/[echolot]/trunk/pingd
ViewVC logotype

Contents of /trunk/pingd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 345 - (hide annotations) (download)
Wed Dec 18 17:36:28 2002 UTC (10 years, 6 months ago) by weasel
File size: 19421 byte(s)
Prepare 2.0.6
1 weasel 158 #!/usr/bin/perl -w
2 weasel 1
3 weasel 138 $| = 1;
4    
5 weasel 1 # (c) 2002 Peter Palfrader <peter@palfrader.org>
6 weasel 345 # $Id: pingd,v 1.84 2002/12/18 17:36:28 weasel Exp $
7 weasel 1 #
8    
9 weasel 54 =pod
10    
11     =head1 NAME
12    
13     pingd - echolot ping daemon
14    
15     =head1 SYNOPSIS
16    
17     =over
18    
19     =item B<pingd> B<start>
20    
21     =item B<pingd> B<stop>
22    
23 weasel 88 =item B<pingd> B<process>
24    
25 weasel 75 =item B<pingd> B<add> I<address> [I<address> ...]
26 weasel 54
27 weasel 94 =item B<pingd> B<delete> I<address> [I<address> ...]
28    
29 weasel 75 =item B<pingd> B<set> option=value [option=value..] I<address> [I<address> ...]
30    
31 weasel 103 =item B<pingd> B<setremailercaps> I<capsstring>
32    
33     =item B<pingd> B<deleteremailercaps> I<address>
34    
35 weasel 206 =item B<pingd> B<getkeyconf> [I<address> [I<address> ...]]
36 weasel 94
37 weasel 295 =item B<pingd> B<sendpings> [I<address> [I<address> ...]]
38    
39 weasel 172 =item B<pingd> B<buildstats>
40    
41     =item B<pingd> B<buildkeys>
42    
43     =item B<pingd> B<buildthesaurus>
44    
45 weasel 81 =item B<pingd> B<dumpconf>
46    
47 weasel 54 =back
48    
49     =head1 DESCRIPTION
50    
51 weasel 337 pingd is the heart of echolot. Echolot is a pinger for anonymous remailers.
52 weasel 54
53     A Pinger in the context of anonymous remailers is a program that regularily
54     sends messages through remailers to check their reliability. It then calculates
55     reliability statistics which are used by remailer clients to choose the chain
56     of remailers to use.
57    
58     Additionally it collects configuration parameters and keys of all remailers and
59     offers them in a format readable by remailer clients.
60    
61     When called without parameters pingd schedules tasks like sending pings,
62 weasel 337 processing incoming mail and requesting remailer-xxx data and runs them at
63 weasel 54 configurable intervalls.
64    
65     =head1 COMMANDS
66    
67     =over
68    
69     =item B<start>
70    
71     Start the ping daemon.
72    
73     =item B<stop>
74    
75     Send the running pingd process a SIGTERM.
76    
77 weasel 88 =item B<process>
78    
79     Sends a HUP signal to the daemon which instructs it to process the commands.
80    
81 weasel 337 For other effects of sending the HUP Signal see the SIGNALS section below.
82 weasel 88
83 weasel 75 =item B<add> I<address> [I<address> ...]
84 weasel 54
85     Add I<address> to the list of remailers to query for
86     keys and confs.
87    
88 weasel 94 =item B<delete> I<address> [I<address> ...]
89    
90     Delete I<address> from the list of remailers to query for
91 weasel 128 keys and confs. Delete all statistics and keys for that remailer.
92 weasel 94
93 weasel 75 =item B<set> option=value [option=value..] I<address> [I<address> ...]
94    
95     Possible options and values:
96    
97     =over
98    
99     =item B<showit=>{B<on>,B<off>}
100    
101     Set B<showit> (show remailer in mlist, rlist etc.) for remailer I<address> to
102     either B<on> or B<off>.
103    
104     =item B<pingit=>{B<on>,B<off>}
105    
106     Set B<pingit> (send out pings to that remailer) for remailer I<address> to
107     either B<on> or B<off>.
108    
109     =item B<fetch=>{B<on>,B<off>}
110    
111     Set B<fetch> (fetch remailer-key and remailer-conf) for remailer I<address> to
112     either B<on> or B<off>.
113    
114     =back
115    
116 weasel 103 =item B<setremailercaps> I<capsstring>
117    
118     Some remailers (Mixmaster V2 - currently lcs and passthru2) don't return a
119     useable remailer-conf message. For such remailers you need to set it manually.
120    
121     For instance:
122    
123     ./pingd setremailercaps '$remailer{"passthru2"} = "<mixer@immd1.informatik.uni-erlangen.de> mix middle";'
124     ./pingd setremailercaps '$remailer{"lcs"} = "<mix@anon.lcs.mit.edu> mix klen1000";'
125    
126     =item B<deleteremailercaps> I<address>
127    
128     Delete remailer-conf data for I<address>. The config data will be reset from
129     the next valid remailer-conf reply by the remailer.
130    
131 weasel 206 =item B<getkeyconf> [I<address> [I<address> ...]]
132 weasel 94
133     Send a command to immediatly request keys and configuration from remailers.
134 weasel 304 If no addresses are given requests will be sent to all remailers.
135 weasel 94
136 weasel 295 =item B<sendpings> [I<address> [I<address> ...]]
137    
138     Send a command to immediatly send pings to the given remailers.
139 weasel 304 If no addresses are given requests will be sent to all remailers.
140 weasel 295
141 weasel 172 =item B<buildstats>
142    
143     Send a command to immediatly rebuild stats.
144    
145     =item B<buildkeys>
146    
147     Send a command to immediatly rebuild the keyrings.
148    
149     =item B<buildthesaurus>
150    
151     Send a command to immediatly rebuild the Thesaurus.
152    
153 weasel 81 =item B<dumpconf>
154    
155     Dumps the current configuration to standard output.
156    
157 weasel 103 =back
158    
159 weasel 54 =head1 OPTIONS
160    
161 weasel 81 =over
162 weasel 54
163 weasel 221 =item B<--basedir>
164 weasel 81
165 weasel 337 The home directory to which everything else is relative. See the BASE
166 weasel 221 DIRECTORY section below.
167    
168     =item B<--verbose>
169    
170 weasel 81 Verbose mode. Causes B<pingd> to print debugging messages about its progress.
171    
172 weasel 245 =item B<--quiet>
173    
174 weasel 337 Quiet mode. Be even quieter than normal.
175 weasel 245
176 weasel 221 =item B<--help>
177 weasel 81
178 weasel 337 Print a short help message and exit sucessfully.
179 weasel 81
180 weasel 221 =item B<--version>
181 weasel 117
182     Print version number and exit sucessfully.
183    
184 weasel 221 =item B<--nohup>
185 weasel 88
186 weasel 128 Usefull only with the B<add>, B<set>, B<setremailercaps>,
187 weasel 295 B<deleteremailercaps>, B<getkeyconf>, B<sendpings>, B<buildstats>,
188     B<buildkeys>, or B<buildthesaurus> command.
189 weasel 88
190 weasel 94 Don't send a HUP signal to the daemon which instructs it to process the
191     commands after adding the command to the task list.
192 weasel 88
193 weasel 337 By default such a signal is sent.
194 weasel 94
195 weasel 221 =item B<--process>
196 weasel 127
197 weasel 128 Usefull only with the B<start> command.
198 weasel 127
199     Read and process the commands file on startup.
200    
201 weasel 221 =item B<--detach>
202 weasel 88
203 weasel 128 Usefull only with the B<start> command.
204 weasel 88
205     Tell B<pingd> to detach.
206    
207 weasel 54 =back
208    
209 weasel 221 =head1 BASE DIRECTORY
210    
211 weasel 337 The home directory to which everything else is relative.
212 weasel 221
213     Basedir defaults to whatever directory the B<pingd> binary is located. It can
214 weasel 337 be overridden by the B<ECHOLOT_HOME> environment variable which in turn is
215 weasel 221 weaker than the B<--basedir> setting.
216    
217     This directory is then used to locate the configuration file B<pingd.conf> (see
218     FILES below).
219    
220     The B<homedir> setting in B<pingd.conf> finally sets the base directory.
221    
222 weasel 54 =head1 FILES
223    
224 weasel 337 The configuration file is searched in these places in this order:
225 weasel 54
226 weasel 115 =over
227    
228     =item the file pointed to by the B<ECHOLOT_CONF> environment variable
229    
230 weasel 221 =item <basedir>/pingd.conf
231 weasel 115
232     =item $HOME/echolot/pingd.conf
233    
234     =item $HOME/pingd.conf
235    
236     =item $HOME/.pingd.conf
237    
238 weasel 234 =item /etc/echolot/pingd.conf
239    
240 weasel 115 =item /etc/pingd.conf
241    
242     =back
243    
244 weasel 221 =head1 ENVIRONMENT
245    
246     =over
247    
248     =item ECHOLOT_CONF echolot config file (see section FILES)
249    
250     =item ECHOLOT_HOME echolot base directory (see section BASE DIRECTORY)
251    
252     =back
253    
254 weasel 88 =head1 SIGNALS
255    
256 weasel 103 On B<SIGINT>, B<SIGQUIT>, and B<SIGTERM> B<pingd> will schedule a shutdown
257     for as soon as the current actions are finished or immediatly if no actions are
258 weasel 337 currently being processed. It will then write all metadata and pingdata to
259 weasel 88 disk and close all files cleanly before exiting.
260    
261     On B<SIGHUP> <pingd> will execute any pending commands from the commands file
262 weasel 337 (B<commands.txt> by default). It also closes and reopens the file 'output'
263     which is used for stdout and stderr when the daemon is running detached.
264 weasel 88 This can be used if you want to rotate that file.
265    
266 weasel 54 =head1 AUTHOR
267    
268 weasel 103 Peter Palfrader E<lt>peter@palfrader.orgE<gt>
269 weasel 54
270     =head1 BUGS
271    
272 weasel 103 Please report them at E<lt>URL:http://savannah.gnu.org/bugs/?group=echolotE<gt>
273 weasel 54
274     =cut
275    
276 weasel 1 use strict;
277 weasel 221 use FindBin qw{ $Bin };
278     use lib ( $Bin, "$Bin/lib" );
279 weasel 1 use Getopt::Long;
280 weasel 54 use English;
281 weasel 91 use Carp;
282 weasel 1 use Echolot::Config;
283     use Echolot::Globals;
284     use Echolot::Storage::File;
285 weasel 15 use Echolot::Scheduler;
286 weasel 1 use Echolot::Conf;
287     use Echolot::Mailin;
288 weasel 15 use Echolot::Pinger;
289 weasel 34 use Echolot::Stats;
290 weasel 54 use Echolot::Commands;
291 weasel 106 use Echolot::Thesaurus;
292 weasel 223 use POSIX qw(setsid);
293 weasel 1
294     delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
295    
296 weasel 54
297 weasel 345 my $VERSION = '2.0.6';
298 weasel 117
299    
300 weasel 88 my $redirected_stdio = 0;
301 weasel 54
302     sub setSigHandlers() {
303     $SIG{'HUP'} = sub {
304 weasel 115 print "Got SIGHUP. scheduling readcommands\n";
305 weasel 280 Echolot::Globals::get()->{'scheduler'}->schedule('readcommands', 0, time() );
306 weasel 88 if ($redirected_stdio) {
307     close STDOUT;
308     close STDERR;
309     open (STDOUT, ">>output") or die ("Cannot open 'output' as STDOUT\n");
310     open (STDERR, ">&STDOUT") or die ("Cannot dup STDOUT as STDERR\n");
311     };
312 weasel 54 };
313     $SIG{'INT'} = sub {
314     print "Got SIGINT. scheduling exit\n";
315 weasel 280 Echolot::Globals::get()->{'scheduler'}->schedule('exit', 0, time() );
316 weasel 54 };
317     $SIG{'QUIT'} = sub {
318     print "Got SIGQUIT. scheduling exit\n";
319 weasel 280 Echolot::Globals::get()->{'scheduler'}->schedule('exit', 0, time() );
320 weasel 54 };
321     $SIG{'TERM'} = sub {
322     print "Got SIGTERM. scheduling exit\n";
323 weasel 280 Echolot::Globals::get()->{'scheduler'}->schedule('exit', 0, time() );
324 weasel 54 };
325 weasel 34 };
326 weasel 54
327 weasel 88
328    
329 weasel 54 sub commit_prospective_address() {
330     Echolot::Globals::get()->{'storage'}->commit_prospective_address();
331 weasel 34 };
332 weasel 60 sub expire() {
333     Echolot::Globals::get()->{'storage'}->expire();
334     };
335 weasel 308 sub metadata_backup() {
336     Echolot::Globals::get()->{'storage'}->metadata_backup();
337     };
338 weasel 54
339    
340    
341    
342    
343 weasel 94 sub command_adddelete(@) {
344     my $command = shift @_;
345 weasel 88 my @argv = @_;
346 weasel 54
347 weasel 94 die ("command_adddelete requires command\n") unless defined $command;
348 weasel 88 die ("add requires argument <address>\n") unless scalar @argv;
349 weasel 75 my @addresses;
350 weasel 88 for my $address (@argv) {
351 weasel 75 die ("argument <address> is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+._-]+\@[a-zA-Z0-9+.-]+$/ );
352     push @addresses, $address;
353     };
354     for my $address (@addresses) {
355 weasel 94 Echolot::Commands::addCommand("$command $address");
356 weasel 75 };
357 weasel 88 };
358    
359     sub command_set(@) {
360     my @argv = @_;
361    
362 weasel 75 my @settings;
363 weasel 88 while (scalar @argv && $argv[0] =~ /^(showit|pingit|fetch)=(on|off)$/) {
364     push @settings, $argv[0];
365     shift @argv;
366 weasel 75 };
367    
368     my @addresses;
369 weasel 88 for my $address (@argv) {
370 weasel 75 die ("argument $address is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+._-]+\@[a-zA-Z0-9+.-]+$/ );
371     push @addresses, $address;
372     };
373    
374 weasel 88 for my $address (@argv) {
375 weasel 75 for my $setting (@settings) {
376     Echolot::Commands::addCommand("set $address $setting");
377     };
378     };
379 weasel 88 };
380    
381 weasel 103 sub command_setremailercaps(@) {
382     my @argv = @_;
383 weasel 94
384 weasel 103 my @caps;
385     for my $caps (@argv) {
386     my ($remailer_nick, $remailer_address) = ($caps =~ /^\s* \$remailer{"(.*)"} \s*=\s* "<(.*@.*)>.*"; \s*$/ix);
387     die ("caps '$caps' is not a valid remailer caps line\n") unless (defined $remailer_nick && defined $remailer_address);
388     push @caps, {
389     address => $remailer_address,
390     caps => $caps };
391     };
392     for my $caps (@caps) {
393     Echolot::Commands::addCommand("setremailercaps ".$caps->{'address'}." ".$caps->{'caps'});
394     };
395     };
396 weasel 94
397 weasel 103 sub command_deleteremailercaps(@) {
398     my @argv = @_;
399    
400     my @addresses;
401     for my $address (@argv) {
402     die ("argument $address is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+._-]+\@[a-zA-Z0-9+.-]+$/ );
403     push @addresses, $address;
404     };
405    
406 weasel 206 for my $address (@addresses) {
407 weasel 103 Echolot::Commands::addCommand("deleteremailercaps $address");
408     };
409     };
410    
411 weasel 206 sub command_getkeyconf(@) {
412     my @argv = @_;
413 weasel 103
414 weasel 206 my @addresses;
415     for my $address (@argv) {
416     die ("argument $address is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+._-]+\@[a-zA-Z0-9+.-]+$/ );
417     push @addresses, $address;
418     };
419    
420     push @addresses, 'all' unless (scalar @addresses);
421    
422     for my $address (@addresses) {
423     Echolot::Commands::addCommand("getkeyconf $address");
424     };
425     };
426    
427 weasel 295 sub command_sendpings(@) {
428     my @argv = @_;
429 weasel 206
430 weasel 295 my @addresses;
431     for my $address (@argv) {
432     die ("argument $address is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+._-]+\@[a-zA-Z0-9+.-]+$/ );
433     push @addresses, $address;
434     };
435    
436     push @addresses, 'all' unless (scalar @addresses);
437    
438     for my $address (@addresses) {
439     Echolot::Commands::addCommand("sendpings $address");
440     };
441     };
442    
443    
444 weasel 88 sub pid_exists() {
445     return (-e Echolot::Config::get()->{'pidfile'});
446     };
447    
448 weasel 129 sub daemon_run($) {
449     my ($process) = @_;
450    
451 weasel 88 die ("Pidfile '".Echolot::Config::get()->{'pidfile'}."' exists\n")
452     if pid_exists();
453     open (PIDFILE, '>'.Echolot::Config::get()->{'pidfile'}) or
454 weasel 152 confess ("Cannot open pidfile '".Echolot::Config::get()->{'pidfile'}."': $!\n");
455 weasel 88 print PIDFILE "$PROCESS_ID ".Echolot::Globals::get()->{'hostname'}." ".time()."\n";
456     close PIDFILE;
457    
458 weasel 60 Echolot::Globals::initStorage();
459 weasel 54 setSigHandlers();
460 weasel 1
461 weasel 94 Echolot::Globals::get()->{'scheduler'} = new Echolot::Scheduler;
462     my $scheduler = Echolot::Globals::get()->{'scheduler'};
463 weasel 83 $scheduler->add('exit' , -1 , 0, 'exit' );
464     $scheduler->add('readcommands' , -1 , 0, \&Echolot::Commands::processCommands );
465 weasel 1
466 weasel 83 $scheduler->add('processmail' , Echolot::Config::get()->{'processmail'} , 0, \&Echolot::Mailin::process );
467     $scheduler->add('ping' , Echolot::Config::get()->{'pinger_interval'} , 0, \&Echolot::Pinger::send_pings );
468 weasel 107 $scheduler->add('buildstats' , Echolot::Config::get()->{'buildstats'} , 0, \&Echolot::Stats::build_stats );
469     $scheduler->add('buildkeys' , Echolot::Config::get()->{'buildkeys'} , 0, \&Echolot::Stats::build_keys );
470 weasel 172 $scheduler->add('buildthesaurus' , Echolot::Config::get()->{'buildthesaurus'} , 0, \&Echolot::Thesaurus::build_thesaurus );
471 weasel 54
472 weasel 308 $scheduler->add('metadata_backup' , Echolot::Config::get()->{'metadata_backup'} , 0, \&metadata_backup );
473 weasel 83 $scheduler->add('commitprospectives' , Echolot::Config::get()->{'commitprospectives'} , 0, \&commit_prospective_address );
474     $scheduler->add('expire' , Echolot::Config::get()->{'expire'} , 0, \&expire );
475 weasel 206 $scheduler->add('getkeyconf' , Echolot::Config::get()->{'getkeyconf_interval'}, 0, \&Echolot::Conf::send_requests );
476 weasel 121 $scheduler->add('check_resurrection' , Echolot::Config::get()->{'check_resurrection'} , 0, \&Echolot::Conf::check_resurrection );
477 weasel 54
478 weasel 280 Echolot::Globals::get()->{'scheduler'}->schedule('readcommands', 0, time() )
479 weasel 129 if ($process);
480 weasel 127
481 weasel 54 $scheduler->run();
482    
483     Echolot::Globals::get()->{'storage'}->commit();
484     Echolot::Globals::get()->{'storage'}->finish();
485 weasel 88
486     unlink (Echolot::Config::get()->{'pidfile'}) or
487     cluck ("Cannot unlink pidfile ".Echolot::Config::get()->{'pidfile'});
488     };
489    
490     sub send_sig($) {
491     my ($sig) = @_;
492    
493 weasel 107 die ("Pidfile '".Echolot::Config::get()->{'pidfile'}."' does not exist\n")
494 weasel 88 unless pid_exists();
495     open (PIDFILE, '<'.Echolot::Config::get()->{'pidfile'}) or
496 weasel 152 confess ("Cannot open pidfile '".Echolot::Config::get()->{'pidfile'}."': $!\n");
497 weasel 88 my $line = <PIDFILE>;
498     close PIDFILE;
499    
500     my ($pid, $host, $time) = $line =~ /^(\d+) \s+ (\S+) \s+ (\d+) \s* $/x or
501 weasel 152 confess ("Cannot parse pidfile '$line'\n");
502 weasel 88 my $sent = kill $sig, $pid;
503     ($sent == 1) or
504 weasel 152 confess ("Did not send signal $sig to exactly one process but $sent. (pidfile reads $line)\n");
505 weasel 88 };
506    
507     sub daemon_hup() {
508     send_sig(1);
509     };
510    
511     sub daemon_stop() {
512     send_sig(15);
513     };
514    
515 weasel 91 sub make_dirs() {
516     for my $dir (
517     Echolot::Config::get()->{'resultdir'},
518 weasel 106 Echolot::Config::get()->{'thesaurusdir'},
519 weasel 91 ) {
520     if ( ! -d $dir ) {
521 weasel 193 mkdir ($dir, 0755) or
522 weasel 152 confess ("Cannot create directory $dir: $!\n");
523 weasel 91 };
524     };
525 weasel 240 my @dirs = (
526 weasel 246 Echolot::Config::get()->{'private_resultdir'},
527     Echolot::Config::get()->{'gnupghome'},
528     Echolot::Config::get()->{'mixhome'},
529     Echolot::Config::get()->{'tmpdir'},
530     Echolot::Config::get()->{'storage'}->{'File'}->{'basedir'},
531 weasel 91 Echolot::Config::get()->{'mailerrordir'},
532     Echolot::Config::get()->{'mailerrordir'}.'/cur',
533     Echolot::Config::get()->{'mailerrordir'}.'/tmp',
534 weasel 240 Echolot::Config::get()->{'mailerrordir'}.'/new');
535     push @dirs, (
536     Echolot::Config::get()->{'mailin'}.'/cur',
537     Echolot::Config::get()->{'mailin'}.'/tmp',
538     Echolot::Config::get()->{'mailin'}.'/new' )
539     if (-d Echolot::Config::get()->{'mailin'});
540    
541     for my $dir (@dirs) {
542 weasel 91 if ( ! -d $dir ) {
543     mkdir ($dir, 0700) or
544 weasel 152 confess ("Cannot create directory $dir: $!\n");
545 weasel 91 };
546     };
547     };
548 weasel 88
549 weasel 172 sub hup_if_wanted($) {
550     my ($nohup) = @_;
551     if (!$nohup && pid_exists()) {
552     daemon_hup()
553     } else {
554     print "Don't forget to run $PROGRAM_NAME process.\n";
555     };
556     };
557 weasel 91
558    
559    
560    
561    
562    
563    
564    
565    
566    
567 weasel 221 my $params = { basedir => $Bin };
568     $params->{'basedir'} = $ENV{'ECHOLOT_HOME'} if (defined $ENV{'ECHOLOT_HOME'});
569    
570 weasel 88 Getopt::Long::config('bundling');
571     if (!GetOptions (
572 weasel 221 'help' => \$params->{'help'},
573     'version' => \$params->{'version'},
574     'verbose+' => \$params->{'verbose'},
575     'nohup' => \$params->{'nohup'},
576     'detach' => \$params->{'detach'},
577     'process' => \$params->{'process'},
578     'basedir' => \$params->{'basedir'},
579 weasel 245 'quiet' => \$params->{'quiet'},
580 weasel 88 )) {
581     die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [-fwhv]\n");
582     };
583     if ($params->{'help'}) {
584 weasel 115 print ("Usage: $PROGRAM_NAME [options] command\n");
585     print ("See man pingd or perldoc pingd for more info.\n");
586 weasel 117 print ("echolot $VERSION - (c) 2002 Peter Palfrader <peter\@palfrader.org>\n");
587     print ("http://savannah.gnu.org/projects/echolot/\n");
588 weasel 220 print ("\n");
589     print ("Commands:\n");
590     print (" start starts echolot pingd\n");
591     print (" signals pingd to ... \n");
592     print (" stop ... shutdown\n");
593     print (" process ... reopen outfile and process commands\n");
594     print (" add ... add a remailer address\n");
595     print (" delete ... delete a remailer address\n");
596     print (" set ... set remailer options\n");
597     print (" setremailercaps ... set remailer capabilities manually\n");
598     print (" deleteremailercaps ... delete remailer capabilities manually\n");
599     print (" getkeyconf ... request remailer-xxx data immediatly\n");
600 weasel 295 print (" sendpings ... request immediate sending of pings\n");
601 weasel 220 print (" buildstats ... build remailer stats immediatly\n");
602     print (" buildkeys ... buid keyrings immediatly\n");
603     print (" buildthesaurus ... build thesaurus immediatly\n");
604     print (" dumpconf dump configuration\n");
605 weasel 88 exit 0;
606     };
607 weasel 117 if ($params->{'version'}) {
608     print ("echolot $VERSION\n");
609     print ("(c) 2002 Peter Palfrader <peter\@palfrader.org>\n");
610     print ("http://savannah.gnu.org/projects/echolot/\n");
611     exit 0;
612     };
613 weasel 245 $params->{'quiet'} = undef if ($params->{'verbose'});
614 weasel 88
615     my $COMMAND = shift @ARGV;
616     die ("command required\n") unless defined $COMMAND;
617    
618    
619     Echolot::Config::init( $params );
620     chdir( Echolot::Config::get()->{'homedir'} );
621 weasel 187 Echolot::Globals::init( version => $VERSION);
622 weasel 88
623    
624 weasel 94 if ($COMMAND eq 'add' || $COMMAND eq 'delete') {
625     command_adddelete($COMMAND, @ARGV);
626 weasel 172 hup_if_wanted($params->{'nohup'});
627 weasel 88 } elsif ($COMMAND eq 'set') {
628     command_set(@ARGV);
629 weasel 172 hup_if_wanted($params->{'nohup'});
630     } elsif ($COMMAND eq 'deleteremailercaps') {
631     command_deleteremailercaps(@ARGV);
632     hup_if_wanted($params->{'nohup'});
633 weasel 103 } elsif ($COMMAND eq 'setremailercaps') {
634     command_setremailercaps(@ARGV);
635 weasel 172 hup_if_wanted($params->{'nohup'});
636 weasel 94 } elsif ($COMMAND eq 'getkeyconf') {
637 weasel 206 command_getkeyconf(@ARGV);
638 weasel 172 hup_if_wanted($params->{'nohup'});
639 weasel 295 } elsif ($COMMAND eq 'sendpings') {
640     command_sendpings(@ARGV);
641     hup_if_wanted($params->{'nohup'});
642 weasel 172 } elsif ($COMMAND eq 'buildstats') {
643     Echolot::Commands::addCommand("buildstats");
644     hup_if_wanted($params->{'nohup'});
645     } elsif ($COMMAND eq 'buildkeys') {
646     Echolot::Commands::addCommand("buildkeys");
647     hup_if_wanted($params->{'nohup'});
648     } elsif ($COMMAND eq 'buildthesaurus') {
649     Echolot::Commands::addCommand("buildthesaurus");
650     hup_if_wanted($params->{'nohup'});
651 weasel 88 } elsif ($COMMAND eq 'process') {
652     daemon_hup();
653     } elsif ($COMMAND eq 'stop') {
654     daemon_stop();
655     } elsif ($COMMAND eq 'start') {
656 weasel 103 die ("Pidfile '".Echolot::Config::get()->{'pidfile'}."' exists\n")
657     if pid_exists();
658 weasel 91 make_dirs();
659 weasel 88 if ($params->{'detach'}) {
660 weasel 245 print "Detaching.\n" unless ($params->{'quiet'});
661 weasel 223 exit(0) if (fork());
662     POSIX::setsid();
663     exit(0) if (fork());
664     open (STDOUT, ">>output") or die ("Cannot open 'output' as STDOUT\n");
665     open (STDERR, ">&STDOUT") or die ("Cannot dup STDOUT as STDERR\n");
666 weasel 290 open (STDIN , "</dev/null") or die ("Cannot open /dev/null as STDIN\n");
667 weasel 223 $redirected_stdio = 1;
668     print "Startup at ".scalar localtime().".\n";
669     daemon_run( $params->{'process'} );
670     print "done at ".scalar localtime().".\n";
671 weasel 88 } else {
672 weasel 129 daemon_run( $params->{'process'} );
673 weasel 88 };
674 weasel 81 } elsif ($COMMAND eq 'dumpconf') {
675     Echolot::Config::dump();
676 weasel 75 } elsif ($COMMAND eq 'convert') {
677     Echolot::Globals::initStorage();
678     setSigHandlers();
679    
680     Echolot::Globals::get()->{'storage'}->convert();
681    
682     Echolot::Globals::get()->{'storage'}->commit();
683     Echolot::Globals::get()->{'storage'}->finish();
684 weasel 54 } else {
685     die ("Command $COMMAND unknown");
686     };
687    
688 weasel 34 exit 0;
689 weasel 1
690     # vim: set ts=4 shiftwidth=4:

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5