X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Ftemplate%2Finspircd;h=8405c2a6b8fbf6400b1d81227bb3115d40878af1;hb=88bfcabe027216022df7b6f410f0dd862a92128d;hp=1b9f25a866b49731003848d081352816fe579fdd;hpb=dd49cf696c14c1189efa9eca5318b856a804c985;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/template/inspircd b/make/template/inspircd index 1b9f25a86..8405c2a6b 100644 --- a/make/template/inspircd +++ b/make/template/inspircd @@ -1,30 +1,64 @@ +%mode 0750 #!/usr/bin/env perl -# +------------------------------------+ -# | Inspire Internet Relay Chat Daemon | -# +------------------------------------+ + +# +# InspIRCd -- Internet Relay Chat Daemon +# +# Copyright (C) 2009-2010 Daniel De Graaf +# +# This file is part of InspIRCd. InspIRCd is free software: you can +# redistribute it and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. # -# InspIRCd: (C) 2002-2010 InspIRCd Development Team -# See: http://wiki.inspircd.org/Credits +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . # -# This program is free but copyrighted software; see -# the file COPYING for details. + +# InspIRCd Start up the InspIRCd Internet Relay Chat Daemon # -# --------------------------------------------------- +# chkconfig: 2345 55 25 +# description: InspIRCd -- Internet Relay Chat Daemon # +# processname: inspircd + use strict; use POSIX; use Fcntl; +# From http://refspecs.linuxbase.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html +use constant { + STATUS_EXIT_SUCCESS => 0, + STATUS_EXIT_DEAD_WITH_PIDFILE => 1, + STATUS_EXIT_DEAD_WITH_LOCKFILE => 2, + STATUS_EXIT_NOT_RUNNING => 3, + STATUS_EXIT_UNKNOWN => 4, + + GENERIC_EXIT_SUCCESS => 0, + GENERIC_EXIT_UNSPECIFIED => 1, + GENERIC_EXIT_INVALID_ARGUMENTS => 2, + GENERIC_EXIT_UNIMPLEMENTED => 3, + GENERIC_EXIT_INSUFFICIENT_PRIVILEGE => 4, + GENERIC_EXIT_NOT_INSTALLED => 5, + GENERIC_EXIT_NOT_CONFIGURED => 6, + GENERIC_EXIT_NOT_RUNNING => 7 +}; + my $basepath = "@BASE_DIR@"; my $confpath = "@CONFIG_DIR@/"; my $binpath = "@BINARY_DIR@"; my $runpath = "@BASE_DIR@"; +my $datadir = "@DATA_DIR@"; my $valgrindlogpath = "$basepath/valgrindlogs"; -my $executable = "@EXECUTABLE@"; -my $version = "@VERSION@"; +my $executable = "inspircd"; +my $version = "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@+@VERSION_LABEL@"; my $uid = "@UID@"; -if ($< == 0 || $> == 0) { +if (!("--runasroot" ~~ @ARGV) && ($< == 0 || $> == 0)) { if ($uid !~ /^\d+$/) { # Named UID, look it up $uid = getpwnam $uid; @@ -72,12 +106,11 @@ if (!defined($sub)) { print STDERR "Invalid command or none given.\n"; cmd_help(); - exit 1; + exit GENERIC_EXIT_UNIMPLEMENTED; } else { - $sub->(@ARGV); - exit 0; + exit $sub->(@ARGV); # Error code passed through return value } sub cmd_help() @@ -90,7 +123,7 @@ sub cmd_help() $_ =~ s/_/-/g foreach (@cmds, @devs); print STDERR "Usage: ./inspircd (" . join("|", @cmds) . ")\n"; print STDERR "Developer arguments: (" . join("|", @devs) . ")\n"; - exit 0; + exit GENERIC_EXIT_SUCCESS; } sub cmd_status() @@ -98,10 +131,10 @@ sub cmd_status() if (getstatus() == 1) { my $pid = getprocessid(); print "InspIRCd is running (PID: $pid)\n"; - exit(); + exit STATUS_EXIT_SUCCESS; } else { print "InspIRCd is not running. (Or PID File not found)\n"; - exit(); + exit STATUS_EXIT_NOT_RUNNING; } } @@ -111,23 +144,23 @@ sub cmd_rehash() my $pid = getprocessid(); system("kill -HUP $pid >/dev/null 2>&1"); print "InspIRCd rehashed (pid: $pid).\n"; - exit(); + exit GENERIC_EXIT_SUCCESS; } else { print "InspIRCd is not running. (Or PID File not found)\n"; - exit(); + exit GENERIC_EXIT_NOT_RUNNING; } } sub cmd_cron() { if (getstatus() == 0) { goto &cmd_start(); } - exit(); + exit GENERIC_EXIT_UNSPECIFIED; } sub cmd_version() { print "InspIRCd version: $version\n"; - exit(); + exit GENERIC_EXIT_SUCCESS; } sub cmd_restart(@) @@ -141,13 +174,13 @@ sub hid_cheese_sandwich() { print "Creating Cheese Sandwich..\n"; print "Done.\n"; - exit(); + exit GENERIC_EXIT_SUCCESS; } sub cmd_start(@) { # Check to see its not 'running' already. - if (getstatus() == 1) { print "InspIRCd is already running.\n"; return 0; } + if (getstatus() == 1) { print "InspIRCd is already running.\n"; exit GENERIC_EXIT_SUCCESS; } # If we are still alive here.. Try starting the IRCd.. chdir $runpath; print "$binpath/$executable doesn't exist\n" and return 0 unless(-e "$binpath/$executable"); @@ -274,7 +307,7 @@ sub dev_screenvaldebug(@) sub cmd_stop() { - if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return 0; } + if (getstatus() == 0) { print "InspIRCd is not running. (Or PID File not found)\n"; return GENERIC_EXIT_SUCCESS; } # Get to here, we have something to kill. my $pid = getprocessid(); print "Stopping InspIRCd (pid: $pid)...\n"; @@ -284,12 +317,12 @@ sub cmd_stop() sleep 1; if (getstatus() == 0) { print "InspIRCd Stopped.\n"; - return; + return GENERIC_EXIT_SUCCESS; } } print "InspIRCd not dying quietly -- forcing kill\n"; kill KILL => $pid; - return 0; + return GENERIC_EXIT_SUCCESS; } ### @@ -374,13 +407,13 @@ sub getpidfile } # End of includes / No includes found. Using default. - $pidfile = $runpath . "/data/inspircd.pid"; + $pidfile = $datadir . "/inspircd.pid"; } sub getstatus { my $pid = getprocessid(); return 0 if $pid == 0; - return kill 0, $1; + return kill 0, $pid; } @@ -389,7 +422,7 @@ sub getprocessid { open PIDFILE, '<', $pidfile or return 0; while() { - /(\d+)/ and $pid = $1; + /^(\d+)$/ and $pid = $1; } close PIDFILE; return $pid; @@ -400,7 +433,7 @@ sub checkvalgrind unless(`valgrind --version`) { print "Couldn't start valgrind: $!\n"; - exit; + exit GENERIC_EXIT_UNSPECIFIED; } } @@ -409,7 +442,7 @@ sub checkgdb unless(`gdb --version`) { print "Couldn't start gdb: $!\n"; - exit; + exit GENERIC_EXIT_UNSPECIFIED; } } @@ -418,6 +451,6 @@ sub checkscreen unless(`screen --version`) { print "Couldn't start screen: $!\n"; - exit; + exit GENERIC_EXIT_UNSPECIFIED; } }