1#!/bin/sh
2
3. ${STREAMBOOST_CFGDIR:-/etc/appflow}/rc.appflow
4
5#
6# Environment config
7#
8BINARY="cape"
9NAME=${BINARY}
10DISPLAY_NAME="Class Arbiter/Policy Engine"
11
12#
13# Cape config
14#
15# path to cape binary
16CAPE_BIN="${BINDIR}/${BINARY}"
17
18# path to cape pid file
19PIDFILE="${RUNDIR}/${BINARY}.pid"
20
21# Redis server
22REDIS_PORT=6379
23REDIS_UNIXSOCK=/var/run/appflow/redis.sock
24
25# pull in the guest network config so we know if we need to create
26# a node exception rule
27[ -f /etc/dhcp.guest.conf ] && . /etc/dhcp.guest.conf
28
29# Format the command line parameters
30CMDLINE_OPTS="--daemon -u ${REDIS_UNIXSOCK} -p ${PIDFILE} --cache 8"
31#
32# Functions
33#
34
35start() {
36	# if we're configured for guest network, we need to add node
37	# exceptions for all nodes on the network
38	[ "$GUEST_DHCP_ENABLE" = "yes" ] && {
39		local bypass=$(ipaddr_netmask_to_cidr ${GUEST_DHCP_IPADDR} ${GUEST_DHCP_NETMASK})
40		redis-cli lpush policydb:except:nodes "${bypass}"
41	}
42
43	[ ! -d "${RUNDIR}" ] && {
44		mkdir ${RUNDIR}
45	}
46
47	[ -x ${CAPE_BIN} ] || {
48		echo "${BINARY} not found: ${CAPE_BIN}"
49		exit 2
50	}
51
52	echo -n "Starting ${NAME}: "
53	${CAPE_BIN} ${CMDLINE_OPTS} "$@"
54	retval=$?
55	echo
56	return ${retval}
57}
58
59boot() {
60	start "$@"
61}
62
63stop() {
64	default_stop
65
66	# clean up the guest network node exceptions
67	[ "$GUEST_DHCP_ENABLE" = "yes" ] && {
68		local bypass=$(ipaddr_netmask_to_cidr ${GUEST_DHCP_IPADDR} ${GUEST_DHCP_NETMASK})
69		redis-cli lrem policydb:except:nodes 0 "${bypass}"
70	}
71
72	return 0
73}
74
75action "$@"
76exit $?
77