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