-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiple-nodes
executable file
·88 lines (81 loc) · 3.4 KB
/
multiple-nodes
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
##
# Start/stop multiple Platformer nodes at once
#
USAGE="usage: $0 [options] {start|stop|restart|status}"
. /lib/lsb/init-functions || (echo "Missing LSB init-functions; this script won't work right." && exit 1)
BASE_DIR=$(cd `dirname $0` && pwd)
COMMAND="$BASE_DIR/platformer"
PRIV_DIR="$BASE_DIR/priv"
# Defaults
NODE_COUNT=2
START_PORT=8000
CONFIG="platformer_node"
LOG_CONFIG="log-errors"
ARGS="--background"
set -- `getopt --options C:s:rc:l:qh --longoptions count:,start:,reset-db,config:,log-config:,quiet,help --unquoted -- "$@"`
while [ $# -gt 0 ]; do
case "$1" in
-C|--count) NODE_COUNT=$2; shift;;
-s|--start) START_PORT=$2; shift;;
-c|--config) ARGS="$ARGS --config=$2"; shift;;
-L|--log-config) ARGS="$ARGS --log-config=$2"; shift;;
-r|--reset-db) ARGS="$ARGS --reset-db";;
-q|--quiet) QUIET="quiet" ; ARGS="$ARGS --quiet";;
-h|--help)
echo $USAGE;
echo "options (specify any or none):"
echo "-C|--count=NUMBER how many Platformer nodes to start (default: $NODE_COUNT)"
echo "-s|--start=PORT the port number to start with (default: $START_PORT)"
echo "-r|--reset-db reset the database(s) on startup"
echo "-c|--config=NAME read application configuration from NAME.config (default: $APP_CONFIG)"
echo "-L|--log-config=NAME read logging configuration from NAME.config (default: $LOG_CONFIG)"
echo "-q|--quiet don't print any messages about starting and stopping"
echo "-h|--help print this help message"
echo
echo "command (specify one):"
echo "start start the specified Platformer nodes"
echo "stop stop the specified Platformer nodes"
echo "restart restart the specified Platformer nodes"
echo "status check whether the specified Platformer nodes are running"
shift
exit 0;;
--) shift; break;;
*) echo >&2 $USAGE; exit 1;;
esac
shift
done
END_PORT=$(( $START_PORT + $NODE_COUNT - 1 ))
case "$@" in
start)
if [ -z "$QUIET" ]; then
log_action_msg "Starting $NODE_COUNT Platformer nodes, beginning at port $START_PORT."
fi
for PORT in $(seq $START_PORT $END_PORT ); do
$COMMAND $ARGS --port=$PORT start
done
;;
stop)
if [ -z "$QUIET" ]; then
log_action_msg "Stopping $NODE_COUNT Platformer nodes."
fi
for PORT in $(seq $START_PORT $END_PORT); do
$COMMAND $ARGS --port=$PORT stop
done
;;
restart)
if [ -z "$QUIET" ]; then
log_action_msg "Restarting $NODE_COUNT Platformer nodes."
fi
for PORT in $(seq $START_PORT $END_PORT); do
$COMMAND $ARGS --port=$PORT restart
done
;;
status)
for PORT in $(seq $START_PORT $END_PORT); do
$COMMAND $ARGS --port=$PORT status
done
;;
*)
echo >&2 $USAGE; exit 1;;
esac