forked from bcgov/von-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage
executable file
·141 lines (121 loc) · 3.53 KB
/
manage
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
export MSYS_NO_PATHCONV=1
export DOCKERHOST=${APPLICATION_URL-$(docker run --rm --net=host codenvy/che-ip)}
set -e
SCRIPT_HOME="$( cd "$( dirname "$0" )" && pwd )"
export COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-von}"
# =================================================================================================================
# Usage:
# -----------------------------------------------------------------------------------------------------------------
usage () {
cat <<-EOF
Usage: $0 [command] [options]
Commands:
build - Build the docker images for the project.
You need to do this first.
up - Starts all containers and docker-compose logs.
Use ctrl-c to exit logging. Use "down" or "stop" to stop the run.
Examples:
$0 start
$0 start <ip_proxy_1>,<ip_proxy_2>,<ip_proxy_3>,<ip_proxy_4> &
start - Same as up
start-web - Start the web server to monitor an existing ledger, requires GENESIS_URL and LEDGER_SEED params
Example:
$0 start-web GENESIS_URL=http://foo.bar/genesis.txt LEDGER_SEED=00000000000000000000000000000012
logs - Display the logs from the docker compose run (ctrl-c to exit).
cli - Start client container
down - Brings down the services and removes the volumes (storage) and containers.
rm - Same as down
stop - Stops the services. This is a non-destructive process. The volumes and containers
are not deleted so they will be reused the next time you run start.
rebuild - Rebuild the docker images.
EOF
exit 1
}
# -----------------------------------------------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------------------------------------------
toLower() {
echo $(echo ${@} | tr '[:upper:]' '[:lower:]')
}
initEnv() {
if [ -f .env ]; then
while read line; do
if [[ ! "$line" =~ ^\# ]] && [[ "$line" =~ .*= ]]; then
export ${line//[$'\r\n']}
fi
done <.env
fi
for arg in "$@"; do
# Remove recognized arguments from the list after processing.
shift
case "$arg" in
*=*)
export "${arg}"
;;
*)
# If not recognized, save it for later procesing ...
set -- "$@" "$arg"
;;
esac
done
IP=""
IPS=""
if [[ $1 == *","* ]]; then
IPS="$1"
else
IP="$1"
fi
export IP="$IP" IPS="$IPS"
export LOG_LEVEL=${LOG_LEVEL:-info}
export RUST_LOG=${RUST_LOG:-warning}
}
# =================================================================================================================
pushd ${SCRIPT_HOME} >/dev/null
COMMAND=$(toLower ${1})
shift || COMMAND=usage
case "${COMMAND}" in
start|up)
initEnv "$@"
docker-compose up -d webserver node1 node2 node3 node4
docker-compose logs -f
;;
start-combined)
initEnv "$@"
docker-compose up -d webserver nodes
docker-compose logs -f
;;
start-web)
initEnv "$@"
if [ -z "$LEDGER_SEED" ]; then
export ANONYMOUS=1
fi
docker-compose up -d webserver
docker-compose logs -f webserver
;;
cli)
initEnv "$@"
docker-compose run --rm client
;;
logs)
initEnv "$@"
docker-compose logs -f
;;
stop)
initEnv "$@"
docker-compose stop
;;
down|rm)
initEnv "$@"
docker-compose down -v
;;
build)
docker build -t von-network-base .
;;
rebuild)
docker build --no-cache -t von-network-base .
;;
*)
usage;;
esac
popd >/dev/null