~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/echolot

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# pingcntl: echolot control + wrapper
 
4
# Written by admin@arancio.net, peter@palfrader.org
 
5
#
 
6
### BEGIN INIT INFO
 
7
# Provides:          echolot
 
8
# Required-Start:    $local_fs $remote_fs $time
 
9
# Required-Stop:     $local_fs $remote_fs
 
10
# Should-Start:      mail-transport-agent $syslog
 
11
# Should-Stop:       mail-transport-agent $syslog
 
12
# Default-Start:     2 3 4 5
 
13
# Default-Stop:      0 1 6
 
14
# Short-Description: Pinger for anonymous remailers
 
15
# Description:       Echolot is a pinger for anonymous remailers
 
16
#                    such as Mixmaster.  As the name implies it
 
17
#                    regularly sends pings to remailers to
 
18
#                    collect performance statistics on each node.
 
19
### END INIT INFO
 
20
 
 
21
set -e
 
22
 
 
23
VERBOSE=0
 
24
 
 
25
# You probably don't want to mess with stuff below this line
 
26
################################################################
 
27
 
 
28
RUNDIR=/var/run/echolot
 
29
PIDFILE="$RUNDIR/pingd.pid"
 
30
CHECKULIMIT=1
 
31
CHECKUID=1
 
32
USER=echolot
 
33
GROUP=echolot
 
34
DAEMON=/usr/bin/pingd
 
35
DESC="Echolot Ping Daemon"
 
36
NAME="pingd"
 
37
test -f $DAEMON || exit 0
 
38
 
 
39
PATH=/bin:/usr/bin:/sbin:/usr/sbin
 
40
export PATH
 
41
 
 
42
# Reads config file (will override defaults above)
 
43
[ -r /etc/default/echolot ] && . /etc/default/echolot
 
44
 
 
45
if [ ! -d ${RUNDIR} ]; then
 
46
        mkdir "$RUNDIR"
 
47
        chown root:"$GROUP" "$RUNDIR"
 
48
        chmod 02770 "$RUNDIR"
 
49
fi
 
50
 
 
51
wait_for_deaddaemon () {
 
52
        PID=$1
 
53
        sleep 3
 
54
        if test -n "$PID"
 
55
        then
 
56
                if kill -0 $PID 2>/dev/null
 
57
                then
 
58
                        echo -n "Waiting for pid $PID ."
 
59
                        cnt=0
 
60
                        while kill -0 $PID 2>/dev/null
 
61
                        do
 
62
                                cnt=`expr $cnt + 1`
 
63
                                if [ $cnt -gt 30 ]
 
64
                                then
 
65
                                        echo " Failed.. "
 
66
                                        exit 1
 
67
                                fi
 
68
                                sleep 2
 
69
                                echo -n "."
 
70
                        done
 
71
                        rm -f $PIDFILE
 
72
                else
 
73
                        rm -f $PIDFILE
 
74
                fi
 
75
        fi
 
76
}
 
77
 
 
78
 
 
79
# Check for evil ulimits
 
80
if [ "$CHECKULIMIT" -gt "0" ]; then
 
81
        FDs=`ulimit -n`
 
82
        HFDs=`ulimit -H -n`
 
83
        if [ "$FDs" -lt "512" ]; then
 
84
                if [ "$HFDs" -lt "512" ]; then
 
85
                        echo "Hardlimit for open File Descriptors is less than 512." >&2
 
86
                        echo "Please consider raising it." >&2
 
87
                        if [ "$FDs" -lt "$HFDs" ]; then
 
88
                                echo "Raising it to $HFDs" >&2
 
89
                                ulimit -n $HFDs
 
90
                        fi
 
91
                else
 
92
                        if [ "$HFDs" -lt "1024" ]; then
 
93
                                FDs=$HFDs
 
94
                        else
 
95
                                FDs=1024
 
96
                        fi
 
97
                        echo "Softlimit for open File Descriptors is less than 512." >&2
 
98
                        echo "Raising it to $FDs" >&2
 
99
                        ulimit -n $FDs
 
100
                fi
 
101
        fi
 
102
fi
 
103
 
 
104
 
 
105
# set VERBOSE
 
106
if [ $VERBOSE -gt 0 ]; then
 
107
        VERBOSE="--verbose"
 
108
else
 
109
        VERBOSE=""
 
110
fi
 
111
 
 
112
 
 
113
case $1 in
 
114
 
 
115
start)
 
116
        if [ -f $PIDFILE ] ; then
 
117
                PID=`cat $PIDFILE 2>/dev/null` || true
 
118
                if kill -0 $PID 2>/dev/null
 
119
                then
 
120
                        echo "$DESC already running."
 
121
                        exit 0
 
122
                else
 
123
                        echo -n "Removing stale pid file: "
 
124
                        rm -f $PIDFILE
 
125
                        echo "$PIDFILE."
 
126
                fi
 
127
        fi
 
128
        if [ $RUN_ECHOLOT -gt 0 ]; then
 
129
                echo -n "Starting $DESC: "
 
130
                start-stop-daemon \
 
131
                        --start \
 
132
                        --quiet \
 
133
                        --pidfile $PIDFILE \
 
134
                        --chuid $USER:$GROUP \
 
135
                        --exec $DAEMON -- --detach $VERBOSE --process --quiet start
 
136
                echo "$NAME."
 
137
        else
 
138
                echo "Not starting $DESC: disabled in configuration"
 
139
        fi
 
140
        ;;
 
141
 
 
142
stop)
 
143
        echo -n "Stopping $DESC: "
 
144
        PID=`cat $PIDFILE 2>/dev/null` || true
 
145
        start-stop-daemon \
 
146
                --stop \
 
147
                --quiet \
 
148
                --oknodo \
 
149
                --pidfile $PIDFILE \
 
150
                --user $USER
 
151
        wait_for_deaddaemon $PID
 
152
        echo "$NAME."
 
153
        ;;
 
154
 
 
155
reload|force-reload|restart)
 
156
        PID=`cat $PIDFILE 2>/dev/null` || true
 
157
        $0 stop
 
158
        wait_for_deaddaemon $PID
 
159
        $0 start
 
160
        ;;
 
161
process|add|delete|set|setremailercaps|deleteremailercaps|getkeyconf|sendpings|sendchainpings|buildstats|buildkeys|buildthesaurus|buildfromlines|dumpconf|summary|enable|disable)
 
162
        # Check for right User
 
163
        if [ "$CHECKUID" -gt "0" ]; then
 
164
                CUID=`id -u`
 
165
                CUIDNAME=`id -nu`
 
166
                if [ "$CUIDNAME" = "$USER" ]; then
 
167
                        "$DAEMON" "$@"
 
168
                elif [ "$CUID" = "0" ]; then
 
169
                        command="$DAEMON"
 
170
                        while [ "$#" -gt 0 ]; do
 
171
                                command="$command \"$1\""
 
172
                                shift
 
173
                        done
 
174
                        su "$USER" -c "$command"
 
175
                else
 
176
                        echo "You are neither $USER nor root. Aborting." >&2
 
177
                        exit 1;
 
178
                fi
 
179
        fi
 
180
 
 
181
        echo "Running $DESC: $NAME $1..."
 
182
        echo "done."
 
183
        ;;
 
184
*)
 
185
        echo "Usage: $0 (start|stop|reload|force-reload|restart)" >&2
 
186
        echo "       $0 <COMMAND> [parameters]" >&2
 
187
        echo "See the pingd(1) manual page for valid commands" >&2
 
188
        exit 1
 
189
        ;;
 
190
esac
 
191
 
 
192
exit 0
 
193
 
 
194
# vim:set ts=2:
 
195
# vim:set shiftwidth=2: