2 # +------------------------------------+
3 # | Inspire Internet Relay Chat Daemon |
4 # +------------------------------------+
6 # Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
8 # <brain@chatspike.net>
9 # <Craig@chatspike.net>
11 # Written by Craig Edwards, Craig McLure, and others.
12 # This program is free but copyrighted software; see
13 # the file COPYING for details.
15 # I HATE PERL.. kthxbye
16 # ---------------------------------------------------
18 $ENV{"LD_LIBRARY_PATH"} = $ENV{"LD_LIBRARY_PATH"} . ":/usr/local/lib/mysql:/usr/lib/mysql";
20 my $conffile = "@CONFIG_DIR@/inspircd.conf";
21 my $binpath = "@BINARY_DIR@/inspircd";
23 # Lets see what they want to do.. Set the variable (Cause i'm a lazy coder)
27 if ($arg eq "start") { start(); exit(); }
28 if ($arg eq "debug") { debug(); exit(); }
29 if ($arg eq "stop") { stop(); exit(); }
30 if ($arg eq "status") {
31 if (getstatus() == 1) {
32 my $pid = getprocessid();
33 print "InspIRCd is running (PID: $pid)\n";
36 print "InspIRCd is not running. (Or PID File not found)\n";
40 if ($arg eq "rehash") {
41 if (getstatus() == 1) {
42 my $pid = getprocessid();
43 system("kill -HUP $pid >/dev/null 2>&1");
44 print "InspIRCd rehashed.\n";
47 print "InspIRCd is not running. (Or PID File not found)\n";
53 if (getstatus() == 0) { start(); }
57 if ($arg eq "restart") {
64 if ($arg eq "Cheese-Sandwich") {
65 print "Creating Cheese Sandwich..\n";
71 # If we get here.. bad / no parameters.
73 print "Invalid Argument: $arg\n";
74 print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
78 # Generic Helper Functions.
82 # Check to see its not 'running' already.
83 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
84 # If we are still alive here.. Try starting the IRCd..
87 if (getstatus() == 0) {
88 print "InspIRCd Seemingly not started, Log follows:\n";
89 system("tail ircd.log");
97 # Check to see its not 'running' already.
98 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
99 # If we are still alive here.. Try starting the IRCd..
100 system("gdb --args $binpath -nofork -debug");
102 if (getstatus() == 0) {
103 print "InspIRCd Seemingly not started, Log follows:\n";
104 system("tail ircd.log");
113 if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)"; return 0; }
114 # Get to here, we have something to kill.
115 my $pid = getprocessid();
116 print "Stopping InspIRCd...\n";
117 system("kill -TERM $pid >/dev/null 2>&1");
119 if (getstatus() == 1)
121 print "InspIRCd not dying Quietly -- Forcing Kill\n";
122 system("kill -9 $pid >/dev/null 2>&1");
124 print "InspIRCd Stopped.\n";
129 open INFILE, "< $conffile" or die "Couldn't open $conffile";
130 my(@lines) = <INFILE>;
134 foreach $i (@lines) {
135 $i =~ s/[^=]+=\s(.*)/\1/;
138 my $tmp = join("",@lines);
139 $tmp =~ /<pid file=\"(\S+)\">/i;
145 my $pid = getprocessid();
146 if ($pid == 0) { return 0; }
147 $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
148 if ($status == 0) { return 1; }
155 open PIDFILE, "< $pidfile" or return 0;
156 while($i = <PIDFILE>)