source: debian/i2p.init @ 454c7f1

Last change on this file since 454c7f1 was 454c7f1, checked in by kytv <kytv@…>, 10 years ago

Debian: get locale information by sourcing /etc/environment and
/etc/default/locale, if found. This prevents a problem with the encoding being
set to ANSI_X3.4-1968 when I2P is started at boot.

  • Property mode set to 100755
File size: 4.4 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.'
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/"
29WRAPPERLOG="/var/log/i2p/wrapper.log"
30
31# Don't touch these, edit /etc/default/i2p
32RUN_DAEMON="False"
33NICE=
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.5=-Dwrapper.logfile=$WRAPPERLOG \
39 wrapper.logfile=$WRAPPERLOG \
40 wrapper.pidfile=$PIDFILE \
41 wrapper.java.pidfile=$JVMPIDFILE \
42 wrapper.daemonize=TRUE"
43
44for ENV_FILE in /etc/environment /etc/default/locale; do
45[ -r "$ENV_FILE" ] || continue
46[ -s "$ENV_FILE" ] || continue
47
48 for var in LANG LANGUAGE LC_ALL LC_CTYPE; do
49     value=`egrep "^${var}=" "$ENV_FILE" | tail -n1 | cut -d= -f2`
50     [ -n "$value" ] && eval export $var=$value
51
52     if [ -n "$value" ] && [ "$ENV_FILE" = /etc/environment ]; then
53         log_warning_msg "/etc/environment has been deprecated for locale information; use /etc/default/locale for $var=$value instead"
54     fi
55 done
56done
57
58# this isn't really needed since we depend on lsb-base (>= 3.2-14)
59## Actually, we *do* need this since the versioned dependency has been dropped
60## the I2P packages can be installed in GnewSense.
61[ -r /lib/lsb/init-functions ] && . /lib/lsb/init-functions
62[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
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 set. Aborting."
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
80# is the wrapper from the service-wrapper package even installed?
81# if not, bail NOW
82
83[ -x $DAEMON ] || exit 0
84
85# Ditto for i2prouter. Even though this script doesn't call it,
86# if it's not found the package probably hasn't been installed.
87
88[ -r /usr/bin/i2prouter ] || exit 0
89
90do_start()
91{
92        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null\
93                || return 1
94        [ -d $RUN ] || mkdir $RUN
95        [ -r $PIDFILE ] || touch $PIDFILE
96        [ -r $JVMPIDFILE ] || touch $JVMPIDFILE
97        [ -d $I2PTEMP ] || mkdir $I2PTEMP 
98        chown -Rf $I2PUSER:$I2PUSER  $I2PTEMP/*i2p* $I2PTEMP/router.ping $RUN > /dev/null 2>&1
99        chown -f -R $I2PUSER:adm /var/log/$NAME
100        TZ=UTC start-stop-daemon --start --quiet -c $I2PUSER --pidfile $PIDFILE --exec $DAEMON $NICE -- \
101                $I2P_ARGS || return 2
102}
103
104do_stop()
105{
106        start-stop-daemon --stop --quiet --retry=TERM/15/KILL/5 --pidfile $PIDFILE -u $I2PUSER
107        RETVAL="$?"
108        [ "$RETVAL" = 2 ] && return 2
109
110#       start-stop-daemon --stop --quiet --oknodo --retry=TERM/15/KILL/5 -u $I2PUSER
111
112        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
113
114        rm -f "$PIDFILE" "$JVMPIDFILE"
115        [ -d $RUN ] && rmdir $RUN
116}
117
118
119case "$1" in
120  start)
121        log_daemon_msg "Starting $DESC" "$NAME"
122        do_start
123        case "$?" in
124                0|1) log_end_msg 0 ;;
125                2) log_end_msg 1 ;;
126        esac
127        ;; 
128  stop)
129        log_daemon_msg "Stopping $DESC" "$NAME"
130        do_stop
131        case "$?" in
132                0|1) log_end_msg 0 ;;
133                2) log_end_msg 1 ;;
134        esac
135        ;; 
136  status)
137       status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
138        ;;
139 restart|force-reload)
140        log_daemon_msg "Restarting $DESC" "$NAME"
141        do_stop
142        case "$?" in
143          0|1)
144                do_start
145                case "$?" in
146                        0) log_end_msg 0 ;;
147                        1) log_end_msg 1 ;; # Old process is still running
148                        *) log_end_msg 1 ;; # Failed to start
149                esac
150                ;;
151          *)
152                # Failed to stop
153                log_end_msg 1
154                ;;
155        esac
156        ;;
157*)
158        N=/etc/init.d/$NAME
159        echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
160        exit 3
161        ;;
162
163
164esac
Note: See TracBrowser for help on using the repository browser.