-
Notifications
You must be signed in to change notification settings - Fork 2
/
policyserver
executable file
·62 lines (57 loc) · 2.58 KB
/
policyserver
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
#!/bin/sh
# starts, stops and controlls the flash policy server
# see http://github.com/saulabs/flashpolicy-erlang
NODE="flashpolicy"
RANDOM_COOKIE=`head /dev/random | shasum | cut -d " " -f1 | tr -d '\n'`
COOKIE=`ps ax | grep flashpolicy | grep beam | grep -o -e 'setcookie[[:blank:]]\+[[:alnum:]]\+' | cut -d " " -f2 | tr -d '\n'`
NODE_NAME="$NODE@"`hostname -s`
ERL=`which erl || echo 'erl'`
RUN_INCLUDE_PATHS="-pa ./ebin"
MONITOR_CMD="$ERL -pa $RUN_INCLUDE_PATHS -setcookie $COOKIE -sname monitor -noshell -noinput"
MONITOR_SHUTDOWN="-run erlang halt"
SERVER_CMD="$ERL +K true $RUN_INCLUDE_PATHS -noshell -noinput -detached -sname $NODE_NAME -setcookie $RANDOM_COOKIE -heart -run flashpolicy_app start"
# force epmd to bind to loopback interface only when started by erl command
export ERL_EPMD_ADDRESS=127.0.0.1
if [ $# -ne 1 ]
then
echo "Starts or stops the flash policy server"
echo
echo "Usage: `basename $0` start|stop|status|reload|test|[enable|disable]-logging"
echo
echo "start: starts the flash policy server (detached)"
echo "stop: stops the runnning flash policy server"
echo "status: prints the server status to stdout"
echo "reload: reloads the flashpolicy.xml file"
echo "test: loads the flash policy file from the server via http"
echo "enable-logging: enables the logging of accepted connections"
echo "disable-logging: disables the logging of accepted connections"
echo
else
ACTION=$1
if [ $ACTION == "start" ]; then
echo "starting server..."
if [ $USER != "root" ]; then echo "YOU SHOULD START THE POLICY SERVER AS ROOT\n(because it usually binds to privileged prot 843)"; fi
export HEART_COMMAND=$SERVER_CMD
$SERVER_CMD
elif [ $ACTION == "stop" ]; then
$MONITOR_CMD -run flashpolicy_app shutdown $NODE_NAME $MONITOR_SHUTDOWN
elif [ $ACTION == "status" ]; then
echo "server status..."
$MONITOR_CMD -run flashpolicy_app status $NODE_NAME $MONITOR_SHUTDOWN
exit $?
elif [ $ACTION == "reload" ]; then
echo "reloading flash policy xml file..."
$MONITOR_CMD -run flashpolicy_app execute $NODE_NAME reload $MONITOR_SHUTDOWN
elif [ $ACTION == "test" ]; then
echo "loading policy file from server..."
curl -- http://127.0.0.1:843
elif [ $ACTION == "enable-logging" ]; then
echo "enabling logging..."
$MONITOR_CMD -run flashpolicy_app execute $NODE_NAME enable-logging $MONITOR_SHUTDOWN
elif [ $ACTION == "disable-logging" ]; then
echo "disabling logging..."
$MONITOR_CMD -run flashpolicy_app execute $NODE_NAME disable-logging $MONITOR_SHUTDOWN
else
$0
fi
fi