summaryrefslogtreecommitdiff
path: root/.inspircd.inc
diff options
context:
space:
mode:
authorfrostycoolslug <frostycoolslug@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-05 21:17:33 +0000
committerfrostycoolslug <frostycoolslug@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-05 21:17:33 +0000
commitc2dd34ae043d06781cd59bd56fbbdcd4d4df04b9 (patch)
treef7dc83d8ce326f6ee5135bca57494699b1f6b85e /.inspircd.inc
parent5cce62f7d799f073ea6ca1793328c08c2df7c3ff (diff)
Added ./inspircd (start|stop|restart|rehash|status|cron|Cheese-Sandwich) (Happy luigiman?)
Made a slightly nicer method for .Makefile.inc Updated ./configure to reflect the above changes. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@983 e03df62e-2008-0410-955e-edbf42e46eb7
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;
+}