lldpd: conversion of init script to procd format
[openwrt/svn-archive/archive.git] / package / network / services / lldpd / files / lldpd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2012 OpenWrt.org
3
4 START=90
5
6 USE_PROCD=1
7
8 find_release_info()
9 {
10 [ -s /etc/openwrt_release ] && . /etc/openwrt_release
11 [ -z "$DISTRIB_DESCRIPTION" ] && [ -s /etc/openwrt_version ] && \
12 DISTRIB_DESCRIPTION="$(cat /etc/openwrt_version)"
13
14 echo "${DISTRIB_DESCRIPTION:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
15 }
16
17 start_service() {
18 . /lib/functions/network.sh
19
20 local enable_cdp
21 local enable_fdp
22 local enable_sonmp
23 local enable_edp
24 local lldp_class
25 local lldp_location
26 local lldp_description
27 local readonly_mode
28
29 config_load 'lldpd'
30 config_get_bool enable_cdp 'config' 'enable_cdp' 0
31 config_get_bool enable_fdp 'config' 'enable_fdp' 0
32 config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
33 config_get_bool enable_edp 'config' 'enable_edp' 0
34 config_get lldp_class 'config' 'lldp_class'
35 config_get lldp_location 'config' 'lldp_location'
36 config_get lldp_description 'config' 'lldp_description' "$(find_release_info)"
37 config_get_bool readonly_mode 'config' 'readonly_mode' 0
38
39 local ifaces
40 config_get ifaces 'config' 'interface'
41
42 local iface ifnames=""
43 for iface in $ifaces; do
44 local ifname=""
45 if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
46 append ifnames "${ifname:-$iface}" ","
47 fi
48 done
49
50 mkdir -p /var/run/lldp
51 chown lldp:lldp /var/run/lldp
52
53 procd_open_instance
54 procd_set_param command /usr/sbin/lldpd
55 procd_append_param command -d # don't daemonize, procd will handle that for us
56
57 [ -n "$ifnames" ] && procd_append_param command "-I $ifnames"
58 [ $enable_cdp -gt 0 ] && procd_append_param command '-c'
59 [ $enable_fdp -gt 0 ] && procd_append_param command '-f'
60 [ $enable_sonmp -gt 0 ] && procd_append_param command '-s'
61 [ $enable_edp -gt 0 ] && procd_append_param command '-e'
62 [ $readonly_mode -gt 0 ] && procd_append_param command '-r'
63 [ -n "$lldp_class" ] && procd_append_param command "-M $lldp_class"
64 [ -n "$lldp_description" ] && procd_append_param command "-S $lldp_description"
65
66 # set auto respawn behavior
67 procd_set_param respawn
68 procd_close_instance
69 }
70
71 stop_service() {
72 rm -f /var/run/lldpd.socket /var/run/lldpd.pid
73 }