File: farpd.init

package info (click to toggle)
farpd 0.2-10
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 320 kB
  • ctags: 92
  • sloc: sh: 3,213; ansic: 1,009; makefile: 71
file content (151 lines) | stat: -rw-r--r-- 3,604 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh -e
#
# /etc/init.d/farpd
#
# Originally written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for nessusd by Luca Andreucci <andrew@andrew.org>
# Furter changes by Javier Fernandez-Sanguino <jfs@debian.org> for the 
# Debian GNU/Linux distribution
# Modified for farpd by Javier Fernandez-Sanguino <jfs@debian.org> 
#
### BEGIN INIT INFO
# Provides:          farpd
# Required-Start:    $network $syslog
# Required-Stop:     $network $syslog
# Default-Start:     
# Default-Stop:      0 1 6
# Short-Description: Daemon that replies to any ARP requests
# Description:       Farpd ('fake ARPD') will reply to any ARP request for IP 
#                    addresses matching a destination net with the MAC
#                    address of the specified interface if no hosts claims it.
### END INIT INFO

# Default
INTERFACE=""
NETWORK="unconfigured"
# time to wait for daemons death, in seconds
# don't set it too low or you might not let it die gracefully
DODTIME=1
[ -r /etc/default/farpd ] && . /etc/default/farpd

. /lib/lsb/init-functions

DAEMON=/usr/sbin/farpd
PIDFILE=/var/run/farpd.pid
NAME=farpd
LABEL="Fake-arpd daemon"
DAEMONOPTS="$NETWORK"
if [ -n "$INTERFACE" ] ; then
    DAEMONOPTS="-i $INTERFACE "
fi
if [ -n "$NETWORK" ] ; then
    DAEMONOPTS="$DAEMONOPTS $NETWORK "
fi

test -x $DAEMON || exit 0


configured() {
# Check if the user has configured it
    if [ "$NETWORK" = "unconfigured" ] ; then
        log_failure_msg "Fake-arpd has not been configured, please review and configure /etc/default/farpd"
        log_end_msg 1
    fi
}

running()
{
    # No pidfile, probably no daemon present
    #
    [ -r "$PIDFILE" ] && pid=`cat $PIDFILE`

    # No pid, probably no daemon present
    [ -z "$pid" ] && return 1

    [ ! -d /proc/$pid ] &&  return 1
    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
    # No process?
    [ "$cmd" != "$DAEMON" ] &&  return 1

    return 0
}


start() {
        start-stop-daemon --start --exec $DAEMON -- $DAEMONOPTS 2>&1 >/dev/null
	errcode=$?
# If we don't sleep then running() might not see the pidfile
	sleep $DODTIME
	return $errcode
}

force_stop() {
	[ ! -e "$PIDFILE" ] && return
	if running ; then
		kill -15 $pid
	# Is it really dead?
		sleep "$DODTIME"s
		if running ; then
			kill -9 $pid
			sleep "$DODTIME"s
			if running ; then
				log_failure_msg "Cannot kill $LABEL (pid=$pid)!"
                                log_end_msg 1
			fi
		fi
	fi
	rm -f $PIDFILE
}

case "$1" in
  start)
    configured
    log_daemon_msg "Starting $LABEL" "$NAME"
    if start && running ;  then
            log_end_msg 0
    else
            log_end_msg 1
    fi
    ;;
  stop)
    log_daemon_msg "Stopping $LABEL" "$NAME"
    start-stop-daemon --stop --pidfile $PIDFILE --quiet --oknodo --exec $DAEMON
    if running; then
        force_stop
    fi
    log_end_msg 0
      ;;
  reload|force-reload|restart)
    configured
    log_daemon_msg "Restarting $LABEL" "$NAME"
    if running; then
    	start-stop-daemon --stop --pidfile $PIDFILE --quiet --oknodo --exec $DAEMON
    	sleep "$DODTIME"s
    fi
    if running; then
        force_stop
    fi
    if start && running ;  then
            log_end_msg 0
    else
            log_end_msg 1
    fi
    ;;
  status)
    configured
    echo -n "$LABEL is "
    if running ;  then
	    echo "running"
    else
    	    echo " not running."
	    exit 1
    fi
    ;;
  *)
    log_action_msg "Usage: /etc/init.d/$NAME {start|stop|restart|reload|status}"
    exit 2
    ;;
esac

exit 0