summaryrefslogtreecommitdiff
path: root/debian/echolot.init
blob: 0ff289780e09aced0a125fd49257739acd994607 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/sh
#
# pingcntl: echolot control + wrapper
# Written by admin@arancio.net, peter@palfrader.org
#
### BEGIN INIT INFO
# Provides:          echolot
# Required-Start:    $local_fs $remote_fs $time
# Required-Stop:     $local_fs $remote_fs
# Should-Start:      mail-transport-agent $syslog
# Should-Stop:       mail-transport-agent $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Pinger for anonymous remailers
# Description:       Echolot is a pinger for anonymous remailers
#                    such as Mixmaster.  As the name implies it
#                    regularly sends pings to remailers to
#                    collect performance statistics on each node.
### END INIT INFO

set -e

VERBOSE=0

# You probably don't want to mess with stuff below this line
################################################################

PIDFILE=/var/run/echolot/pingd.pid
CHECKULIMIT=1
CHECKUID=1
USER=echolot
GROUP=echolot
DAEMON=/usr/bin/pingd
DESC="Echolot Ping Daemon"
NAME="pingd"
test -f $DAEMON || exit 0

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

# Reads config file (will override defaults above)
[ -r /etc/default/echolot ] && . /etc/default/echolot


wait_for_deaddaemon () {
	PID=$1
	sleep 3
	if test -n "$PID"
	then
		if kill -0 $PID 2>/dev/null
		then
			echo -n "Waiting for pid $PID ."
			cnt=0
			while kill -0 $PID 2>/dev/null
			do
				cnt=`expr $cnt + 1`
				if [ $cnt -gt 30 ]
				then
					echo " Failed.. "
					exit 1
				fi
				sleep 2
				echo -n "."
			done
			rm -f $PIDFILE
		else
			rm -f $PIDFILE
		fi
	fi
}


# Check for evil ulimits
if [ "$CHECKULIMIT" -gt "0" ]; then
	FDs=`ulimit -n`
	HFDs=`ulimit -H -n`
	if [ "$FDs" -lt "512" ]; then
		if [ "$HFDs" -lt "512" ]; then
			echo "Hardlimit for open File Descriptors is less than 512." >&2
			echo "Please consider raising it." >&2
			if [ "$FDs" -lt "$HFDs" ]; then
				echo "Raising it to $HFDs" >&2
				ulimit -n $HFDs
			fi
		else
			if [ "$HFDs" -lt "1024" ]; then
				FDs=$HFDs
			else
				FDs=1024
			fi
			echo "Softlimit for open File Descriptors is less than 512." >&2
			echo "Raising it to $FDs" >&2
			ulimit -n $FDs
		fi
	fi
fi


# set VERBOSE
if [ $VERBOSE -gt 0 ]; then
	VERBOSE="--verbose"
else
	VERBOSE=""
fi


case $1 in

start)
	if [ -f $PIDFILE ] ; then
		PID=`cat $PIDFILE 2>/dev/null` || true
		if kill -0 $PID 2>/dev/null
		then
			echo "$DESC already running."
			exit 0
		else
			echo -n "Removing stale pid file: "
			rm -f $PIDFILE
			echo "$PIDFILE."
		fi
	fi
	if [ $RUN_ECHOLOT -gt 0 ]; then
		echo -n "Starting $DESC: "
		start-stop-daemon \
			--start \
			--quiet \
			--pidfile $PIDFILE \
			--chuid $USER:$GROUP \
			--exec $DAEMON -- --detach $VERBOSE --process --quiet start
		echo "$NAME."
	else
		echo "Not starting $DESC: disabled in configuration"
	fi
	;;

stop)
	echo -n "Stopping $DESC: "
	PID=`cat $PIDFILE 2>/dev/null` || true
	start-stop-daemon \
		--stop \
		--quiet \
		--oknodo \
		--pidfile $PIDFILE \
		--user $USER
	wait_for_deaddaemon $PID
	echo "$NAME."
	;;

reload|force-reload|restart)
	PID=`cat $PIDFILE 2>/dev/null` || true
	$0 stop
	wait_for_deaddaemon $PID
	$0 start
	;;
process|add|delete|set|setremailercaps|deleteremailercaps|getkeyconf|sendpings|sendchainpings|buildstats|buildkeys|buildthesaurus|buildfromlines|dumpconf|summary|enable|disable)
	# Check for right User
	if [ "$CHECKUID" -gt "0" ]; then
		CUID=`id -u`
		CUIDNAME=`id -nu`
		if [ "$CUIDNAME" = "$USER" ]; then
			"$DAEMON" "$@"
		elif [ "$CUID" = "0" ]; then
			command="$DAEMON"
			while [ "$#" -gt 0 ]; do
				command="$command \"$1\""
				shift
			done
			su "$USER" -c "$command"
		else
			echo "You are neither $USER nor root. Aborting." >&2
			exit 1;
		fi
	fi

	echo "Running $DESC: $NAME $1..."
	echo "done."
	;;
*)
	echo "Usage: $0 (start|stop|reload|force-reload|restart)" >&2
	echo "       $0 <COMMAND> [parameters]" >&2
	echo "See the pingd(1) manual page for valid commands" >&2
	exit 1
	;;
esac

exit 0

# vim:set ts=2:
# vim:set shiftwidth=2: