]> git.ipfire.org Git - people/ms/rstp.git/blame - bridge-stp
bridge-stp: Fix variable name used to generate pid_file
[people/ms/rstp.git] / bridge-stp
CommitLineData
3afabefa
SH
1#!/bin/bash
2#
3# Script to start/stop spanning tree called from kernel
358260ff
SH
4# Make sure umask is sane
5umask 022
3afabefa 6
358260ff
SH
7# Set up a default search path.
8PATH="/sbin:/usr/sbin:/bin:/usr/bin"
9export PATH
3afabefa
SH
10
11if [ $# -ne 2 ]; then
12 echo "Usage: bridge-stp <bridge> {start|stop}"
13 exit 1
14fi
358260ff
SH
15bridge=$1
16service=rstpd
b27ab0ef 17pid_file=/var/run/${service}.pid
358260ff
SH
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.
22checkpid() {
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
38daemon() {
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
49start() {
50 daemon
51}
3afabefa
SH
52
53case $2 in
358260ff
SH
54 start)
55 daemon
18da741b 56 exec /sbin/rstpctl rstp $bridge on ;;
358260ff 57 stop)
18da741b 58 exec /sbin/rstpctl rstp $bridge off ;;
3afabefa
SH
59 *)
60 echo "Unknown action:" $2
61 echo "Usage: bridge-stp <bridge> {start|stop}"
62 exit 1
63esac