source: debian/i2p.init @ a456888

Last change on this file since a456888 was 8397296, checked in by kytv <kytv@…>, 8 years ago

Add 'graceful' / comment out stanza not needed on Ubuntu

  • Property mode set to 100755
File size: 5.7 KB
Line 
1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: i2p i2p-router
5# Required-Start: $remote_fs $syslog $named $network $time
6# Required-Stop: $remote_fs $syslog $named $network
7# Default-Start: 2 3 4 5
8# Default-Stop: 0 1 6
9# Short-Description: start and stop the i2p router
10# Description: i2p is a load-balanced unspoofable packet switching network
11### END INIT INFO
12
13# Check permissions
14if [ "`id -ur`" != '0' ]; then
15   echo 'ERROR: You must be root to start this service.' >&2
16   echo
17   exit 1
18fi
19
20PATH=/sbin:/usr/sbin:/bin:/usr/bin
21DESC="I2P Router"
22NAME="i2p"
23RUN="/var/run/$NAME"
24DAEMON="/usr/sbin/wrapper"
25PIDFILE="$RUN/$NAME.pid"
26JVMPIDFILE="$RUN/routerjvm.pid"
27I2P="/usr/share/i2p"
28I2PTEMP="/tmp/${NAME}-daemon"
29WRAPPERLOG="/var/log/i2p/wrapper.log"
30
31# Don't touch these, edit /etc/default/i2p
32RUN_DAEMON="False"
33NICE=0
34I2PUSER="i2psvc"
35
36I2P_ARGS="/etc/i2p/wrapper.config \
37 wrapper.java.additional.1=-DloggerFilenameOverride=/var/log/i2p/log-router-@.txt \
38 wrapper.java.additional.10=-Dwrapper.logfile=$WRAPPERLOG \
39 wrapper.java.additional.11=-Di2p.dir.pid=$RUN \
40 wrapper.java.additional.12=-Di2p.dir.temp=$I2PTEMP \
41 wrapper.logfile=$WRAPPERLOG \
42 wrapper.pidfile=$PIDFILE \
43 wrapper.java.pidfile=$JVMPIDFILE \
44 wrapper.daemonize=TRUE"
45
46[ -r /lib/lsb/init-functions ] && . /lib/lsb/init-functions
47[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
48
49
50for ENV_FILE in /etc/environment /etc/default/locale; do
51[ -r "$ENV_FILE" ] || continue
52[ -s "$ENV_FILE" ] || continue
53
54 for var in LANG LANGUAGE LC_ALL LC_CTYPE; do
55     value=`egrep "^${var}=" "$ENV_FILE" | tail -n1 | cut -d= -f2`
56     [ -n "$value" ] && eval export $var=$value
57
58# This is commented out for Ubuntu: Ubuntu still creates
59# /etc/environment in the most recent release
60# (currently 'Precise').
61#
62# TODO Add logic to automatically handle this
63#
64# Commented for Ubuntu since PPA packages 0.9-1$DISTRO1.
65# Packages for Debian systems will have this stanza uncommented.
66#
67#     if [ -n "$value" ] && [ "$ENV_FILE" = /etc/environment ]; then
68#         log_warning_msg "/etc/environment has been deprecated for locale information; use /etc/default/locale for $var=$value instead"
69#     fi
70
71 done
72done
73
74# read config file
75[ -r /etc/default/$NAME ] && . /etc/default/$NAME
76
77if [ -z "$RUN_DAEMON" ]; then
78    echo "/etc/default/$NAME is not properly configured. Aborting." >&2
79    exit 1
80fi
81
82case "$RUN_DAEMON" in
83        [NnFf]*)
84                log_action_msg "$DESC daemon disabled in /etc/default/$NAME".
85                exit 0
86                ;;
87esac
88
89# We need the wrapper. If it's not found, abort.
90[ -x $DAEMON ] || exit 1
91
92# Even though this script doesn't call it, check for i2prouter.  If it's not
93# found, it probably means that the package isn't installed anymore.
94[ -x /usr/bin/i2prouter ] || exit 1
95
96do_start()
97{
98    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null 2>&1 \
99        || return 1
100    [ -d $RUN ] || mkdir $RUN > /dev/null 2>&1
101    [ -d $I2PTEMP ] || mkdir $I2PTEMP > /dev/null 2>&1
102    if [ -r $PIDFILE ]; then
103        PID="$(cat ${PIDFILE})"
104        if ! kill -0 $PID > /dev/null 2>&1; then
105                rm "$PIDFILE" "$JVMPIDFILE"
106        else
107                # we shouldn't get here, but...
108                echo "ERROR: Another instance of $DESC is already running." >&2
109                return 1
110        fi
111    fi
112    chown -Rf $I2PUSER:$I2PUSER  $I2PTEMP $RUN > /dev/null 2>&1
113    chown -f -R $I2PUSER:i2psvc /var/log/$NAME > /dev/null 2>&1
114    TZ=UTC start-stop-daemon --start --quiet -c $I2PUSER --pidfile $PIDFILE --exec $DAEMON -n $NICE -- \
115        $I2P_ARGS || return 2
116}
117
118do_stop()
119{
120    start-stop-daemon --stop --quiet --retry=TERM/60/KILL/20 --pidfile $PIDFILE -u $I2PUSER
121    RETVAL="$?"
122    [ "$RETVAL" = 2 ] && return 2
123
124    start-stop-daemon --stop --quiet --oknodo --retry=0/60/KILL/20 --exec $DAEMON
125
126    rm -rf "$I2PTEMP" > /dev/null 2>&1
127    [ -d "$RUN" ] && rmdir "$RUN" 2>&1
128}
129
130do_dump()
131{
132    start-stop-daemon --stop --quiet -s 3 --pidfile $PIDFILE -u $I2PUSER
133    RETVAL="$?"
134    [ "$RETVAL" = 2 ] && return 2
135}
136
137do_graceful()
138{
139    start-stop-daemon --stop --quiet -s HUP --pidfile $PIDFILE -u $I2PUSER
140    [ "$RETVAL" = 2 ] && return 2
141}
142
143case "$1" in
144  start)
145        log_daemon_msg "Starting $DESC" "$NAME"
146        do_start
147        case "$?" in
148                0|1) log_end_msg 0 ;;
149                2) log_end_msg 1 ;;
150        esac
151        ;;
152  dump)
153        log_daemon_msg "Dumping $DESC" "$NAME"
154        do_dump
155        case "$?" in
156                0|1) log_end_msg 0 ;;
157                2) log_end_msg 1 ;;
158        esac
159        ;;
160  graceful)
161        log_daemon_msg "Attempting graceful shutdown of $DESC" "$NAME"
162        log_daemon_msg "(could take up to 11 minutes)"
163        do_graceful
164        case "$?" in
165                0|1) log_end_msg 0 ;;
166                2) log_end_msg 1 ;;
167        esac
168        ;;
169  stop)
170    log_daemon_msg "Stopping $DESC" "$NAME"
171        do_stop
172        case "$?" in
173                0|1) log_end_msg 0 ;;
174                2) log_end_msg 1 ;;
175        esac
176        ;;
177  status)
178       status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
179    ;;
180 restart|force-reload)
181        log_daemon_msg "Restarting $DESC" "$NAME"
182        do_stop
183        case "$?" in
184          0|1)
185                do_start
186                case "$?" in
187                        0) log_end_msg 0 ;;
188                        1) log_end_msg 1 ;; # Old process is still running
189                        *) log_end_msg 1 ;; # Failed to start
190                esac
191                ;;
192          *)
193                # Failed to stop
194                log_end_msg 1
195                ;;
196        esac
197        ;;
198*)
199    N=/etc/init.d/$NAME
200    echo "Usage: $N {start|stop|dump|graceful|status|restart|force-reload}" >&2
201    exit 3
202    ;;
203
204
205esac
Note: See TracBrowser for help on using the repository browser.