summaryrefslogtreecommitdiff
path: root/.inspircd.inc
diff options
context:
space:
mode:
Diffstat (limited to '.inspircd.inc')
-rw-r--r--.inspircd.inc135
1 files changed, 135 insertions, 0 deletions
diff --git a/.inspircd.inc b/.inspircd.inc
new file mode 100644
index 000000000..a3032f676
--- /dev/null
+++ b/.inspircd.inc
@@ -0,0 +1,135 @@
+#!/usr/bin/perl
+# +------------------------------------+
+# | Inspire Internet Relay Chat Daemon |
+# +------------------------------------+
+#
+# Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+# E-mail:
+# <brain@chatspike.net>
+# <Craig@chatspike.net>
+#
+# Written by Craig Edwards, Craig McLure, and others.
+# This program is free but copyrighted software; see
+# the file COPYING for details.
+#
+# I HATE PERL.. kthxbye
+# ---------------------------------------------------
+
+my $conffile = "@CONFIG_DIR@/inspircd.conf";
+my $binpath = "@BINARY_DIR@/inspircd";
+
+# Lets see what they want to do.. Set the variable (Cause i'm a lazy coder)
+my $arg = $ARGV[0];
+getpidfile();
+
+if ($arg eq "start") { start(); exit(); }
+if ($arg eq "stop") { stop(); exit(); }
+if ($arg eq "status") {
+ if (getstatus() == 1) {
+ my $pid = getprocessid();
+ print "InspIRCd is running (PID: $pid)\n";
+ exit();
+ } else {
+ print "InspIRCd is not running. (Or PID File not found)\n";
+ exit();
+ }
+}
+if ($arg eq "rehash") {
+ if (getstatus() == 1) {
+ my $pid = getprocessid();
+ system("kill -HUP $pid >/dev/null 2>&1");
+ print "InspIRCd rehashed.\n";
+ exit();
+ } else {
+ print "InspIRCd is not running. (Or PID File not found)\n";
+ exit();
+ }
+}
+
+if ($arg eq "cron") {
+ if (getstatus() == 0) { start(); exit(); }
+}
+
+if ($arg eq "restart") {
+ stop();
+ start();
+ # kthxbye();
+ exit();
+}
+
+if ($arg eq "Cheese-Sandwich") {
+ print "Creating Cheese Sandwich..\n";
+ print "Done.\n";
+ exit();
+}
+
+###
+# If we get here.. bad / no parameters.
+###
+print "Invalid Argument: $arg\n";
+print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
+exit();
+
+###
+# Generic Helper Functions.
+###
+
+sub start {
+ # Check to see its not 'running' already.
+ if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
+ # If we are still alive here.. Try starting the IRCd..
+ system($binpath);
+ sleep 1;
+ if (getstatus() == 0) {
+ print "InspIRCd Seemingly not started, Log follows:\n";
+ system("tail ircd.log");
+ } else {
+ # We're good!
+ return 1;
+ }
+}
+
+sub stop {
+ if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)"; return 0; }
+ # Get to here, we have something to kill.
+ my $pid = getprocessid();
+ system("kill -TERM $pid >/dev/null 2>&1");
+ print "InspIRCd Stopped.\n";
+}
+
+
+sub getpidfile {
+ open INFILE, "< $conffile" or die "Couldn't open $conffile";
+ my(@lines) = <INFILE>;
+ close INFILE;
+ chomp(@lines);
+
+ foreach $i (@lines) {
+ $i =~ s/[^=]+=\s(.*)/\1/;
+ }
+
+ my $tmp = join("",@lines);
+ $tmp =~ /<pid file=\"(\S+)\">/i;
+
+ $pidfile = $1;
+}
+
+sub getstatus {
+ my $pid = getprocessid();
+ if ($pid == 0) { return 0; }
+ $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
+ if ($status == 0) { return 1; }
+ else { return 0; }
+}
+
+
+sub getprocessid {
+ my $pid;
+ open PIDFILE, "< $pidfile" or die "Cannot open PID";
+ while($i = <PIDFILE>)
+ {
+ $pid = $i;
+ }
+ close PIDFILE;
+ return $pid;
+}