3 # infobot -- copyright kevin lenzo (c) 1997-1999
4 # blootbot -- copyright david sobon (c) 1999-infinity
7 use vars qw($bot_base_dir $bot_src_dir $bot_misc_dir $bot_state_dir
8 $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir
9 $bot_pid $memusage %param
13 if (@ARGV and -f $ARGV[0]) {
14 # source passed config to allow $bot_*_dir to be set.
18 # set any $bot_*_dir var's that aren't already set
19 $bot_base_dir ||= '.';
20 $bot_config_dir ||= 'files/';
21 $bot_data_dir ||= 'files/';
22 $bot_state_dir ||= 'files/';
24 $bot_src_dir ||= "$bot_base_dir/src";
25 $bot_log_dir ||= "$bot_base_dir/log";
26 $bot_misc_dir ||= "$bot_base_dir/files";
30 unshift @INC,"$bot_src_dir","$bot_src_dir/Modules";
32 require "$bot_src_dir/logger.pl";
33 require "$bot_src_dir/core.pl";
34 require "$bot_src_dir/modules.pl";
36 # load the configuration (params) file.
39 &showProc(); # to get the first value.
40 &status("Initial memory usage: $memusage kB");
43 &loadFactoidsModules();
46 &status("Memory usage after loading modules: $memusage kB");
49 # prevent duplicate processes of the same bot
52 # initialize everything
53 &startup(); # first time initialization.
56 if (!&IsParam("Interface") or $param{'Interface'} =~ /IRC/) {
57 # launch the irc event loop
63 exit 0; # just so you don't look farther down in this file :)
65 # --- support routines
67 # FIXME: add arguments, basically '-h' and '--help', heh.
72 my $file = $file{PID};
75 open(PIDFILE,$file) or die "error: cannot open $file.";
76 my $thispid = <PIDFILE> || "NULL\n";
80 if ($thispid =~ /^\D$/) {
81 &staus("warning: pidfile is invalid; wiping out.");
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'.");
89 &status("warning: stale $file found; wiping.");
94 open(PIDFILE,">$file") or die "error: cannot write to $file.";
95 print PIDFILE "$pid\n";