forked from Someguy123/peerplays-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·219 lines (194 loc) · 4.85 KB
/
run.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
#
# Peerplays node manager
# Released under GNU AGPL by Someguy123
#
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DOCKER_DIR="$DIR/dkr"
DATADIR="$DIR/data"
DOCKER_NAME="peerplays"
BOLD="$(tput bold)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
WHITE="$(tput setaf 7)"
RESET="$(tput sgr0)"
# default. override in .env
PORTS="7777"
if [[ -f .env ]]; then
source .env
fi
if [[ ! -f data/witness_node_data_dir/config.ini ]]; then
echo "config.ini not found. copying example (seed)";
cp data/witness_node_data_dir/config.ini.example data/witness_node_data_dir/config.ini
fi
IFS=","
DPORTS=()
for i in $PORTS; do
if [[ $i != "" ]]; then
DPORTS+=("-p0.0.0.0:$i:$i")
fi
done
help() {
echo "Usage: $0 COMMAND [DATA]"
echo
echo "Commands: "
echo " start - starts peerplays container"
echo " replay - starts peerplays container (in replay mode)"
echo " shm_size - resizes /dev/shm to size given, e.g. ./run.sh shm_size 10G "
echo " stop - stops peerplays container"
echo " status - show status of peerplays container"
echo " restart - restarts peerplays container"
echo " install - pulls latest docker image from server (no compiling)"
echo " rebuild - builds peerplays container (from docker file), and then restarts it"
echo " build - only builds peerplays container (from docker file)"
echo " logs - show all logs inc. docker logs, and peerplays logs"
echo " wallet - open cli_wallet in the container"
echo " enter - enter a bash session in the container"
echo
exit
}
build() {
echo $GREEN"Building docker container"$RESET
cd $DOCKER_DIR
docker build -t peerplays .
}
install() {
# step 1, get rid of old peerplays
echo "Stopping and removing any existing peerplays containers"
docker stop peerplays
echo "Loading image from someguy123/peerplays"
docker pull someguy123/peerplays
echo "Tagging as peerplays"
docker tag someguy123/peerplays peerplays
echo "Installation completed. You may now configure or run the server"
}
seed_exists() {
seedcount=$(docker ps -a -f name="^/"$DOCKER_NAME"$" | wc -l)
if [[ $seedcount -eq 2 ]]; then
return 0
else
return -1
fi
}
seed_running() {
seedcount=$(docker ps -f 'status=running' -f name=$DOCKER_NAME | wc -l)
if [[ $seedcount -eq 2 ]]; then
return 0
else
return -1
fi
}
start() {
echo $GREEN"Starting container..."$RESET
seed_exists
if [[ $? == 0 ]]; then
docker start $DOCKER_NAME
else
docker run ${DPORTS[@]} -v /dev/shm:/shm -v "$DATADIR":/peerplays -d --name $DOCKER_NAME -t peerplays
fi
}
replay() {
echo "Removing old container"
docker rm $DOCKER_NAME
echo "Running peerplays with replay..."
docker run ${DPORTS[@]} -v /dev/shm:/shm -v "$DATADIR":/peerplays -d --name $DOCKER_NAME -t peerplays witness_node --replay
echo "Started."
}
shm_size() {
echo "Setting SHM to $1"
mount -o remount,size=$1 /dev/shm
}
stop() {
echo $RED"Stopping container..."$RESET
docker stop $DOCKER_NAME
docker rm $DOCKER_NAME
}
enter() {
docker exec -it $DOCKER_NAME bash
}
wallet() {
docker exec -it $DOCKER_NAME cli_wallet
}
logs() {
echo $BLUE"DOCKER LOGS: "$RESET
docker logs --tail=30 $DOCKER_NAME
#echo $RED"INFO AND DEBUG LOGS: "$RESET
#tail -n 30 $DATADIR/{info.log,debug.log}
}
status() {
seed_exists
if [[ $? == 0 ]]; then
echo "Container exists?: "$GREEN"YES"$RESET
else
echo "Container exists?: "$RED"NO (!)"$RESET
echo "Container doesn't exist, thus it is NOT running. Run $0 build && $0 start"$RESET
return
fi
seed_running
if [[ $? == 0 ]]; then
echo "Container running?: "$GREEN"YES"$RESET
else
echo "Container running?: "$RED"NO (!)"$RESET
echo "Container isn't running. Start it with $0 start"$RESET
return
fi
}
if [ "$#" -lt 1 ]; then
help
fi
case $1 in
build)
echo "You may want to use '$0 install' for a binary image instead, it's faster."
build
;;
install)
install
;;
start)
start
;;
replay)
replay
;;
shm_size)
shm_size $2
;;
stop)
stop
;;
restart)
stop
sleep 5
start
;;
rebuild)
stop
sleep 5
build
start
;;
optimize)
echo "Applying recommended dirty write settings..."
optimize
;;
status)
status
;;
wallet)
wallet
;;
enter)
enter
;;
logs)
logs
;;
*)
echo "Invalid cmd"
help
;;
esac