/[echolot]/trunk/pingd
ViewVC logotype

Contents of /trunk/pingd

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5