1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          lldpd
4 # Required-Start:    $remote_fs $network $syslog
5 # Required-Stop:     $network $remote_fs $syslog
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: LLDP daemon
9 # Description:       lldpd is a 802.1AB implementation, a L2 network
10 #                    discovery protocol. It also supports CDP, EDP and
11 #                    various other protocols.
12 ### END INIT INFO
13 
14 # Do NOT "set -e"
15 
log_daemon_msg()16 log_daemon_msg() {
17     echo $*
18 }
19 
log_end_msg()20 log_end_msg() {
21     if [ $1 -eq 0 ]; then
22         success $*
23     else
24         failure $*
25     fi
26 }
27 
log_failure_msg()28 log_failure_msg() {
29     echo $*
30 }
31 
log_success_msg()32 log_success_msg() {
33     echo $*
34 }
35 
36 
37 # PATH should only include /usr/* if it runs after the mountnfs.sh script
38 PATH=/sbin:/usr/sbin:/bin:/usr/bin
39 DESC="LLDP daemon"
40 NAME=lldpd
41 DAEMON=/usr/sbin/$NAME
42 DAEMON_ARGS=""
43 PIDFILE=/var/run/$NAME.pid
44 SCRIPTNAME=/etc/init.d/$NAME
45 CHROOT=/var/run/$NAME
46 
47 # Exit if the package is not installed
48 [ -x "$DAEMON" ] || exit 0
49 
50 # Read configuration variable file if it is present
51 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
52 
53 # LSB log_* functions
54 . /etc/init.d/functions
55 
56 do_start()
57 {
58 	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
59 		$DAEMON_ARGS \
60 		|| return 2
61 }
62 
63 do_stop()
64 {
65 	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
66 	RETVAL="$?"
67 	[ "$RETVAL" = 2 ] && return 2
68 	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
69 	[ "$?" = 2 ] && return 2
70 	rm -f $PIDFILE
71 	return "$RETVAL"
72 }
73 
74 do_reload() {
75 	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
76 	return 0
77 }
78 
79 case "$1" in
80   start)
81 	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
82 	do_start
83 	case "$?" in
84 		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
85 		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
86 	esac
87 	;;
88   stop)
89 	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
90 	do_stop
91 	case "$?" in
92 		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
93 		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
94 	esac
95 	;;
96   reload)
97 	log_daemon_msg "Reloading $DESC" "$NAME"
98 	do_reload
99 	log_end_msg $?
100 	;;
101   restart|force-reload)
102 	log_daemon_msg "Restarting $DESC" "$NAME"
103 	do_stop
104 	case "$?" in
105 	  0|1)
106 		do_start
107 		case "$?" in
108 			0) log_end_msg 0 ;;
109 			1) log_end_msg 1 ;; # Old process is still running
110 			*) log_end_msg 1 ;; # Failed to start
111 		esac
112 		;;
113 	  *)
114 	  	# Failed to stop
115 		log_end_msg 1
116 		;;
117 	esac
118 	;;
119   status)
120 	status_of_proc $DAEMON $NAME -p $PIDFILE && exit 0 || exit $?
121 	;;
122   *)
123 	echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2
124 	exit 3
125 	;;
126 esac
127 
128 :
129