]> git.donarmstrong.com Git - infobot.git/blob - infobot
more bloot refs
[infobot.git] / infobot
1 #!/usr/bin/perl
2
3 # infobot
4 # copyright kevin lenzo (c) 1997-1999
5 # copyright david sobon (c) 1999-infinity
6 # Copyright (c) 2001-2008 Tim Riker <Tim@Rikers.org>
7
8 use strict;
9 use vars qw($bot_base_dir $bot_src_dir $bot_misc_dir $bot_state_dir
10             $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir
11             $bot_pid $memusage %param
12 );
13
14 BEGIN {
15     if (@ARGV and -f $ARGV[0]) {
16         # source passed config to allow $bot_*_dir to be set.
17         do $ARGV[0];
18     }
19
20     # set any $bot_*_dir var's that aren't already set
21     $bot_base_dir       ||= '.';
22     $bot_config_dir     ||= 'files/';
23     $bot_data_dir       ||= 'files/';
24     $bot_state_dir      ||= 'files/';
25     $bot_run_dir        ||= '.';
26     $bot_src_dir        ||= "$bot_base_dir/src";
27     $bot_log_dir        ||= "$bot_base_dir/log";
28     $bot_misc_dir       ||= "$bot_base_dir/files";
29
30     $bot_pid            = $$;
31
32     require "$bot_src_dir/logger.pl";
33     require "$bot_src_dir/core.pl";
34     require "$bot_src_dir/modules.pl";
35
36     # load the configuration (params) file.
37     &setupConfig();
38
39     &showProc();        # to get the first value.
40     &status("Initial memory usage: $memusage kB");
41     &loadCoreModules();
42     &loadDBModules();
43     &loadFactoidsModules();
44     &loadIRCModules();
45
46     &status("Memory usage after loading modules: $memusage kB");
47 }
48
49 # prevent duplicate processes of the same bot
50 &duperuncheck();
51
52 # initialize everything
53 &startup();     # first time initialization.
54 &setup();
55
56 if (!&IsParam("Interface") or $param{'Interface'} =~ /IRC/) {
57     # launch the irc event loop
58     &ircloop();
59 } else {
60     &cliloop();
61 }
62
63 exit 0;  # just so you don't look farther down in this file :)
64
65 # --- support routines
66
67 # FIXME: add arguments, basically '-h' and '--help', heh.
68
69 # added by the xk
70 sub duperuncheck {
71     my $pid     = $$;
72     my $file    = $file{PID};
73
74     if ( -f $file) {
75         open(PIDFILE,$file) or die "error: cannot open $file.";
76         my $thispid = <PIDFILE> || "NULL\n";
77         close PIDFILE;
78         chop $thispid;
79
80         if ($thispid =~ /^\D$/) {
81             &staus("warning: pidfile is invalid; wiping out.");
82         } else {
83             if ( -d "/proc/$thispid/") {
84                 &ERROR("bot is already running from this directory.");
85                 &ERROR("if this is incorrect, erase '*.pid'.");
86                 &ERROR("verify with 'ps -axu | grep $thispid'.");
87                 exit 1;
88             } else {
89                 &status("warning: stale $file found; wiping.");
90             }
91         }
92     }
93
94     open(PIDFILE,">$file") or die "error: cannot write to $file.";
95     print PIDFILE "$pid\n";
96     close PIDFILE;
97
98     return 0;
99 }
100
101 1;
102
103 # vim:ts=4:sw=4:expandtab:tw=80