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 $confpath = "@CONFIG_DIR@/";
19 my $binpath = "@BINARY_DIR@";
20 my $libpath = "@LIBRARY_DIR@";
21 my $executable = "@EXECUTABLE@";
24 # Lets see what they want to do.. Set the variable (Cause i'm a lazy coder)
26 getpidfile($confpath."inspircd.conf");
28 if ($arg eq "start") { start(); exit(); }
29 if ($arg eq "debug") { debug(); exit(); }
30 if ($arg eq "screendebug") { screendebug(); exit() }
31 if ($arg eq "valdebug") { valdebug(); exit(); }
32 if ($arg eq "screenvaldebug") { screenvaldebug(); exit(); }
33 if ($arg eq "stop") { stop(); exit(); }
34 if ($arg eq "status") {
35 if (getstatus() == 1) {
36 my $pid = getprocessid();
37 print "InspIRCd is running (PID: $pid)\n";
40 print "InspIRCd is not running. (Or PID File not found)\n";
44 if ($arg eq "rehash") {
45 if (getstatus() == 1) {
46 my $pid = getprocessid();
47 system("kill -HUP $pid >/dev/null 2>&1");
48 print "InspIRCd rehashed.\n";
51 print "InspIRCd is not running. (Or PID File not found)\n";
57 if (getstatus() == 0) { start(); }
61 if ($arg eq "restart") {
63 unlink($pidfile) if (-e $pidfile);
69 if ($arg eq "Cheese-Sandwich") {
70 print "Creating Cheese Sandwich..\n";
76 # If we get here.. bad / no parameters.
78 print "Invalid Argument: $arg\n";
79 print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
83 # Generic Helper Functions.
87 # Check to see its not 'running' already.
88 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
89 # If we are still alive here.. Try starting the IRCd..
90 system("$binpath/$executable");
95 # Check to see its not 'running' already.
96 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
101 # If we are still alive here.. Try starting the IRCd..
102 system("gdb --command=.gdbargs --args $binpath/$executable -nofork -debug -nolog");
107 # Check to see its not 'running' already.
108 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
114 # If we are still alive here.. Try starting the IRCd..
115 print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the gdb output and get a backtrace.\n";
116 print "Once you're inside the screen session press ^C + d to re-detach from the session\n";
117 system("screen -m -d gdb --command=.gdbargs --args $binpath/$executable -nofork -debug -nolog");
122 # Check to see its not 'running' already.
123 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
125 # Check we have valgrind and gdb
129 # If we are still alive here.. Try starting the IRCd..
130 # May want to do something with these args at some point: --suppressions=.inspircd.sup --gen-suppressions=yes
131 # Could be useful when we want to stop it complaining about things we're sure aren't issues.
132 system("valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10 $binpath/$executable -nofork -debug -nolog");
137 # Check to see its not 'running' already.
138 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
145 # If we are still alive here.. Try starting the IRCd..
146 print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the valgrind and gdb output and get a backtrace.\n";
147 print "Once you're inside the screen session press ^C + d to re-detach from the session\n";
148 system("screen -m -d valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10 $binpath/$executable -nofork -debug -nolog");
152 if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return 0; }
153 # Get to here, we have something to kill.
154 my $pid = getprocessid();
155 print "Stopping InspIRCd...\n";
156 system("kill -TERM $pid >/dev/null 2>&1");
157 if (getstatus() == 1)
159 print "InspIRCd not dying Quietly -- Forcing Kill\n";
160 system("kill -9 $pid >/dev/null 2>&1");
162 print "InspIRCd Stopped.\n";
165 # GetPidfile Version 2 - Now With Include Support..
166 # I beg for months for include support in insp, then..
167 # when it is added, it comes around and BITES ME IN THE ASS,
168 # because i then have to code support into this script.. Evil.
172 # Before we start, do we have a PID already? (Should never occur)
176 # Are We using a relative path?
177 if ($file !~ /^\//) {
178 # Convert it to a full path..
179 $file = $confpath . $file;
182 # Have we checked this file before?
183 for (my $i = 0; $i < $filesparsed; $i++) {
184 if ($filesparsed[$i] eq $file) {
185 # Already Parsed, Possible recursive loop..
190 # If we get here, Mark as 'Read'
191 $filesparsed[$filesparsed] = $file;
194 open INFILE, "< $file" or die "Unable to Open file $file\n";
195 # Grab entire file contents..
196 my(@lines) = <INFILE>;
200 # Clean up the file, no newlines etc..
202 foreach $i (@lines) {
203 $i =~ s/[^=]+=\s(.*)/\1/;
205 my $tmp = join("",@lines);
207 # Does this file have a pid?
208 if ($tmp =~ /<pid file=\"(\S+)\">/i) {
209 # Set the PID file and return.
214 # If we get here, NO PID FILE! -- Check for includes (Seeing as we will eventually return,
215 # The while (1) is safe.)
217 if ($tmp =~ s/\<include file=\"(.+?)\"\>//i)
219 # Decend into that file, and check for PIDs.. (that sounds like an STD ;/)
222 if ($pidfile ne "") {
227 # End of includes / No includes found.
234 my $pid = getprocessid();
235 if ($pid == 0) { return 0; }
236 $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
237 if ($status == 0) { return 1; }
244 open PIDFILE, "< $pidfile" or return 0;
245 while($i = <PIDFILE>)
255 unless(`valgrind --version`)
257 print "Couldn't start valgrind: $!\n";
264 unless(`gdb --version`)
266 print "Couldn't start gdb: $!\n";
273 unless(`screen --version`)
275 print "Couldn't start screen: $!\n";