]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - .inspircd.inc
Added LD_LIBRARY_PATH hacks/kludges to the .inspircd.inc file to make it find libmysq...
[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@/inspircd";
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 "stop") { stop(); exit(); }
29 if ($arg eq "status") {
30         if (getstatus() == 1) { 
31                 my $pid = getprocessid();
32                 print "InspIRCd is running (PID: $pid)\n";
33                 exit();
34         } else {
35                 print "InspIRCd is not running. (Or PID File not found)\n";
36                 exit();
37         }
38 }
39 if ($arg eq "rehash") {
40         if (getstatus() == 1) {
41                 my $pid = getprocessid();
42                 system("kill -HUP $pid >/dev/null 2>&1");
43                 print "InspIRCd rehashed.\n";
44                 exit();
45         } else {
46                 print "InspIRCd is not running. (Or PID File not found)\n";
47                 exit();
48         }
49 }
50
51 if ($arg eq "cron") {
52         if (getstatus() == 0) { start(); }
53         exit();
54 }
55
56 if ($arg eq "restart") {
57         stop();
58         start();
59         # kthxbye();
60         exit();
61 }
62
63 if ($arg eq "Cheese-Sandwich") {
64         print "Creating Cheese Sandwich..\n";
65         print "Done.\n";
66         exit();
67 }
68
69 ###
70 # If we get here.. bad / no parameters.
71 ###
72 print "Invalid Argument: $arg\n";
73 print "Usage: inspircd (start|stop|restart|rehash|status|cron)\n";
74 exit();
75
76 ###
77 # Generic Helper Functions.
78 ###
79
80 sub start {
81         # Check to see its not 'running' already.
82         if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; }
83         # If we are still alive here.. Try starting the IRCd..
84         system($binpath);
85         sleep 1;
86         if (getstatus() == 0) {
87                 print "InspIRCd Seemingly not started, Log follows:\n";
88                 system("tail ircd.log");
89         } else {
90                 # We're good!
91                 return 1;
92         }
93 }
94
95 sub stop {
96         if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)"; return 0; }
97         # Get to here, we have something to kill.
98         my $pid = getprocessid();
99         print "Stopping InspIRCd...\n";
100         system("kill -TERM $pid >/dev/null 2>&1");
101         sleep 2;
102         if (getstatus() == 1)
103         {
104                 print "InspIRCd not dying Quietly -- Forcing Kill\n";
105                 system("kill -9 $pid >/dev/null 2>&1");
106         }
107         print "InspIRCd Stopped.\n";
108 }
109
110
111 sub getpidfile {
112         open INFILE, "<  $conffile" or die "Couldn't open $conffile";
113         my(@lines) = <INFILE>;
114         close INFILE;
115         chomp(@lines);
116
117         foreach $i (@lines) {
118             $i =~ s/[^=]+=\s(.*)/\1/;
119         }
120
121         my $tmp = join("",@lines);
122         $tmp =~ /<pid file=\"(\S+)\">/i;
123
124         $pidfile = $1;
125 }
126
127 sub getstatus {
128         my $pid = getprocessid();
129         if ($pid == 0) { return 0; }
130         $status = system("kill -0 $pid >/dev/null 2>&1") / 256;
131         if ($status == 0) { return 1; }
132         else { return 0; }
133 }
134
135
136 sub getprocessid {
137         my $pid;
138         open PIDFILE, "< $pidfile" or return 0;
139         while($i = <PIDFILE>)
140         {
141                 $pid = $i;
142         }
143         close PIDFILE;
144         return $pid;
145 }