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 "stop") { stop(); exit(); }
31 if ($arg eq "status") {
32 if (getstatus() == 1) {
33 my $pid = getprocessid();
34 print "InspIRCd is running (PID: $pid)\n";
37 print "InspIRCd is not running. (Or PID File not found)\n";
41 if ($arg eq "rehash") {
42 if (getstatus() == 1) {
43 my $pid = getprocessid();
44 system("kill -HUP $pid >/dev/null 2>&1");
45 print "InspIRCd rehashed.\n";
48 print "InspIRCd is not running. (Or PID File not found)\n";
54 if (getstatus() == 0) { start(); }
58 if ($arg eq "restart") {
65 if ($arg eq "Cheese-Sandwich") {
66 print "Creating Cheese Sandwich..\n";
72 # If we get here.. bad / no parameters.
74 print "Invalid Argument: $arg\n";
75 print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
79 # Generic Helper Functions.
83 # Check to see its not 'running' already.
84 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
85 # If we are still alive here.. Try starting the IRCd..
86 system("$binpath/$executable");
91 # Check to see its not 'running' already.
92 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
93 # If we are still alive here.. Try starting the IRCd..
94 system("gdb --eval-command=\"handle SIGPIPE pass nostop noprint\" --eval-command=\"run\" --args $binpath/$executable -nofork -debug");
99 if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return 0; }
100 # Get to here, we have something to kill.
101 my $pid = getprocessid();
102 print "Stopping InspIRCd...\n";
103 system("kill -TERM $pid >/dev/null 2>&1");
104 if (getstatus() == 1)
106 print "InspIRCd not dying Quietly -- Forcing Kill\n";
107 system("kill -9 $pid >/dev/null 2>&1");
109 print "InspIRCd Stopped.\n";
112 # GetPidfile Version 2 - Now With Include Support..
113 # I beg for months for include support in insp, then..
114 # when it is added, it comes around and BITES ME IN THE ASS,
115 # because i then have to code support into this script.. Evil.
119 # Before we start, do we have a PID already? (Should never occur)
123 # Are We using a relative path?
124 if ($file !~ /^\//) {
125 # Convert it to a full path..
126 $file = $confpath . $file;
129 # Have we checked this file before?
130 for (my $i = 0; $i < $filesparsed; $i++) {
131 if ($filesparsed[$i] eq $file) {
132 # Already Parsed, Possible recursive loop..
137 # If we get here, Mark as 'Read'
138 $filesparsed[$filesparsed] = $file;
141 open INFILE, "< $file" or die "Unable to Open file $file\n";
142 # Grab entire file contents..
143 my(@lines) = <INFILE>;
147 # Clean up the file, no newlines etc..
149 foreach $i (@lines) {
150 $i =~ s/[^=]+=\s(.*)/\1/;
152 my $tmp = join("",@lines);
154 # Does this file have a pid?
155 if ($tmp =~ /<pid file=\"(\S+)\">/i) {
156 # Set the PID file and return.
161 # If we get here, NO PID FILE! -- Check for includes (Seeing as we will eventually return,
162 # The while (1) is safe.)
164 if ($tmp =~ s/\<include file=\"(.+?)\"\>//i)
166 # Decend into that file, and check for PIDs.. (that sounds like an STD ;/)
169 if ($pidfile ne "") {
174 # End of includes / No includes found.
181 my $pid = getprocessid();
182 if ($pid == 0) { return 0; }
183 $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
184 if ($status == 0) { return 1; }
191 open PIDFILE, "< $pidfile" or return 0;
192 while($i = <PIDFILE>)