summaryrefslogtreecommitdiff
path: root/recipes-core/busybox/files/ifplugd.init
blob: 418b088d9f8e9227f0ac0be872565ddd6af55c22 (plain)
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
#! /bin/bash
#
# ifplugd  init.d script
[[ -x /usr/sbin/ifplugd ]] || exit 0
[[ -r /etc/default/ifplugd ]] && . /etc/default/ifplugd


#Functions to do individual actions
startdaemon(){
    # Start the application
    echo -n "Starting ifplugd: "
    CONFS=($(find -L /etc/ifplugd -name '*.conf'))
    ((i=0))
    logger -p daemon.info "Found ${#CONFS[@]} Configurations"
    while ((i < ${#CONFS[@]})) ; do
        unset ARGS INTERFACE
        . ${CONFS[$i]}
	logger -p daemon.info "Starting Interface ${INTERFACE}"
        ((i++))
        /usr/sbin/start-stop-daemon -Svp /run/ifplugd.${INTERFACE}.pid -a /usr/sbin/ifplugd -- ${ARGS}
    done
    if ((${#CONFS[@]} == 0)) ; then
        /usr/sbin/start-stop-daemon -n ifplugd -Sv -x /usr/sbin/ifplugd -- ${ARGS}
    fi
    echo "done"
}
stopdaemon(){
    echo -n "Stopping ifplugd: "
    PIDS=($(find /run -xdev -name 'ifplugd.*.pid'))
    ((i=0))
    while ((i < ${#PIDS[@]})) ; do
        PF=${PIDS[$i]}
        [[ $PF =~ /ifplugd\.([^.]*)\.pid ]]
        IF=${BASH_REMATCH[1]}
        logger -p user.info "Shutting down interface $IF"
        /usr/sbin/start-stop-daemon -n ifplugd -Kqp $PF
        ((i++))
    done
    echo "done"
}

case "$1" in
  start)
        [[ ${ENABLED} == "yes" ]] || exit 0
	startdaemon
	;;
  stop)
  	stopdaemon
	;;
  restart|force-reload)
	stopdaemon
	sleep 2
	startdaemon
	;;
  *)
	echo "Usage: /etc/init.d/ifplugd { start | stop | restart | force-reload }" >&2
	exit 1
	;;
esac

exit 0