source: debian/i2p.init @ 9e6885d

Last change on this file since 9e6885d was dc2198d, checked in by kytv <kytv@…>, 9 years ago

Debian: Add ability to dump threads to the initscript

  • Property mode set to 100755
File size: 4.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.'
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
118do_dump()
119{
120        start-stop-daemon --stop --quiet -s 3 --pidfile $PIDFILE -u $I2PUSER
121        RETVAL="$?"
122        [ "$RETVAL" = 2 ] && return 2
123}
124
125case "$1" in
126  start)
127        log_daemon_msg "Starting $DESC" "$NAME"
128        do_start
129        case "$?" in
130                0|1) log_end_msg 0 ;;
131                2) log_end_msg 1 ;;
132        esac
133        ;;
134  dump)
135        log_daemon_msg "Dumping $DESC" "$NAME"
136        do_dump
137        case "$?" in
138                0|1) log_end_msg 0 ;;
139                2) log_end_msg 1 ;;
140        esac
141        ;;
142  stop)
143        log_daemon_msg "Stopping $DESC" "$NAME"
144        do_stop
145        case "$?" in
146                0|1) log_end_msg 0 ;;
147                2) log_end_msg 1 ;;
148        esac
149        ;;
150  status)
151       status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
152        ;;
153 restart|force-reload)
154        log_daemon_msg "Restarting $DESC" "$NAME"
155        do_stop
156        case "$?" in
157          0|1)
158                do_start
159                case "$?" in
160                        0) log_end_msg 0 ;;
161                        1) log_end_msg 1 ;; # Old process is still running
162                        *) log_end_msg 1 ;; # Failed to start
163                esac
164                ;;
165          *)
166                # Failed to stop
167                log_end_msg 1
168                ;;
169        esac
170        ;;
171*)
172        N=/etc/init.d/$NAME
173        echo "Usage: $N {start|stop|dump|status|restart|force-reload}" >&2
174        exit 3
175        ;;
176
177
178esac
Note: See TracBrowser for help on using the repository browser.