source: debian/i2p.init @ 77d970f

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

debian: initscript: reorder, change some exit statuses

  • Property mode set to 100755
File size: 5.0 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     if [ -n "$value" ] && [ "$ENV_FILE" = /etc/environment ]; then
59         log_warning_msg "/etc/environment has been deprecated for locale information; use /etc/default/locale for $var=$value instead"
60     fi
61 done
62done
63
64# read config file
65[ -r /etc/default/$NAME ] && . /etc/default/$NAME
66
67if [ -z "$RUN_DAEMON" ]; then
68    echo "/etc/default/$NAME is not properly configured. Aborting." >&2
69    exit 1
70fi
71
72case "$RUN_DAEMON" in
73        [NnFf]*)
74                log_action_msg "$DESC daemon disabled in /etc/default/$NAME".
75                exit 0
76                ;;
77esac
78
79# We need the wrapper. If it's not found, abort.
80[ -x $DAEMON ] || exit 1
81
82# Even though this script doesn't call it, check for i2prouter.  If it's not
83# found, it probably means that the package isn't installed anymore.
84[ -x /usr/bin/i2prouter ] || exit 1
85
86do_start()
87{
88    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null 2>&1 \
89        || return 1
90    [ -d $RUN ] || mkdir $RUN > /dev/null 2>&1
91    [ -d $I2PTEMP ] || mkdir $I2PTEMP > /dev/null 2>&1
92    if [ -r $PIDFILE ]; then
93        PID="$(cat ${PIDFILE})"
94        if ! kill -0 $PID > /dev/null 2>&1; then
95                rm "$PIDFILE" "$JVMPIDFILE"
96        else
97                # we shouldn't get here, but...
98                echo "ERROR: Another instance of $DESC is already running." >&2
99                return 1
100        fi
101    fi
102    chown -Rf $I2PUSER:$I2PUSER  $I2PTEMP $RUN > /dev/null 2>&1
103    chown -f -R $I2PUSER:i2psvc /var/log/$NAME > /dev/null 2>&1
104    TZ=UTC start-stop-daemon --start --quiet -c $I2PUSER --pidfile $PIDFILE --exec $DAEMON -n $NICE -- \
105        $I2P_ARGS || return 2
106}
107
108do_stop()
109{
110    start-stop-daemon --stop --quiet --retry=TERM/60/KILL/20 --pidfile $PIDFILE -u $I2PUSER
111    RETVAL="$?"
112    [ "$RETVAL" = 2 ] && return 2
113
114    start-stop-daemon --stop --quiet --oknodo --retry=0/60/KILL/20 --exec $DAEMON
115
116    rm -rf "$I2PTEMP" > /dev/null 2>&1
117    [ -d "$RUN" ] && rmdir "$RUN" 2>&1
118}
119
120do_dump()
121{
122    start-stop-daemon --stop --quiet -s 3 --pidfile $PIDFILE -u $I2PUSER
123    RETVAL="$?"
124    [ "$RETVAL" = 2 ] && return 2
125}
126
127case "$1" in
128  start)
129        log_daemon_msg "Starting $DESC" "$NAME"
130        do_start
131        case "$?" in
132                0|1) log_end_msg 0 ;;
133                2) log_end_msg 1 ;;
134        esac
135        ;;
136  dump)
137        log_daemon_msg "Dumping $DESC" "$NAME"
138        do_dump
139        case "$?" in
140                0|1) log_end_msg 0 ;;
141                2) log_end_msg 1 ;;
142        esac
143        ;;
144  stop)
145    log_daemon_msg "Stopping $DESC" "$NAME"
146        do_stop
147        case "$?" in
148                0|1) log_end_msg 0 ;;
149                2) log_end_msg 1 ;;
150        esac
151        ;;
152  status)
153       status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
154    ;;
155 restart|force-reload)
156        log_daemon_msg "Restarting $DESC" "$NAME"
157        do_stop
158        case "$?" in
159          0|1)
160                do_start
161                case "$?" in
162                        0) log_end_msg 0 ;;
163                        1) log_end_msg 1 ;; # Old process is still running
164                        *) log_end_msg 1 ;; # Failed to start
165                esac
166                ;;
167          *)
168                # Failed to stop
169                log_end_msg 1
170                ;;
171        esac
172        ;;
173*)
174    N=/etc/init.d/$NAME
175    echo "Usage: $N {start|stop|dump|status|restart|force-reload}" >&2
176    exit 3
177    ;;
178
179
180esac
Note: See TracBrowser for help on using the repository browser.