forked from tinode/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-cluster.sh
executable file
·50 lines (44 loc) · 1.48 KB
/
run-cluster.sh
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
#!/bin/bash
# Start/stop test cluster on localhost. This is NOT a production script. Use it for reference only.
# Names of cluster nodes
ALL_NODE_NAMES=( one two three )
# Port where the first node will listen for client connections over http
HTTP_BASE_PORT=6080
# Port where the first node will listen for gRPC intra-cluster connections.
GRPC_BASE_PORT=6090
# Allow for non-default config file to be specifid on the command line like config=file_name
if [ ! -z "$config" ] ; then
TINODE_CONF=$config
else
TINODE_CONF="./tinode.conf"
fi
case "$1" in
start)
echo 'Running cluster on localhost, ports 6080-6082'
HTTP_PORT=$HTTP_BASE_PORT
GRPC_PORT=$GRPC_BASE_PORT
for NODE_NAME in "${ALL_NODE_NAMES[@]}"
do
# Start the node
./server -config=${TINODE_CONF} -cluster_self=$NODE_NAME -listen=:${HTTP_PORT} -grpc_listen=:${GRPC_PORT} &
# Save PID of the node to a temp file.
# /var/tmp/ does not requre root access.
echo $!> "/var/tmp/tinode-${NODE_NAME}.pid"
# Increment ports for the next node.
HTTP_PORT=$((HTTP_PORT+1))
GRPC_PORT=$((GRPC_PORT+1))
done
;;
stop)
echo 'Stopping cluster'
for NODE_NAME in "${ALL_NODE_NAMES[@]}"
do
# Reda PIDs of running nodes from temp files and kill them.
kill `cat /var/tmp/tinode-${NODE_NAME}.pid`
# Clean up: delete temp files.
rm "/var/tmp/tinode-${NODE_NAME}.pid"
done
;;
*)
echo $"Usage: $0 {start|stop} [ config=<path_to_tinode.conf> ]"
esac