-
Notifications
You must be signed in to change notification settings - Fork 5
/
services
executable file
·67 lines (57 loc) · 1.8 KB
/
services
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
#!/usr/bin/env bash
set -u
abort() {
printf "%s" "$@"
exit 1
}
greentext() {
printf "\x1B[32m%b\e[0m\n" "$1"
}
source ./configs/pass.conf
source ./configs/env.env
BTK_SERVICES_UPGRADE=0
BTK_SERVICES_START=0
BTK_SERVICES_STOP=0
BTK_SLEEP_TIME=${SLEEP:-6}
if [[ ! -f "./.lock" ]]; then
abort "Please execute the './setup' script first."
else
if [[ ! -z $1 ]]; then
source .lock
for var in "$@"
do
[[ $var == "upgrade" ]] && BTK_SERVICES_UPGRADE=1
[[ $var == "run" || $var == "start" ]] && BTK_SERVICES_START=1
[[ $var == "stop" ]] && BTK_SERVICES_STOP=1
done
else
echo "usage: services [command]"
echo " - start: start the services specified during setup (i.e. node, rest, slp)"
echo " - stop: stops the services that are currently running"
exit 0
fi
fi
# Check that we have docker-compose installed
if [ ! -x "$(command -v docker-compose)" ]; then
echo "Docker-compose not found. Please install docker-compose."
exit 1
fi
# Ensure only one of two exclusive commands are chosen
if [[ $BTK_SERVICES_START == 1 && $BTK_SERVICES_STOP == 1 ]]; then
echo "You can't start and stop services at the same time..."
exit 1
fi
if [[ $BTK_SERVICES_START == 1 && $BTK_SERVICES_UPGRADE == 1 ]]; then
eval "docker-compose $DOCKER_ARGS pull && docker-compose $DOCKER_ARGS up -d"
fi
if [[ $BTK_SERVICES_START == 1 && $BTK_SERVICES_UPGRADE == 0 ]]; then
eval "docker-compose $DOCKER_ARGS up -d"
fi
if [[ $BTK_SERVICES_START == 0 && $BTK_SERVICES_UPGRADE == 1 ]]; then
eval "docker-compose $DOCKER_ARGS pull"
fi
if [[ $BTK_SERVICES_STOP == 1 ]]; then
eval "docker-compose $DOCKER_ARGS exec -T bch-node bitcoin-cli -conf=/bitcoin.conf stop"
sleep $BTK_SLEEP_TIME
eval "docker-compose $DOCKER_ARGS stop"
fi