]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - .inspircd.inc
Fixed to always look for the ircd.log within the bin/ dir
[user/henk/code/inspircd.git] / .inspircd.inc
1 #!/usr/bin/perl
2 #       +------------------------------------+
3 #       | Inspire Internet Relay Chat Daemon |
4 #       +------------------------------------+
5 #
6 #  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 #                       E-mail:
8 #                <brain@chatspike.net>
9 #                <Craig@chatspike.net>
10 #
11 # Written by Craig Edwards, Craig McLure, and others.
12 # This program is free but copyrighted software; see
13 #            the file COPYING for details.
14 #
15 #               I HATE PERL.. kthxbye
16 # ---------------------------------------------------
17
18 $ENV{"LD_LIBRARY_PATH"} = $ENV{"LD_LIBRARY_PATH"} . ":/usr/local/lib/mysql:/usr/lib/mysql";
19
20 my $conffile = "@CONFIG_DIR@/inspircd.conf";
21 my $binpath = "@BINARY_DIR@";
22
23 # Lets see what they want to do.. Set the variable (Cause i'm a lazy coder)
24 my $arg = $ARGV[0];
25 getpidfile();
26
27 if ($arg eq "start") { start(); exit(); }
28 if ($arg eq "debug") { debug(); exit(); }
29 if ($arg eq "stop") { stop(); exit(); }
30 if ($arg eq "status") {
31         if (getstatus() == 1) { 
32                 my $pid = getprocessid();
33                 print "InspIRCd is running (PID: $pid)\n";
34                 exit();
35         } else {
36                 print "InspIRCd is not running. (Or PID File not found)\n";
37                 exit();
38         }
39 }
40 if ($arg eq "rehash") {
41         if (getstatus() == 1) {
42                 my $pid = getprocessid();
43                 system("kill -HUP $pid >/dev/null 2>&1");
44                 print "InspIRCd rehashed.\n";
45                 exit();
46         } else {
47                 print "InspIRCd is not running. (Or PID File not found)\n";
48                 exit();
49         }
50 }
51
52 if ($arg eq "cron") {
53         if (getstatus() == 0) { start(); }
54         exit();
55 }
56
57 if ($arg eq "restart") {
58         stop();
59         start();
60         # kthxbye();
61         exit();
62 }
63
64 if ($arg eq "Cheese-Sandwich") {
65         print "Creating Cheese Sandwich..\n";
66         print "Done.\n";
67         exit();
68 }
69
70 ###
71 # If we get here.. bad / no parameters.
72 ###
73 print "Invalid Argument: $arg\n";
74 print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
75 exit();
76
77 ###
78 # Generic Helper Functions.
79 ###
80
81 sub start {
82         # Check to see its not 'running' already.
83         if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
84         # If we are still alive here.. Try starting the IRCd..
85         system("$binpath/inspircd");
86         sleep 1;
87         if (getstatus() == 0) {
88                 print "InspIRCd Seemingly not started, Log follows:\n";
89                 system("tail $binpath/ircd.log");
90         } else {
91                 # We're good!
92                 return 1;
93         }
94 }
95
96 sub debug {
97         # Check to see its not 'running' already.
98         if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
99         # If we are still alive here.. Try starting the IRCd..
100         system("gdb --args $binpath/inspircd -nofork -debug");
101 }
102
103
104 sub stop {
105         if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return 0; }
106         # Get to here, we have something to kill.
107         my $pid = getprocessid();
108         print "Stopping InspIRCd...\n";
109         system("kill -TERM $pid >/dev/null 2>&1");
110         sleep 2;
111         if (getstatus() == 1)
112         {
113                 print "InspIRCd not dying Quietly -- Forcing Kill\n";
114                 system("kill -9 $pid >/dev/null 2>&1");
115         }
116         print "InspIRCd Stopped.\n";
117 }
118
119
120 sub getpidfile {
121         open INFILE, "<  $conffile" or die "Couldn't open $conffile\n";
122         my(@lines) = <INFILE>;
123         close INFILE;
124         chomp(@lines);
125
126         foreach $i (@lines) {
127             $i =~ s/[^=]+=\s(.*)/\1/;
128         }
129
130         my $tmp = join("",@lines);
131         $tmp =~ /<pid file=\"(\S+)\">/i;
132
133         $pidfile = $1;
134 }
135
136 sub getstatus {
137         my $pid = getprocessid();
138         if ($pid == 0) { return 0; }
139         $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
140         if ($status == 0) { return 1; }
141         else { return 0; }
142 }
143
144
145 sub getprocessid {
146         my $pid;
147         open PIDFILE, "< $pidfile" or return 0;
148         while($i = <PIDFILE>)
149         {
150                 $pid = $i;
151         }
152         close PIDFILE;
153         return $pid;
154 }