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 my $basepath = "@BASE_DIR@";
19 my $confpath = "@CONFIG_DIR@/";
20 my $binpath = "@BINARY_DIR@";
21 my $libpath = "@LIBRARY_DIR@";
22 my $executable = "@EXECUTABLE@";
23 my $version = "@VERSION@";
26 # Lets see what they want to do.. Set the variable (Cause i'm a lazy coder)
28 getpidfile($confpath."inspircd.conf");
30 if ($arg eq "start") { start(); exit(); }
31 if ($arg eq "debug") { debug(); exit(); }
32 if ($arg eq "screendebug") { screendebug(); exit() }
33 if ($arg eq "valdebug") { valdebug(); exit(); }
34 if ($arg eq "screenvaldebug") { screenvaldebug(); exit(); }
35 if ($arg eq "stop") { stop(); exit(); }
36 if ($arg eq "status") {
37 if (getstatus() == 1) {
38 my $pid = getprocessid();
39 print "InspIRCd is running (PID: $pid)\n";
42 print "InspIRCd is not running. (Or PID File not found)\n";
46 if ($arg eq "rehash") {
47 if (getstatus() == 1) {
48 my $pid = getprocessid();
49 system("kill -HUP $pid >/dev/null 2>&1");
50 print "InspIRCd rehashed.\n";
53 print "InspIRCd is not running. (Or PID File not found)\n";
59 if (getstatus() == 0) { start(); }
63 if ($arg eq "version") {
64 print "InspIRCd version: $version\n";
68 if ($arg eq "restart") {
70 unlink($pidfile) if (-e $pidfile);
76 if ($arg eq "Cheese-Sandwich") {
77 print "Creating Cheese Sandwich..\n";
83 # If we get here.. bad / no parameters.
85 print "Invalid Argument: $arg\n";
86 print "Usage: inspircd (start|stop|restart|rehash|status|cron|version)\n";
90 # Generic Helper Functions.
94 # Check to see its not 'running' already.
95 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
96 # If we are still alive here.. Try starting the IRCd..
97 print "$binpath/$executable doesn't exist\n" and return 0 unless(-e "$binpath/$executable");
99 system("$binpath/$executable");
104 # Check to see its not 'running' already.
105 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
107 print "$binpath/$executable doesn't exist\n" and return 0 unless(-e "$binpath/$executable");
112 # If we are still alive here.. Try starting the IRCd..
113 system("gdb --command=$basepath/.gdbargs --args $binpath/$executable -nofork -debug -nolog");
118 # Check to see its not 'running' already.
119 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
121 print "$binpath/$executable doesn't exist\n" and return 0 unless(-e "$binpath/$executable");
127 # If we are still alive here.. Try starting the IRCd..
128 print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the gdb output and get a backtrace.\n";
129 print "Once you're inside the screen session press ^C + d to re-detach from the session\n";
130 system("screen -m -d gdb --command=$basepath/.gdbargs --args $binpath/$executable -nofork -debug -nolog");
135 # Check to see its not 'running' already.
136 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
138 print "$binpath/$executable doesn't exist\n" and return 0 unless(-e "$binpath/$executable");
140 # Check we have valgrind and gdb
144 # If we are still alive here.. Try starting the IRCd..
145 # May want to do something with these args at some point: --suppressions=.inspircd.sup --gen-suppressions=yes
146 # Could be useful when we want to stop it complaining about things we're sure aren't issues.
147 system("valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10 $binpath/$executable -nofork -debug -nolog");
152 # Check to see its not 'running' already.
153 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
155 print "$binpath/$executable doesn't exist\n" and return 0 unless(-e "$binpath/$executable");
162 # If we are still alive here.. Try starting the IRCd..
163 print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the valgrind and gdb output and get a backtrace.\n";
164 print "Once you're inside the screen session press ^C + d to re-detach from the session\n";
165 system("screen -m -d valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10 $binpath/$executable -nofork -debug -nolog");
169 if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return 0; }
170 # Get to here, we have something to kill.
171 my $pid = getprocessid();
172 print "Stopping InspIRCd...\n";
173 system("kill -TERM $pid >/dev/null 2>&1");
174 if (getstatus() == 1)
176 print "InspIRCd not dying Quietly -- Forcing Kill\n";
177 system("kill -9 $pid >/dev/null 2>&1");
179 print "InspIRCd Stopped.\n";
182 # GetPidfile Version 2 - Now With Include Support..
183 # I beg for months for include support in insp, then..
184 # when it is added, it comes around and BITES ME IN THE ASS,
185 # because i then have to code support into this script.. Evil.
189 # Before we start, do we have a PID already? (Should never occur)
193 # Are We using a relative path?
194 if ($file !~ /^\//) {
195 # Convert it to a full path..
196 $file = $confpath . $file;
199 # Have we checked this file before?
200 for (my $i = 0; $i < $filesparsed; $i++) {
201 if ($filesparsed[$i] eq $file) {
202 # Already Parsed, Possible recursive loop..
207 # If we get here, Mark as 'Read'
208 $filesparsed[$filesparsed] = $file;
211 open INFILE, "< $file" or die "Unable to Open file $file\n";
212 # Grab entire file contents..
213 my(@lines) = <INFILE>;
217 # Clean up the file, no newlines etc..
219 foreach $i (@lines) {
220 $i =~ s/[^=]+=\s(.*)/\1/;
222 my $tmp = join("",@lines);
224 # Does this file have a pid?
225 if ($tmp =~ /<pid file=\"(\S+)\">/i) {
226 # Set the PID file and return.
231 # If we get here, NO PID FILE! -- Check for includes (Seeing as we will eventually return,
232 # The while (1) is safe.)
234 if ($tmp =~ s/\<include file=\"(.+?)\"\>//i)
236 # Decend into that file, and check for PIDs.. (that sounds like an STD ;/)
239 if ($pidfile ne "") {
244 # End of includes / No includes found.
245 return $confpath . "inspircd.pid";
251 my $pid = getprocessid();
252 if ($pid == 0) { return 0; }
253 $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
254 if ($status == 0) { return 1; }
261 open PIDFILE, "< $pidfile" or return 0;
262 while($i = <PIDFILE>)
272 unless(`valgrind --version`)
274 print "Couldn't start valgrind: $!\n";
281 unless(`gdb --version`)
283 print "Couldn't start gdb: $!\n";
290 unless(`screen --version`)
292 print "Couldn't start screen: $!\n";