source: debian/i2p.init @ b6fab82

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

Debian packaging fixes

  • Property mode set to 100755
File size: 3.8 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"
30ANCHORFILE="$I2PTEMP/i2p.anchor"
31
32# Don't touch these, edit /etc/default/i2p
33RUN_DAEMON="False"
34NICE=
35I2PUSER="i2psvc"
36
37I2P_ARGS="/etc/i2p/wrapper.config \
38 wrapper.java.additional.1=-DloggerFilenameOverride=/var/log/i2p/log-router-@.txt \
39 wrapper.java.additional.5=-Dwrapper.logfile=$WRAPPERLOG \
40 wrapper.logfile=$WRAPPERLOG \
41 wrapper.pidfile=$PIDFILE \
42 wrapper.anchorfile=$ANCHORFILE \
43 wrapper.java.pidfile=$JVMPIDFILE \
44 wrapper.daemonize=TRUE"
45
46
47
48# this isn't really needed since we depend on lsb-base (>= 3.2-14)
49[ -r /lib/lsb/init-functions ] && . /lib/lsb/init-functions
50[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
51
52# read config file
53[ -r /etc/default/$NAME ] && . /etc/default/$NAME
54
55case "$RUN_DAEMON" in
56        [NnFf]*)
57                log_action_msg "$DESC daemon disabled in /etc/default/$NAME".
58                exit 0
59                ;;
60esac
61
62
63# is the wrapper from the service-wrapper package even installed?
64# if not, bail NOW
65
66[ -x $DAEMON ] || exit 0
67
68# Ditto for i2prouter. Even though this script doesn't call it,
69# if it's not found the package probably hasn't been installed.
70
71[ -r /usr/bin/i2prouter ] || exit 0
72
73do_start()
74{
75        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null\
76                || return 1
77        [ -d $RUN ] || mkdir $RUN
78        [ -r $PIDFILE ] || touch $PIDFILE
79        [ -r $JVMPIDFILE ] || touch $JVMPIDFILE
80        [ -d $I2PTEMP ] || mkdir $I2PTEMP 
81        chown -Rf $I2PUSER:$I2PUSER  $I2PTEMP/*i2p* $I2PTEMP/router.ping $RUN > /dev/null
82        chown -f -R $I2PUSER:adm /var/log/$NAME
83        TZ=UTC start-stop-daemon --start --quiet -c $I2PUSER --pidfile $PIDFILE --exec $DAEMON $NICE -- \
84                $I2P_ARGS || return 2
85}
86
87do_stop()
88{
89        start-stop-daemon --stop --quiet --retry=TERM/15/KILL/5 --pidfile $PIDFILE -u $I2PUSER
90        RETVAL="$?"
91        [ "$RETVAL" = 2 ] && return 2
92
93#       start-stop-daemon --stop --quiet --oknodo --retry=TERM/15/KILL/5 -u $I2PUSER
94
95        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
96
97        rm -f "$PIDFILE" "$JVMPIDFILE"
98        [ -d $RUN ] && rmdir $RUN
99}
100
101
102case "$1" in
103  start)
104        log_daemon_msg "Starting $DESC" "$NAME"
105        do_start
106        case "$?" in
107                0|1) log_end_msg 0 ;;
108                2) log_end_msg 1 ;;
109        esac
110        ;; 
111  stop)
112        log_daemon_msg "Stopping $DESC" "$NAME"
113        do_stop
114        case "$?" in
115                0|1) log_end_msg 0 ;;
116                2) log_end_msg 1 ;;
117        esac
118        ;; 
119  status)
120       status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
121        ;;
122 restart|force-reload)
123        log_daemon_msg "Restarting $DESC" "$NAME"
124        do_stop
125        case "$?" in
126          0|1)
127                do_start
128                case "$?" in
129                        0) log_end_msg 0 ;;
130                        1) log_end_msg 1 ;; # Old process is still running
131                        *) log_end_msg 1 ;; # Failed to start
132                esac
133                ;;
134          *)
135                # Failed to stop
136                log_end_msg 1
137                ;;
138        esac
139        ;;
140*)
141        N=/etc/init.d/$NAME
142        echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
143        exit 3
144        ;;
145
146
147esac
Note: See TracBrowser for help on using the repository browser.