summaryrefslogtreecommitdiff
path: root/src/bin/anoperc.in
blob: 4c89768b93f47727a132a907b962d0c5a4da1f5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh
#
# Configuration script for Services
#
# (C) 2003-2013 Anope Team
# Contact us at team@anope.org
#
# Please read COPYING and README for further details.
#
# Based on the original code of Epona by Lara.
# Based on the original code of Services by Andy Church.
#
#



ANOPEPID="@DATDEST@/services.pid"
ANOPROG="@BINDEST@/services"
LOG="@DATDEST@/logs/"
ARCVERSION="1.2"

isAnopeRunning () {
if [ ! -f $ANOPEPID ] ; then
	echo "Warning: Anope is not currently running"
	exit 1
fi

PID=`cat $ANOPEPID`

if [ ! `ps auxw | grep $ANOPROG | grep $PID | grep -v -c grep` ] ; then
	echo "Warning: Anope is not currently running"
	exit 1
fi
}

if [ ! -f $ANOPROG ] ; then
	echo "Error: $ANOPROG cannot be accessed"
	exit 1
fi


if [ "$UID" = "0" ] ; then
  echo "######################################";
  echo "# Warning: Do NOT run Anope as root! #";
  echo "######################################";
  exit 1
fi

if [ "$1" = "start" ] ; then

if [ -f $ANOPEPID ] ; then
	PID=`cat $ANOPEPID`
	if [ `ps auxw | grep $ANOPROG | grep $PID | grep -v -c grep` = 1 ] ; then
		echo "Warning! Anope is already running"
		exit 1
	fi
fi
	echo "Starting Anope"
	shift
	$ANOPROG $*
	sleep 1
		if [ ! -f $ANOPEPID ] ; then
	        echo "Unfortunately it seems Anope did not start successfully"
                echo "This error has been logged in your Anope Log file"
                echo "Located in "$LOG""
                echo "This may help you diagnose the problem"
                echo "Further help may be available from http://www.anope.org/"
		exit 1
		fi
		PID=`cat $ANOPEPID`
		if [ ! `ps auxw | grep $ANOPROG | grep $PID | grep -v -c grep` ] ; then
		echo "Unfortunately it seems Anope did not start successfully"
		echo "This error has been logged in your Anope Log file"
		echo "Located in "$LOG""
		echo "This may help you diagnose the problem"
		echo "Further help may be available from http://www.anope.org/"
		exit 1
		fi

elif [ "$1" = "stop" ] ; then
	isAnopeRunning
	echo "Terminating Anope"
	kill -15 `cat $ANOPEPID`

elif [ "$1" = "status" ] ; then
	if [ -f $ANOPEPID ] ; then
		PID=`cat $ANOPEPID`
        	if [ `ps auxw | grep $PID | grep -v -c grep` = 1 ] ; then
		        echo "Anope is currently running"
		        exit 1
	        fi
	fi

	echo "Anope is not currently running"

## :/ SIGUSR2 is ignored after the first restart so we stop / start Anope for now ##
elif [ "$1" = "restart" ] ; then
	isAnopeRunning
	echo "Restarting Anope"
	kill -15 `cat $ANOPEPID`
	sleep 1
	shift
	$ANOPROG $*

elif [ "$1" = "rehash" ] ; then
	isAnopeRunning
	echo "Saving Databases and Rehashing Configuration"
	kill -12 `cat $ANOPEPID`

elif [ "$1" = "version" ] ; then
	$ANOPROG -version

elif [ "$1" = "help" ] ; then
	if [ "$2" = "paramlist" ] ; then
		$ANOPROG -help
		else
		echo "AnopeRC is a remote control script for easy"
		echo "controlling of Anope from the command console"
		echo "$0 start          Start Anope"
		echo "	   	       	Additional parameters may be passed"
		echo "	   	       	(e.g. $0 start -nofork)"
		echo "	   	       	For a list type $0 $1 paramlist"
		echo "$0 stop           Shutdown Anope"
		echo "$0 status         Show Anope's Status"
		echo "$0 restart        Restart Anope (Databases will be saved)"
		echo "			Additional parameters may be passed"
		echo "			(e.g. $0 restart -logchan)"
		echo "			For a list type $0 $1 paramlist"
		echo "$0 rehash         Rehash Configuration and Save Databases"
		echo "$0 version        Return Anope Version and Build Information"
		echo "$0 help           Show this help menu"
		echo "If you need further help please check the /docs/"
		echo "folder or make use of our extensive online support at"
		echo "http://www.anope.org/"
	fi
	
else
	echo "Anope Remote Control ($ARCVERSION)"
	echo "Usage: $0 [start|stop|status|restart|rehash|version|help]"
fi