]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | # | |
3 | # Script to start/stop spanning tree called from kernel | |
4 | # Make sure umask is sane | |
5 | umask 022 | |
6 | ||
7 | # Set up a default search path. | |
8 | PATH="/sbin:/usr/sbin:/bin:/usr/bin" | |
9 | export PATH | |
10 | ||
11 | if [ $# -ne 2 ]; then | |
12 | echo "Usage: bridge-stp <bridge> {start|stop}" | |
13 | exit 1 | |
14 | fi | |
15 | bridge=$1 | |
16 | service=rstpd | |
17 | pid_file=/var/run/${service}.pid | |
18 | ||
19 | # Set $pid to pids from /var/run* for {program}. $pid should be declared | |
20 | # local in the caller. | |
21 | # Returns LSB exit code for the 'status' action. | |
22 | checkpid() { | |
23 | pid= | |
24 | if [ -f "$1" ] ; then | |
25 | local line p | |
26 | read line < "$pid_file" | |
27 | for p in $line ; do | |
28 | [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p" | |
29 | done | |
30 | if [ -n "$pid" ]; then | |
31 | return 0 | |
32 | fi | |
33 | return 1 # "Program is dead and /var/run pid file exists" | |
34 | fi | |
35 | return 3 # "Program is not running" | |
36 | } | |
37 | ||
38 | daemon() { | |
39 | local pid | |
40 | checkpid $pid_file | |
41 | ||
42 | [ -n "$pid" ] && return | |
43 | # start it | |
44 | /sbin/rstpd | |
45 | RETVAL=$? | |
46 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$service | |
47 | } | |
48 | ||
49 | start() { | |
50 | daemon | |
51 | } | |
52 | ||
53 | case $2 in | |
54 | start) | |
55 | daemon | |
56 | exec /sbin/rstpctl rstp $bridge on ;; | |
57 | stop) | |
58 | exec /sbin/rstpctl rstp $bridge off ;; | |
59 | *) | |
60 | echo "Unknown action:" $2 | |
61 | echo "Usage: bridge-stp <bridge> {start|stop}" | |
62 | exit 1 | |
63 | esac |