avoid attempting to run anything at build-time & cleaned up
[ipfw.git] / planetlab / ipfw
1 #!/bin/sh
2 #
3 # ipfw  init the emulation service
4 #
5 # chkconfig: 2345 09 91
6 # description: ipfw init and shutdown
7 #
8
9 # Source function library.
10 . /etc/init.d/functions
11
12 IPFW=ipfw
13 IPFW_BACKEND=/vsys/ipfw-be
14 IPFW_MOD=ipfw_mod
15
16 if [ ! -x /sbin/$IPFW ] || [ ! -x ${IPFW_BACKEND} ]; then
17     echo -n "/sbin/$IPFW does not exist."; warning; echo
18     exit 0
19 fi
20
21 # Load the ipfw module, and initialize netconfig
22 start() {
23         # load the module
24         modprobe $IPFW_MOD >& /dev/null
25         let ret=$?;
26         [ $ret -eq 0 ] && success || failure
27
28         # init netconfig
29         echo "super dbcleanup" | ${IPFW_BACKEND} root >& /dev/null
30         echo "super init" | ${IPFW_BACKEND} root >& /dev/null
31
32         return $ret
33 }
34
35 stop() {
36         # clean netconfig stuff
37         echo "super dbcleanup" | ${IPFW_BACKEND} root >& /dev/null
38         echo "Unloading $IPFW_MOD module: "
39
40         # unload the ipfw module
41         rmmod ${IPFW_MOD}
42         let ret=$?;
43         [ $ret -eq 0 ] && success || failure
44
45         return $ret
46 }
47
48 # echo the ipfw status
49 status() {
50         # check for module presence
51         grep '^ipfw_mod$' /proc/modules >& /dev/null || echo "ipfw not loaded" && return 0
52
53         # Show active users
54         USERS=$(grep BLOCK /tmp/ff | wc -l)
55         echo "ipfw is loaded and there are currently ${USERS} with active emulation."
56         return 0
57 }
58
59 # main
60 case "$1" in
61     start)
62         start
63         RETVAL=$?
64         ;;
65     stop)
66         stop
67         RETVAL=$?
68         ;;
69     restart)
70         stop
71         start
72         RETVAL=$?
73         ;;
74     status)
75         status
76         RETVAL=$?
77         ;;
78     *)
79         echo $"Usage: $0 {start|stop|restart|status}"
80         exit 1
81         ;;
82 esac
83
84 exit $RETVAL