-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·2140 lines (1951 loc) · 79.1 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
################################################################################
# Peerplays node manager #
# Released under GNU AGPL by Someguy123 #
################################################################################
BOLD="" RED="" GREEN="" YELLOW="" BLUE="" MAGENTA="" CYAN="" WHITE="" RESET=""
if [ -t 1 ]; then
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)"
fi
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
: "${DOCKER_DIR=$DIR/peerplays-docker/dkr}"
: "${FULL_DOCKER_DIR=$DIR/dkr_fullnode}"
: "${DATADIR=$DIR/peerplays-docker/data}"
: "${DOCKER_NAME="peerplays"}"
: "${DOCKER_BITCOIN_NAME="bitcoind-node"}"
: "${DOCKER_BITCOIN_VOLUME="bitcoind-data"}"
: "${BITCOIN_DOCKER_TAG="kylemanna/bitcoind"}"
: "${DOCKER_NETWORK="son"}"
: "${BITCOIN_WALLET="son-wallet"}"
: "${BTC_REGTEST_KEY="cSKyTeXidmj93dgbMFqgzD7yvxzA7QAYr5j9qDnY9seyhyv7gH2m"}"
: "${DKR_DATA_MOUNT="/peerplays"}" # Mount $DATADIR onto this folder within the container
: "${DKR_SHM_MOUNT="/shm"}" # Mount $SHM_DIR onto this folder within the container
: "${DKR_RUN_BIN="witness_node"}" # Run this executable within the container
# the tag to use when running/replaying peerplaysd
: "${DOCKER_IMAGE="peerplays"}"
: "${PEERPLAYS_DOCKER_TAG="datasecuritynode/peerplays:latest"}"
# Amount of time in seconds to allow the docker container to stop before killing it.
# Default: 600 seconds (10 minutes)
: "${STOP_TIME=60}"
# Git repository to use when building Steem - containing peerplaysd code
: "${PEERPLAYS_SOURCE="https://github.com/peerplays-network/peerplays.git"}"
: "${PEERPLAYS_DOCKER_SOURCE="https://gitlab.com/PBSA/PeerplaysIO/tools-libs/peerplays-docker.git"}"
# Comma separated list of ports to expose to the internet.
# By default, only port 9777 will be exposed (the P2P seed port)
: "${PORTS="9777"}"
# Internal variable. Set to 1 by build_full to inform child functions
BUILD_FULL=0
# Placeholder for custom tag var CUST_TAG (shared between functions)
CUST_TAG="peerplays"
# Placeholder for BUILD_VER shared between functions
BUILD_VER=""
# blockchain folder, used by dlblocks
: "${BC_FOLDER=$DATADIR/witness_node_data_dir/blockchain}"
: "${EXAMPLE_MIRA=$DATADIR/witness_node_data_dir/database.cfg.example}"
: "${MIRA_FILE=$DATADIR/witness_node_data_dir/database.cfg}"
: "${EXAMPLE_CONF=$DATADIR/witness_node_data_dir/config.ini.example}"
: "${CONF_FILE=$DATADIR/witness_node_data_dir/config.ini}"
# Array of additional arguments to be passed to Docker during builds
# Generally populated using arguments passed to build/build_full
# But you can specify custom additional build parameters by setting BUILD_ARGS
# as an array in .env
# e.g.
#
# BUILD_ARGS=('--rm' '-q' '--compress')
#
BUILD_ARGS=()
# easy coloured messages function
# written by @someguy123
function msg() {
if [[ "$#" -eq 0 ]]; then
echo ""
return
fi
if [[ "$#" -eq 1 ]]; then
echo -e "$1"
return
fi
_msg=""
if ((MSG_TS_DEFAULT == 1)); then
[[ "$1" == "ts" ]] && shift
{ [[ "$1" == "nots" ]] && shift; } || _msg="[$(date +'%Y-%m-%d %H:%M:%S %Z')] "
else
[[ "$1" == "nots" ]] && shift
[[ "$1" == "ts" ]] && shift && _msg="[$(date +'%Y-%m-%d %H:%M:%S %Z')] "
fi
if [[ "$#" -gt 2 ]] && [[ "$1" == "bold" ]]; then
echo -n "${BOLD}"
shift
fi
(($# == 1)) && _msg+="$@" || _msg+="${@:2}"
case "$1" in
bold) echo -e "${BOLD}${_msg}${RESET}" ;;
BLUE | blue) echo -e "${BLUE}${_msg}${RESET}" ;;
YELLOW | yellow) echo -e "${YELLOW}${_msg}${RESET}" ;;
RED | red) echo -e "${RED}${_msg}${RESET}" ;;
GREEN | green) echo -e "${GREEN}${_msg}${RESET}" ;;
CYAN | cyan) echo -e "${CYAN}${_msg}${RESET}" ;;
MAGENTA | magenta | PURPLE | purple) echo -e "${MAGENTA}${_msg}${RESET}" ;;
*) echo -e "${_msg}" ;;
esac
}
export -f msg
export RED GREEN YELLOW BLUE BOLD NORMAL RESET
if [[ -f .env ]]; then
source .env
fi
# blockchain folder, used by dlblocks
: "${BC_FOLDER=$DATADIR/witness_node_data_dir/blockchain}"
: "${EXAMPLE_MIRA=$DATADIR/witness_node_data_dir/database.cfg.example}"
: "${MIRA_FILE=$DATADIR/witness_node_data_dir/database.cfg}"
: "${EXAMPLE_CONF=$DATADIR/witness_node_data_dir/config.ini.example}"
: "${CONF_FILE=$DATADIR/witness_node_data_dir/seed_config.ini}"
# full path to btc regtest config
: "${BTC_REGTEST_CONF="/var/opt/peerplays-docker/bitcoin/regtest/bitcoin.conf"}"
# if the config file doesn't exist, try copying the example config
#if [[ ! -f "$CONF_FILE" ]]; then
# if [[ -f "$EXAMPLE_CONF" ]]; then
# echo "${YELLOW}File config.ini not found. copying example (seed)${RESET}"
# cp -vi "$EXAMPLE_CONF" "$CONF_FILE"
# echo "${GREEN} > Successfully installed example config for seed node.${RESET}"
# echo " > You may want to adjust this if you're running a witness, e.g. disable p2p-endpoint"
# else
# echo "${YELLOW}WARNING: You don't seem to have a config file and the example config couldn't be found...${RESET}"
# echo "${YELLOW}${BOLD}You may want to check these files exist, or you won't be able to launch Peerplays${RESET}"
# echo "Example Config: $EXAMPLE_CONF"
# echo "Main Config: $CONF_FILE"
# fi
#fi
IFS=","
DPORTS=()
for i in $PORTS; do
if [[ $i != "" ]]; then
if grep -q ":" <<<"$i"; then
DPORTS+=("-p$i")
else
DPORTS+=("-p0.0.0.0:$i:$i")
fi
fi
done
if ! ((${#DKR_VOLUMES[@]})); then
DKR_VOLUMES=(
"${SHM_DIR}:${DKR_SHM_MOUNT}"
"${DATADIR}:${DKR_DATA_MOUNT}"
)
fi
if ((${#EXTRA_VOLUMES[@]})); then
IFS="," read -r -a _EXTRA_VOLS <<<"$EXTRA_VOLUMES"
DKR_VOLUMES+=("${_EXTRA_VOLS[@]}")
fi
# load docker hub API
#source scripts/000_docker.sh
help() {
clear
echo "Usage: $0 COMMAND"
echo
echo "Commands:
$(msg bold "#---WITNESS NODE AS SERVICE---#")
$(msg "witness_install") - Builds, Installs and Starts the Peerplays Blockchain as a Service
$(msg "witness_install_only") - Builds, Installs Peerplays Blockchain (Manual Start)
$(msg bold "#---WITNESS NODE AS DOCKER CONTAINER---#")
$(msg "witness_docker_install") - installs and starts ${DOCKER_NAME} witness docker container
$(msg "build") - builds a Peerplays witness docker image from source code
$(msg "start") - starts the ${DOCKER_NAME} witness docker container
$(msg "stop") - stops ${DOCKER_NAME} witness docker container
$(msg "kill") - force stop ${DOCKER_NAME} witness docker container (in event of ${DOCKER_NAME} container hanging indefinitely)
$(msg "restart") - restarts ${DOCKER_NAME} witness docker container
$(msg "status") - show status of ${DOCKER_NAME} witness docker container
$(msg bold "#---SEED NODE AS DOCKER CONTAINER---#")
$(msg "seed_docker_install") - installs and starts ${DOCKER_NAME} seed docker container
$(msg "start") - starts the ${DOCKER_NAME} seed docker container
$(msg "stop") - stops ${DOCKER_NAME} seed docker container
$(msg "kill") - force stop ${DOCKER_NAME} seed docker container (in event of ${DOCKER_NAME} container hanging indefinitely)
$(msg "restart") - restarts ${DOCKER_NAME} seed docker container
$(msg "status") - show status of ${DOCKER_NAME} seed docker container
$(msg bold "#---SON AS DOCKER CONTAINER---#")
$(msg "son_docker_install") - installs and starts ${DOCKER_NAME} SON docker container
$(msg "son_docker_regtest_install") - installs and starts ${DOCKER_NAME} SON docker container in test mode
$(msg "start") - starts the ${DOCKER_NAME} SON docker container
$(msg "stop") - stops ${DOCKER_NAME} SON docker container
$(msg "kill") - force stop ${DOCKER_NAME} SON docker container (in event of ${DOCKER_NAME} container hanging indefinitely)
$(msg "restart") - restarts ${DOCKER_NAME} SON docker container
$(msg "status") - show status of ${DOCKER_NAME} SON docker container
$(msg bold "#---Common commands---#")
$(msg "logs") - shows the logs related to Peerplays Blockchain
$(msg "uninstall") - uninstalls the Peerplays Blockchain installation
$(msg "replay") - starts replay of the installed Peerplays Blockchain installation
$(msg "shm_size") - Resizes the ramdisk used for storing Peerplays's shared_memory at /dev/shm (ex: ./run.sh shm_size 64G)
"
echo
exit
}
####SON NODE COMMANDS#######
# start - starts seed container
# start_son - starts son seed container
# start_son_regtest - starts son seed container and bitcoind container under the docker network
# replay_son - starts son seed container (in replay mode)
# stop - stops seed container
# status - show status of seed container
# restart - restarts seed container
# install_docker - install docker
# install_full - pulls latest (FULL NODE FOR RPC)
############################
APT_UPDATED="n"
pkg_not_found() {
# check if a command is available
# if not, install it from the package specified
# Usage: pkg_not_found [cmd] [apt-package]
# e.g. pkg_not_found git git
if [[ $# -lt 2 ]]; then
echo "${RED}ERR: pkg_not_found requires 2 arguments (cmd) (package)${NORMAL}"
exit
fi
local cmd=$1
local pkg=$2
if ! [ -x "$(command -v $cmd)" ]; then
echo "${YELLOW}WARNING: Command $cmd was not found. installing now...${NORMAL}"
if [[ "$APT_UPDATED" == "n" ]]; then
sudo apt update -y
APT_UPDATED="y"
fi
sudo apt install -y "$pkg"
fi
}
optimize() {
echo 75 | sudo tee /proc/sys/vm/dirty_background_ratio
echo 1000 | sudo tee /proc/sys/vm/dirty_expire_centisecs
echo 80 | sudo tee /proc/sys/vm/dirty_ratio
echo 30000 | sudo tee /proc/sys/vm/dirty_writeback_centisecs
}
parse_build_args() {
BUILD_VER=$1
CUST_TAG="peerplays:$BUILD_VER"
if (($BUILD_FULL == 1)); then
CUST_TAG+="-full"
fi
BUILD_ARGS+=('--build-arg' "peerplaysd=${BUILD_VER}")
shift
if (($# >= 2)); then
if [[ "$1" == "tag" ]]; then
CUST_TAG="$2"
msg yellow " >> Custom re-tag specified. Will tag new image with '${CUST_TAG}'"
shift
shift # Get rid of the two tag arguments. Everything after is now build args
fi
fi
local has_peerplays_src='n'
if (($# >= 1)); then
msg yellow " >> Additional build arguments specified."
for a in "$@"; do
msg yellow " ++ Build argument: ${BOLD}${a}"
BUILD_ARGS+=('--build-arg' "$a")
if grep -q 'PEERPLAYS_SOURCE' <<<"$a"; then
has_peerplays_src='y'
fi
done
fi
if [[ "$has_peerplays_src" == "y" ]]; then
msg bold yellow " [!!] PEERPLAYS_SOURCE has been specified in the build arguments. Using source from build args instead of global"
else
msg bold yellow " [!!] Did not find PEERPLAYS_SOURCE in build args. Using PEERPLAYS_SOURCE from environment:"
msg bold yellow " [!!] PEERPLAYS_SOURCE = ${PEERPLAYS_SOURCE}"
BUILD_ARGS+=('--build-arg' "PEERPLAYS_SOURCE=${PEERPLAYS_SOURCE}")
fi
msg blue " ++ CUSTOM BUILD SPECIFIED. Building from branch/tag ${BOLD}${BUILD_VER}"
msg blue " ++ Tagging final image as: ${BOLD}${CUST_TAG}"
msg yellow " -> Docker build arguments: ${BOLD}${BUILD_ARGS[@]}"
}
build_local() {
PEERPLAYS_SOURCE="local_src_folder"
DOCKER_DIR="${DIR}/dkr_local"
if [[ ! -d "${DOCKER_DIR}/src" ]]; then
msg bold red "ERROR: You must place the source code inside of ${DOCKER_DIR}/src"
return 1
fi
msg green " >>> Local build requested."
msg green " >>> Will build Peerplays using code stored in '${DOCKER_DIR}/src' instead of remote git repo"
build "$@"
}
# Build standard low memory node as a docker image
# Usage: ./run.sh build [version] [tag tag_name] [build_args]
# Version is prefixed with v, matching Peerplays releases
# e.g. build v0.20.6
#
# Override destination tag:
# ./run.sh build v0.21.0 tag 'peerplays:latest'
#
# Additional build args:
# ./run.sh build v0.21.0 ENABLE_MIRA=OFF
#
# Or combine both:
# ./run.sh build v0.21.0 tag 'steem:mira' ENABLE_MIRA=ON
#
build() {
read -r -p "Enter Peerplays blockchain repository branch/tag to be used for building the docker image [Press Enter for default: master]: " BRANCH
BRANCH=${BRANCH:-master}
read -r -p "Enter the docker image name[Press Enter for default: peerplays]: " PEERPLAYS_IMAGE
PEERPLAYS_IMAGE=${PEERPLAYS_IMAGE:-peerplays}
read -r -p "Enter the tag name to be used for the docker image[Press Enter for default: latest]: " PEERPLAYS_IMAGE_TAG
PEERPLAYS_IMAGE_TAG=${PEERPLAYS_IMAGE_TAG:-latest}
PEERPLAYS_DOCKER_TAG="$PEERPLAYS_IMAGE:$PEERPLAYS_IMAGE_TAG"
{
echo -e "BRANCH=$BRANCH"
echo -e "PEERPLAYS_IMAGE_TAG=$PEERPLAYS_IMAGE_TAG"
echo -e "PEERPLAYS_IMAGE=$PEERPLAYS_IMAGE"
echo -e "PEERPLAYS_DOCKER_TAG=$PEERPLAYS_DOCKER_TAG"
} >>$HOME/.install_setting
msg bold blue "Downloading Peerplays blockchain source code"
git clone "${PEERPLAYS_DOCKER_SOURCE}"
fmm="Low Memory Mode (For Seed / Witness nodes)"
(($BUILD_FULL == 1)) && fmm="Full Memory Mode (For RPC nodes)" && DOCKER_DIR="$FULL_DOCKER_DIR"
BUILD_MSG=" >> Building docker container [[ ${fmm} ]]"
if (($# >= 1)); then
"$@"
sleep 2
sudo cp ./peerplays-docker/data/witness_node_data_dir/config.ini.example ./peerplays-docker/data/witness_node_data_dir/config.ini
sed -i.tmp 's/^required-participation\ \=\ .*$/required-participation\ \=\ false/' "$DATADIR"/witness_node_data_dir/config.ini
sed -i "s/ARG\ PEERPLAYS_VERSION=.*$/ARG\ PEERPLAYS_VERSION="$BRANCH"/" "$DOCKER_DIR"/Dockerfile
cd "$DOCKER_DIR" || exit
msg bold green "$BUILD_MSG"
sudo docker build "${BUILD_ARGS[@]}" -t "$PEERPLAYS_DOCKER_TAG" .
ret=$?
if (($ret == 0)); then
echo "${RED}
!!! !!! !!! !!! !!! !!! READ THIS !!! !!! !!! !!! !!! !!!
!!! !!! !!! !!! !!! !!! READ THIS !!! !!! !!! !!! !!! !!!
For your safety, we've tagged this image as $PEERPLAYS_DOCKER_TAG
To use it in this peerplays-docker, run:
${GREEN}${BOLD}
docker tag $PEERPLAYS_DOCKER_TAG ${DOCKER_IMAGE}:latest
${RESET}${RED}
!!! !!! !!! !!! !!! !!! READ THIS !!! !!! !!! !!! !!! !!!
!!! !!! !!! !!! !!! !!! READ THIS !!! !!! !!! !!! !!! !!!
${RESET}
"
msg bold green " +++ Successfully built peerplaysd"
msg green " +++ Peerplays node type: ${BOLD}${fmm}"
msg green " +++ Version/Branch: ${BOLD}${BUILD_VER}"
msg green " +++ Build args: ${BOLD}${BUILD_ARGS[@]}"
msg green " +++ Docker tag: ${PEERPLAYS_DOCKER_TAG}"
else
msg bold red " !!! ERROR: Something went wrong during the build process."
msg red " !!! Please scroll up and check for any error output during the build."
fi
return
fi
msg bold green "$BUILD_MSG"
cd "$DOCKER_DIR" || exit
sudo docker build -t "$DOCKER_IMAGE" .
ret=$?
if (($ret == 0)); then
msg bold green " +++ Successfully built current stable peerplaysd"
msg green " +++ Peerplays node type: ${BOLD}${fmm}"
msg green " +++ Docker tag: ${DOCKER_IMAGE}"
msg bold green " Run ./run.sh start to start the Peerplays witness node"
else
msg bold red " !!! ERROR: Something went wrong during the build process."
msg red " !!! Please scroll up and check for any error output during the build."
fi
}
sci() {
read -r -p "Enter docker image to be saved locally[Press Enter for default: peerplays:latest]: " PEERPLAYS_DOCKER_TAG
PEERPLAYS_DOCKER_TAG=${PEERPLAYS_DOCKER_TAG:-"peerplays:latest"}
read -r -p "Enter the directory where you want to save the Peerplays docker image [Press Enter for default: $PWD]: " SAVE_TO_DIRECTORY
if [ -z "$SAVE_TO_DIRECTORY" ]; then
SAVE_TO_DIRECTORY=$PWD
else
SAVE_TO_DIRECTORY=$(realpath "$SAVE_TO_DIRECTORY")
fi
msg bold blue "Saving the docker image !!!"
if sudo docker save -o $SAVE_TO_DIRECTORY/peerplays_docker-image.tar "$PEERPLAYS_DOCKER_TAG"; then
msg bold green "Saving the docker image $SAVE_TO_DIRECTORY/peerplays_docker-image.tar completed successfully"
msg bold blue "Follow the following steps if you want to load the docker image on a new machine"
msg bold blue "Run the command--> git clone https://gitlab.com/PBSA/PeerplaysIO/tools-libs/peerplays-docker && cd peerplays-docker"
msg bold blue "Copy peerplays_docker-image.tar to the current working directory"
msg bold blue "Run the command--> sudo docker load -i ./peerplays_docker-image.tar"
msg bold blue "To run the peerplays docker container --> sudo docker run -p0.0.0.0:9777:9777 -v /dev/shm:/shm -v $PWD/data:/peerplays -d --name peerplays -t <DOCKER image> witness_node --data-dir=/peerplays/witness_node_data_dir"
else
msg bold green "Saving the docker image faile!!!"
fi
}
# Build full memory node (for RPC nodes) as a docker image
# Usage: ./run.sh build_full [version]
# Version is prefixed with v, matching steem releases
# e.g. build_full v0.20.6
build_full() {
BUILD_FULL=1
build "$@"
}
# Usage: ./run.sh install_docker
# Downloads and installs the latest version of Docker using the Get Docker site
# If Docker is already installed, it should update it.
install_docker() {
clear
#figlet -tc "Peerplays Blockchain"
msg bold green "Installing docker on the machine"
sudo apt update
# curl/git used by docker, xz/lz4 used by dlblocks, jq used by tslogs/pclogs
sudo apt install -y curl git xz-utils liblz4-tool jq
curl https://get.docker.com | sh
if [ "$EUID" -ne 0 ]; then
echo "Adding user $(whoami) to docker group"
sudo usermod -aG docker "$(whoami)"
echo "IMPORTANT: Please re-login (or close and re-connect SSH) for docker to function correctly"
fi
}
# Usage: ./run.sh install [tag]
# Downloads the Steem low memory node image from someguy123's official builds, or a custom tag if supplied
#
# tag - optionally specify a docker tag to install from. can be third party
# format: user/repo:version or user/repo (uses the 'latest' tag)
#
# If no tag specified, it will download the pre-set $DK_TAG in run.sh or .env
# Default tag is normally someguy123/steem:latest (official builds by the creator of steem-docker).
#
install() {
clear
#figlet -tc "Peerplays Blockchain"
read -r -p "Enter Peerplays docker tag which you want to use for the docker container[Press Enter for default: latest]: " PEERPLAYS_IMAGE_TAG
PEERPLAYS_IMAGE_TAG=${PEERPLAYS_IMAGE_TAG:-latest}
PEERPLAYS_DOCKER_TAG="datasecuritynode/peerplays:$PEERPLAYS_IMAGE_TAG"
echo "Enter the seed nodes"
REPEAT=true
i=1
SEED_NODES=
while $REPEAT; do
read -r -p " seed node $i----> eg. 10.10.10.10:1234 ]: " SEED_NODES[$i]
if [ -z "${SEED_NODES}" ]; then
SEED_NODES="\"${SEED_NODES[$i]}\""
else
SEED_NODES="${SEED_NODES},\"${SEED_NODES[$i]}\""
fi
read -r -p "Do you wish to add more nodes? (Y/N) ]: " REPEAT
if [[ "$REPEAT" = "Y" ]]; then
REPEAT=true
i=$((i+1))
else
REPEAT=false
fi
done
SEED_COUNT=$i
{ echo -e "SEED_NODES=$SEED_NODES"; echo -e "SEED_COUNT=$SEED_COUNT"; } >>"$HOME"/.install_setting
unset i SEED_COUNT REPEAT
{ echo -e "PEERPLAYS_IMAGE_TAG=$PEERPLAYS_IMAGE_TAG"; echo -e "PEERPLAYS_DOCKER_TAG=$PEERPLAYS_DOCKER_TAG"; } >>"$HOME"/.install_setting
git clone "${PEERPLAYS_DOCKER_SOURCE}" -b release
sudo cp ./peerplays-docker/data/witness_node_data_dir/config.ini.example ./peerplays-docker/data/witness_node_data_dir/config.ini
sed -i.tmp 's/^required-participation\ \=\ .*$/required-participation\ \=\ false/' "$DATADIR"/witness_node_data_dir/config.ini
sed -i.tmp "s/^seed-nodes\ \=\ .*$/seed-nodes\ \=\ \[$SEED_NODES\]/" "$DATADIR"/witness_node_data_dir/config.ini
msg bold green "Installing image $PEERPLAYS_IMAGE_TAG"
sleep 2
msg yellow " -> Loading image from ${PEERPLAYS_DOCKER_TAG}"
sudo docker pull "$PEERPLAYS_DOCKER_TAG"
msg green " -> Tagging as peerplays"
sudo docker tag "$PEERPLAYS_DOCKER_TAG" peerplays
msg bold green " -> Installation completed. You may now configure or run the server"
}
# Usage: ./run.sh install_full
# Downloads the Steem full node image from the pre-set $DK_TAG_FULL in run.sh or .env
# Default tag is normally someguy123/steem:latest-full (official builds by the creator of steem-docker).
#
install_full() {
msg yellow " -> Loading image from ${DK_TAG_FULL}"
docker pull "$DK_TAG_FULL"
msg green " -> Tagging as steem"
docker tag "$DK_TAG_FULL" steem
msg bold green " -> Installation completed. You may now configure or run the server"
}
# Internal Use Only
# Checks if the container $DOCKER_NAME exists. Returns 0 if it does, -1 if not.
# Usage:
# if seed_exists; then echo "true"; else "false"; fi
#
seed_exists() {
seedcount=$(sudo docker ps -a -f name="^/"$DOCKER_NAME"$" | wc -l)
if [[ $seedcount -eq 2 ]]; then
return 0
else
return -1
fi
}
# Internal Use Only
# Checks if the container $DOCKER_NAME exists. Returns 0 if it does, -1 if not.
# Usage:
# if bitcoin_exists; then echo "true"; else "false"; fi
#
bitcoin_exists() {
bitcoindcount=$(sudo docker ps -a -f name="^/"$DOCKER_BITCOIN_NAME"$" | wc -l)
if [[ $bitcoindcount -eq 2 ]]; then
return 0
else
return -1
fi
}
# Internal Use Only
# Checks if the container $DOCKER_NAME is running. Returns 0 if it's running, -1 if not.
# Usage:
# if seed_running; then echo "true"; else "false"; fi
#
seed_running() {
seedcount=$(sudo docker ps -f 'status=running' -f "name=$DOCKER_NAME" | wc -l)
if [[ $seedcount -eq 2 ]]; then
return 0
else
return 1
fi
}
# stop_seed_running [stop_or_exit=1]
# If the container is running, alert the user and ask if they want to stop the container now.
# By default, if the user says no, 'exit 1' will be called to terminate the script.
#
# If you pass 0 or 'no' as the first argument, then instead of force exiting, a warning will
# be displayed to the user warning that not stopping the container is unsafe, and giving them
# 10 seconds to press CTRL-C in-case they change their minds. Once the 10 second wait is over,
# the function simply returns exit code 1, for the callee function to appropriately handle.
#
stop_seed_running() {
local stop_or_exit=1
(($# > 0)) && stop_or_exit="$1"
if seed_running; then
msg err red "WARNING: Your $DOCKER_NAME server ($DOCKER_NAME) is currently running"
echo
sudo docker ps
echo
read -r -p "Do you want to stop the container now? (y/n): " RESPONSE
RESPONSE=${RESPONSE:-N}
RESPONSE_IC="$(echo "$RESPONSE" | tr '[:lower:]' '[:upper:]')"
if [ "$RESPONSE_IC" == "Y" ]; then
stop
else
msg red "You said no. Cannot continue safely without stopping the container first. Aborting."
exit 1
fi
else
return 0
fi
}
# remove_seed_exists [stop_or_exit=1]
# Remove the container DOCKER_NAME if it exists, calling 'stop_seed_running' beforehand to ensure
# that the container is stopped.
#
# The first argument, 'stop_or_exit' is passed through to stop_seed_running. See comments for
# that function for info on that.
remove_seed_exists() {
local stop_or_exit=1
(($# > 0)) && stop_or_exit="$1"
stop_seed_running "$stop_or_exit"
if seed_exists; then
msg yellow " -> Removing old container '${DOCKER_NAME}'"
sudo docker rm "$DOCKER_NAME"
fi
}
# docker_run_node [steemd extra arguments]
# Create and start a container to run DKR_RUN_BIN (usually `steemd`), appending any arguments from this
# function to the steemd command line arguments.
#
# When ran without arguments, should produce a command which looks like:
# docker run -p 0.0.0.0:2001:2001 -v /hive/data:/steem -d --name $DOCKER_NAME
# -t $DOCKER_IMAGE steemd --data-dir=/steem/witness_node_data_dir
docker_run_node() {
: "${DKR_RUN_ADD_DATA_DIR=1}"
local stm_run_args=()
#(( DKR_RUN_ADD_DATA_DIR )) && stm_run_args+=("--data-dir=${DATADIR}")
((DKR_RUN_ADD_DATA_DIR)) && stm_run_args+=("--data-dir=${DATADIR}/witness_node_data_dir")
stm_run_args+=("${STEEM_RUN_ARGS[@]}" "$@")
_docker_run "${DKR_RUN_BIN}" "${stm_run_args[@]}"
}
docker_run_wallet() {
local ws_node="$REMOTE_WS"
(($# > 0)) && ws_node="$1"
_docker_int_autorm cli_wallet -s "$ws_node" "${@:2}"
}
# docker_run_base [image_executable] [exe_args]
# Works the same as _docker_run, but defaults the following env variables to 0 instead
# of the default 1 set by _docker_run:
#
# RUN_DETACHED DKR_USE_NAME DKR_MOUNT_VOLS DKR_EXPOSE_PORTS
#
_docker_run_base() {
: "${RUN_DETACHED=0}"
: "${DKR_USE_NAME=0}"
: "${DKR_MOUNT_VOLS=0}"
: "${DKR_EXPOSE_PORTS=0}"
_docker_run "$@"
}
# docker_int_autorm [image_executable] [exe_args]
# _docker_run_base wrapper for "interactive auto-removing" containers.
# Mostly the same as _docker_run_base, except DKR_MOUNT_VOLS defaults to 1,
# and the docker args '--rm' and '-i' are appended to DKR_RUN_ARGS
_docker_int_autorm() {
: "${DKR_MOUNT_VOLS=1}"
DKR_RUN_ARGS=("--rm" "-i")
_docker_run_base "$@"
}
# docker_run [image_executable] [exe_args]
# Creates and starts a docker container with `docker run`, while automatically
# building parts of the command for mounting volumes / exposing ports etc.
# based on env vars such as `DKR_VOLUMES`, `DPORTS`, and others.
#
# Example:
# _docker_run steemd --data-dir=/steem/witness_node_data_dir
# RUN_DETACHED=0 DKR_USE_NAME=0 DKR_EXPOSE_PORTS=0 _docker_run cli_wallet -s "wss://hived.privex.io"
#
_docker_run() {
local x_run_args=("$@")
_CMD=(
sudo docker run
)
: "${RUN_DETACHED=1}"
: "${DKR_USE_NAME=1}"
: "${DKR_MOUNT_VOLS=1}"
: "${DKR_EXPOSE_PORTS=1}"
echo "PORTS" "$DKR_EXPOSE_PORTS"
echo "COMMAND" "$_CMD"
((DKR_EXPOSE_PORTS)) && _CMD+=("${DPORTS[@]}")
if ((DKR_MOUNT_VOLS)); then
# Iterate over DKR_VOLUMES to generate docker volume mount arguments
for v in "${DKR_VOLUMES[@]}"; do
_CMD+=("-v" "$v")
done
fi
((RUN_DETACHED)) && _CMD+=('-d')
((${#DKR_RUN_ARGS[@]} > 0)) && _CMD+=("${DKR_RUN_ARGS[@]}")
((DKR_USE_NAME)) && _CMD+=("--name" "$DOCKER_NAME")
_CMD+=("-t" "$PEERPLAYS_DOCKER_TAG")
((${#x_run_args[@]} > 0)) && _CMD+=("${x_run_args[@]}")
if ((DKR_DRY_RUN)); then
echo "Would've ran the following command:"
echo "${_CMD[@]}"
else
env "${_CMD[@]}"
fi
}
# Usage: ./run.sh start
# Creates and/or starts the Steem docker container
start() {
msg bold green " -> Starting container '${DOCKER_NAME}'..."
PEERPLAYS_DOCKER_TAG="$(grep PEERPLAYS_DOCKER_TAG "$HOME"/.install_setting | awk -F= '{print $2}')"
seed_exists
if [[ $? == 0 ]]; then
if sudo docker start "$DOCKER_NAME"; then
msg bold green "Witness node started, now you can view the logs using ./run.sh logs"
else
msg bold red "Witness node docker container failed to start!!!"
exit
fi
else
CHECK_MODE=$(grep MODE "$HOME"/.install_setting | awk -F= '{print $2}')
if [ "$CHECK_MODE" = "WITNESS_DOCKER" ]; then
if sudo docker run "${DPORTS[@]}" -v "$SHM_DIR":/shm -v "$DATADIR":/peerplays -d --name "$DOCKER_NAME" -t "$PEERPLAYS_DOCKER_TAG" witness_node --data-dir=/peerplays/witness_node_data_dir; then
msg bold green "Peerplays witness docker container started successfully, now you can view the logs using ./run.sh logs"
else
msg bold red "Peerplays witness node docker container failed to start!!!"
exit
fi
elif [ "$CHECK_MODE" = "SON_DOCKER" ]; then
if sudo docker run "${DPORTS[@]}" --entrypoint /peerplays/son-entrypoint.sh --network ${DOCKER_NETWORK} -v "$SHM_DIR":/shm -v "$DATADIR":/peerplays -d --name $DOCKER_NAME -t datasecuritynode/peerplays:son-dev witness_node --data-dir=/peerplays/witness_node_data_dir; then
msg bold green "Peerplays SON docker container started successfully, you can view the logs using ./run.sh logs"
else
msg bold red "Peerplays SON docker container failed to start!!!"
exit
fi
elif [ "$CHECK_MODE" = "SON_TEST_DOCKER" ]; then
if sudo docker run "${DPORTS[@]}" --network ${DOCKER_NETWORK} -v "$SHM_DIR":/shm -v "$DATADIR":/peerplays -d --name $DOCKER_NAME -t datasecuritynode/peerplays:son-dev witness_node --data-dir=/peerplays/witness_node_data_dir; then
msg bold green "Peerplays SON docker container(test mode) started successfully, you can view the logs using ./run.sh logs"
else
msg bold red "Peerplays SON docker container(test mode) failed to start!!!"
exit
fi
elif [ "$CHECK_MODE" = "SEED_DOCKER" ]; then
if sudo docker run "${DPORTS[@]}" -v "$SHM_DIR":/shm -v "$DATADIR":/peerplays -d --name ${DOCKER_NAME} -t ${PEERPLAYS_DOCKER_TAG} witness_node --data-dir=/peerplays/witness_node_data_dir; then
msg bold green "Peerplays seed docker container started successfully, you can view the logs using ./run.sh logs"
else
msg bold red "Peerplays seed docker container failed to start!!!"
exit
fi
fi
fi
}
# Usage: ./run.sh replay
# Replays the blockchain for the Steem docker container
# If steem is already running, it will ask you if you still want to replay
# so that it can stop and remove the old container
#
steem_replay() {
remove_seed_exists 1
local p_msg=" -> Running $DOCKER_IMAGE (image: ${DOCKER_IMAGE}) with replay in container '${DOCKER_NAME}'"
(($# > 0)) && p_msg+=" - extra args: '$*'..." || p_msg+="..."
msg green "$p_msg"
docker_run_node --replay-blockchain "$@"
msg bold green " -> Started."
}
#INTERNAL
peerplays_docker_replay() {
remove_seed_exists 1
CHECK_MODE=$(grep MODE "$HOME"/.install_setting | awk -F= '{print $2}')
if [ "$CHECK_MODE" = "WITNESS_DOCKER" ]; then
if sudo docker run "${DPORTS[@]}" -v "$SHM_DIR":/shm -v "$DATADIR":/peerplays -d --name "$DOCKER_NAME" -t "$DOCKER_IMAGE" witness_node --replay-blockchain --data-dir=/peerplays/witness_node_data_dir; then
msg bold green "Replay of witness node started successfully"
else
msg bold red "Replay of witness node failed !!!"
fi
else
if sudo docker run "${DPORTS[@]}" --entrypoint /peerplays/son-entrypoint.sh --network ${DOCKER_NETWORK} -v "$SHM_DIR":/shm -v "$DATADIR":/peerplays -d --name $DOCKER_NAME -t datasecuritynode/peerplays:son-dev witness_node --replay-blockchain --data-dir=/peerplays/witness_node_data_dir; then
msg bold green "Replay of SON docker container started successfully"
else
msg bold red "SON docker container failed to start!!!"
exit
fi
fi
}
#INTERNAL
peerplays_replay() {
msg bold green "Replaying the blockchain"
INSTALL_ABS_DIR="$(grep DIRECTORY "$HOME"/.install_setting | awk -F= '{print $2}')"
msg bold red "Stoping the Peerplays Blockchain Replay Service"
if ! sudo systemctl stop peerplays.service; then
msg bold red "Peerplays witness node stop failed!!!!!"
exit
else
if ! sudo systemctl list-unit-files --type service | grep peerplays-replay.service; then
msg bold blue "Creating Peerplays Blockchain Replay Service"
echo -e "[Unit]" >"$INSTALL_ABS_DIR"/peerplays.service
{
echo -e "Description=Peerplays Witness Node\n"
echo -e "[Service]"
echo -e "User=$(whoami)"
echo -e "WorkingDirectory=$INSTALL_ABS_DIR"
echo -e "ExecStart=$INSTALL_ABS_DIR/src/peerplays/programs/witness_node/witness_node --replay-blockchain"
echo -e "Restart=always\n"
echo -e "[Install]"
echo -e "WantedBy=mult-user.target"
} >>"$INSTALL_ABS_DIR"/peerplays-replay.service
msg bold blue "Starting Peerplays Blockchain replay service"
sudo mv "$INSTALL_ABS_DIR"/peerplays-replay.service /etc/systemd/system && sudo systemctl start peerplays-replay.service
sleep 30
else
msg bold blue "Starting Peerplays Blockchain replay service"
sudo systemctl start peerplays-replay.service
sleep 30
fi
if [ "$(systemctl is-active peerplays-replay.service)" = "active" ]; then
msg bold green "Peerplays witness replay started successfully. You can monitor the logs using ./run.sh logs"
else
msg bold red "Peerplays witness node replay failed!!!!!"
exit
fi
fi
}
# Usage: ./run.sh replay
replay() {
if is_installed; then
if ! sudo systemctl list-unit-files --type service | grep peerplays; then
peerplays_docker_replay
else
peerplays_replay
fi
else
msg bold red "Peerplays Blockchain not present on this server/not installed using run.sh"
fi
}
# For MIRA, you can replay with --memory-replay to tell steemd to store as much chainstate as it can in memory,
# instead of constantly reading/writing it to the disk RocksDB files.
# WARNING: Consumes a ridiculous amount of memory compared to standard MIRA replay and non-MIRA replay
# (somewhere around 120GB for low memory mode with basic plugins...)
memory_replay() {
remove_seed_exists 1
echo "Removing old container"
docker rm "$DOCKER_NAME"
echo "Running ${NETWORK_NAME} with --memory-replay..."
docker_run_node --replay --memory-replay "$@"
echo "Started."
}
# Usage: ./run.sh shm_size size
# Resizes the ramdisk used for storing Steem's shared_memory at /dev/shm
# Size should be specified with G (gigabytes), e.g. ./run.sh shm_size 64G
#
shm_size() {
if (($# < 1)); then
msg red "Please specify a size, such as ./run.sh shm_size 64G"
fi
msg green " -> Setting /dev/shm to $1"
if sudo mount -o "remount,size=$1" /dev/shm; then
msg bold green "Successfully resized /dev/shm"
else
msg bold red "An error occurred while resizing /dev/shm..."
msg red "Make sure to specify size correctly, e.g. 64G. You can also try using sudo to run this."
fi
}
# Usage: ./run.sh stop
# Stops the Steem container, and removes the container to avoid any leftover
# configuration, e.g. replay command line options
#
stop() {
msg "If you don't care about a clean stop, you can force stop the container with ${BOLD}./run.sh kill"
msg red "Stopping container '${DOCKER_NAME}' (allowing up to ${STOP_TIME} seconds before killing)..."
sudo docker stop -t ${STOP_TIME} $DOCKER_NAME
msg red "Removing old container '${DOCKER_NAME}'..."
sudo docker rm "$DOCKER_NAME"
}
kill() {
msg bold red "Killing container '${DOCKER_NAME}'..."
sudo docker kill "$DOCKER_NAME"
msg red "Removing container ${DOCKER_NAME}"
sudo docker rm "$DOCKER_NAME"
}
# Usage: ./run.sh enter
# Enters the running docker container and opens a bash shell for debugging
#
enter() {
docker exec -it $DOCKER_NAME bash
}
# Usage: ./run.sh shell
# Runs the container similar to `run` with mounted directories,
# then opens a BASH shell for debugging
# To avoid leftover containers, it uses `--rm` to remove the container once you exit.
#
shell() {
_docker_int_autorm bash
# docker run ${DPORTS[@]} -v "$SHM_DIR":/shm -v "$DATADIR":/steem --rm -it "$DOCKER_IMAGE" bash
}
# Usage: ./run.sh wallet
# Opens cli_wallet inside of the running Steem container and
# connects to the local steemd over websockets on port 8090
#
wallet() {
docker exec -it $DOCKER_NAME cli_wallet -s ws://127.0.0.1:8090
}
# Usage: ./run.sh remote_wallet [wss_server]
# Connects to a remote websocket server for wallet connection. This is completely safe
# as your wallet/private keys are never sent to the remote server.
#
# By default, it will connect to wss://steemd.privex.io:443 (ws = normal websockets, wss = secure HTTPS websockets)
# See this link for a list of WSS nodes: https://www.steem.center/index.php?title=Public_Websocket_Servers
#
# wss_server - a custom websocket server to connect to, e.g. ./run.sh remote_wallet wss://rpc.steemviz.com
#
remote_wallet() {
if (($# >= 1)); then
REMOTE_WS="$1"
fi
# DKR_RUN_ARGS="--rm -i" RUN_DETACHED=0 DKR_RUN_ADD_DATA_DIR=0
# DKR_RUN_BIN="cli_wallet"
# docker run -v "$DATADIR":/steem --rm -it "$DOCKER_IMAGE" cli_wallet -s "$REMOTE_WS"
docker_run_wallet "$REMOTE_WS"
}
# Usage: ./run.sh logs
# Shows the last 30 log lines of the running steem container, and follows the log until you press ctrl-c
#
logs() {
if is_installed; then
if [ "$(systemctl is-active peerplays.service)" = "active" ]; then
msg bold green "Tailing Peerplays service logs"
#WITNESS_SCRIPT=`systemctl status peerplays|grep ExecStart |awk -F\= '{print $2}'|sed -e 's/[^ ]* *$//'`
#WITNESS_SCRIPT_DIR=`systemctl status peerplays|grep witness|grep peerplays|awk '{print $2}'|xargs dirname`
sudo journalctl -f -u peerplays
exit
elif [ "$(systemctl is-active peerplays-replay.service)" = "active" ]; then
msg bold green "Tailing Peerplays service logs"
#WITNESS_SCRIPT=`systemctl status peerplays|grep ExecStart |awk -F\= '{print $2}'|sed -e 's/[^ ]* *$//'`
#WITNESS_SCRIPT_DIR=`systemctl status peerplays|grep witness|grep peerplays|awk '{print $2}'|xargs dirname`
sudo journalctl -f -u peerplays-replay
exit
else
msg blue "DOCKER LOGS: (press ctrl-c to exit) "
sudo docker logs -f --tail=30 "$DOCKER_NAME"
exit
fi
else
msg bold red "Peerplays Blockchain not present on this server/not installed using run.sh"
fi
#echo $RED"INFO AND DEBUG LOGS: "$RESET
#tail -n 30 $DATADIR/{info.log,debug.log}
}
# Usage: ./run.sh pclogs
# (warning: may require root to work properly in some cases)
# Used to watch % replayed during blockchain replaying.
# Scans and follows a large portion of your steem logs then filters to only include the replay percentage
# example: 2018-12-08T23:47:16 22.2312% 6300000 of 28338603 (60052M free)
#
pclogs() {
if [[ ! $(command -v jq) ]]; then
msg red "jq not found. Attempting to install..."
sleep 3
sudo apt-get update -y >/dev/null
sudo apt-get install -y jq >/dev/null
fi
local LOG_PATH=$(docker inspect "$DOCKER_NAME" | jq -r .[0].LogPath)
local pipe="$(mktemp).fifo"
trap "rm -f '$pipe'" EXIT
if [[ ! -p "$pipe" ]]; then
mkfifo "$pipe"
fi
# the sleep is a dirty hack to keep the pipe open
sleep 1000000 <"$pipe" &
tail -n 5000 -f "$LOG_PATH" &>"$pipe" &
while true; do
if read -r line <"$pipe"; then
# first grep the data for "objects cached" to avoid
# needlessly processing the data
L=$(egrep --colour=never "objects cached|M free" <<<"$line")
if [[ $? -ne 0 ]]; then
continue
fi
# then, parse the line and print the time + log
L=$(jq -r ".time +\" \" + .log" <<<"$L")
# then, remove excessive \r's causing multiple line breaks
L=$(sed -e "s/\r//" <<<"$L")
# now remove the decimal time to make the logs cleaner