source: debian/i2p.init @ 2253ad1

Last change on this file since 2253ad1 was 2dcc75ad, checked in by kytv <kytv@…>, 9 years ago

set /var/log/i2p to group i2psvc instead of adm

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