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") {
68 if ($arg eq "Cheese-Sandwich") {
69 print "Creating Cheese Sandwich..\n";
75 # If we get here.. bad / no parameters.
77 print "Invalid Argument: $arg\n";
78 print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
82 # Generic Helper Functions.
86 # Check to see its not 'running' already.
87 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
88 # If we are still alive here.. Try starting the IRCd..
89 system("$binpath/$executable");
94 # Check to see its not 'running' already.
95 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
100 # If we are still alive here.. Try starting the IRCd..
101 system("gdb --command=.gdbargs --args $binpath/$executable -nofork -debug -nolog");
106 # Check to see its not 'running' already.
107 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
113 # If we are still alive here.. Try starting the IRCd..
114 print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the gdb output and get a backtrace.\n";
115 print "Once you're inside the screen session press ^C + d to re-detach from the session\n";
116 system("screen -m -d gdb --command=.gdbargs --args $binpath/$executable -nofork -debug -nolog");
121 # Check to see its not 'running' already.
122 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
124 # Check we have valgrind and gdb
128 # If we are still alive here.. Try starting the IRCd..
129 # May want to do something with these args at some point: --suppressions=.inspircd.sup --gen-suppressions=yes
130 # Could be useful when we want to stop it complaining about things we're sure aren't issues.
131 system("valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10 $binpath/$executable -nofork -debug -nolog");
136 # Check to see its not 'running' already.
137 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
144 # If we are still alive here.. Try starting the IRCd..
145 print "Starting InspIRCd in `screen`, type `screen -r` when the ircd crashes to view the valgrind and gdb output and get a backtrace.\n";
146 print "Once you're inside the screen session press ^C + d to re-detach from the session\n";
147 system("screen -m -d valgrind -v --tool=memcheck --leak-check=yes --db-attach=yes --num-callers=10 $binpath/$executable -nofork -debug -nolog");
151 if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return 0; }
152 # Get to here, we have something to kill.
153 my $pid = getprocessid();
154 print "Stopping InspIRCd...\n";
155 system("kill -TERM $pid >/dev/null 2>&1");
156 if (getstatus() == 1)
158 print "InspIRCd not dying Quietly -- Forcing Kill\n";
159 system("kill -9 $pid >/dev/null 2>&1");
161 print "InspIRCd Stopped.\n";
164 # GetPidfile Version 2 - Now With Include Support..
165 # I beg for months for include support in insp, then..
166 # when it is added, it comes around and BITES ME IN THE ASS,
167 # because i then have to code support into this script.. Evil.
171 # Before we start, do we have a PID already? (Should never occur)
175 # Are We using a relative path?
176 if ($file !~ /^\//) {
177 # Convert it to a full path..
178 $file = $confpath . $file;
181 # Have we checked this file before?
182 for (my $i = 0; $i < $filesparsed; $i++) {
183 if ($filesparsed[$i] eq $file) {
184 # Already Parsed, Possible recursive loop..
189 # If we get here, Mark as 'Read'
190 $filesparsed[$filesparsed] = $file;
193 open INFILE, "< $file" or die "Unable to Open file $file\n";
194 # Grab entire file contents..
195 my(@lines) = <INFILE>;
199 # Clean up the file, no newlines etc..
201 foreach $i (@lines) {
202 $i =~ s/[^=]+=\s(.*)/\1/;
204 my $tmp = join("",@lines);
206 # Does this file have a pid?
207 if ($tmp =~ /<pid file=\"(\S+)\">/i) {
208 # Set the PID file and return.
213 # If we get here, NO PID FILE! -- Check for includes (Seeing as we will eventually return,
214 # The while (1) is safe.)
216 if ($tmp =~ s/\<include file=\"(.+?)\"\>//i)
218 # Decend into that file, and check for PIDs.. (that sounds like an STD ;/)
221 if ($pidfile ne "") {
226 # End of includes / No includes found.
233 my $pid = getprocessid();
234 if ($pid == 0) { return 0; }
235 $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
236 if ($status == 0) { return 1; }
243 open PIDFILE, "< $pidfile" or return 0;
244 while($i = <PIDFILE>)
254 unless(`valgrind --version`)
256 print "Couldn't start valgrind: $!\n";
263 unless(`gdb --version`)
265 print "Couldn't start gdb: $!\n";
272 unless(`screen --version`)
274 print "Couldn't start screen: $!\n";