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 $ENV{"LD_LIBRARY_PATH"} = $ENV{"LD_LIBRARY_PATH"} . ":/usr/local/lib/mysql:/usr/lib/mysql:$libpath";
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 "stop") { stop(); exit(); }
33 if ($arg eq "status") {
34 if (getstatus() == 1) {
35 my $pid = getprocessid();
36 print "InspIRCd is running (PID: $pid)\n";
39 print "InspIRCd is not running. (Or PID File not found)\n";
43 if ($arg eq "rehash") {
44 if (getstatus() == 1) {
45 my $pid = getprocessid();
46 system("kill -HUP $pid >/dev/null 2>&1");
47 print "InspIRCd rehashed.\n";
50 print "InspIRCd is not running. (Or PID File not found)\n";
56 if (getstatus() == 0) { start(); }
60 if ($arg eq "restart") {
67 if ($arg eq "Cheese-Sandwich") {
68 print "Creating Cheese Sandwich..\n";
74 # If we get here.. bad / no parameters.
76 print "Invalid Argument: $arg\n";
77 print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
81 # Generic Helper Functions.
85 # Check to see its not 'running' already.
86 if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
87 # If we are still alive here.. Try starting the IRCd..
88 system("$binpath/$executable");
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 system("gdb --args $binpath/$executable -nofork -debug");
102 if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return 0; }
103 # Get to here, we have something to kill.
104 my $pid = getprocessid();
105 print "Stopping InspIRCd...\n";
106 system("kill -TERM $pid >/dev/null 2>&1");
108 if (getstatus() == 1)
110 print "InspIRCd not dying Quietly -- Forcing Kill\n";
111 system("kill -9 $pid >/dev/null 2>&1");
113 print "InspIRCd Stopped.\n";
116 # GetPidfile Version 2 - Now With Include Support..
117 # I beg for months for include support in insp, then..
118 # when it is added, it comes around and BITES ME IN THE ASS,
119 # because i then have to code support into this script.. Evil.
123 # Before we start, do we have a PID already? (Should never occur)
127 # Are We using a relative path?
128 if ($file !~ /^\//) {
129 # Convert it to a full path..
130 $file = $confpath . $file;
133 # Have we checked this file before?
134 for (my $i = 0; $i < $filesparsed; $i++) {
135 if ($filesparsed[$i] eq $file) {
136 # Already Parsed, Possible recursive loop..
141 # If we get here, Mark as 'Read'
142 $filesparsed[$filesparsed] = $file;
145 open INFILE, "< $file" or die "Unable to Open file $file\n";
146 # Grab entire file contents..
147 my(@lines) = <INFILE>;
151 # Clean up the file, no newlines etc..
153 foreach $i (@lines) {
154 $i =~ s/[^=]+=\s(.*)/\1/;
156 my $tmp = join("",@lines);
158 # Does this file have a pid?
159 if ($tmp =~ /<pid file=\"(\S+)\">/i) {
160 # Set the PID file and return.
165 # If we get here, NO PID FILE! -- Check for includes (Seeing as we will eventually return,
166 # The while (1) is safe.)
168 if ($tmp =~ s/\<include file=\"(.+?)\"\>//i)
170 # Decend into that file, and check for PIDs.. (that sounds like an STD ;/)
173 if ($pidfile ne "") {
178 # End of includes / No includes found.
185 my $pid = getprocessid();
186 if ($pid == 0) { return 0; }
187 $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
188 if ($status == 0) { return 1; }
195 open PIDFILE, "< $pidfile" or return 0;
196 while($i = <PIDFILE>)