Skip to content

Commit

Permalink
Merge pull request #111 from Samourai-Wallet/imp_mydojo_ronin
Browse files Browse the repository at this point in the history
enable autostart of dojo
  • Loading branch information
kenshin-samourai authored Dec 28, 2019
2 parents 969eeb9 + 166fde5 commit 70f608e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docker/my-dojo/bitcoin/restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ if [ "$COMMON_BTC_NETWORK" == "testnet" ]; then
fi

bitcoind "${bitcoind_options[@]}"
exitCode=$?

if [ $exitCode -eq 0 ]; then
# Loop keeping the container up
# after bitcoind has been stopped
while true
do
tail -f /dev/null > /dev/null
done
fi
40 changes: 30 additions & 10 deletions docker/my-dojo/dojo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,50 @@ start() {

# Stop
stop() {
# Shutdown the bitcoin daemon
if [ "$BITCOIND_INSTALL" == "on" ]; then
# Renewal of bitcoind onion address
if [ "$BITCOIND_EPHEMERAL_HS" = "on" ]; then
docker exec -it tor rm -rf /var/lib/tor/hsv2bitcoind
fi

# Stop the bitcoin daemon
echo "Preparing shutdown of dojo. Please wait."
docker exec -it bitcoind bitcoin-cli \
-rpcconnect=bitcoind \
--rpcport=28256 \
--rpcuser="$BITCOIND_RPC_USER" \
--rpcpassword="$BITCOIND_RPC_PASSWORD" \
stop

echo "Preparing shutdown of dojo. Please wait."

bitcoindDown=$(timeout 3m docker wait bitcoind)
if [ $bitcoindDown -eq 0 ]; then
echo "Bitcoin server stopped."
else
# Check if the bitcoin daemon is still up
# wait 3mn max
i="0"
while [ $i -lt 18 ]
do
# Check if bitcoind rpc api is responding
timeout 5 docker exec -it bitcoind bitcoin-cli \
-rpcconnect=bitcoind \
--rpcport=28256 \
--rpcuser="$BITCOIND_RPC_USER" \
--rpcpassword="$BITCOIND_RPC_PASSWORD" \
getblockchaininfo > /dev/null
# rpc api is down
if [[ $? > 0 ]]; then
echo "Bitcoin server stopped."
break
fi
# Pause before next try
sleep 5
i=$[$i+1]
done
# Bitcoin daemon is still up
# => force close
if [ $i -eq 18 ]; then
echo "Force shutdown of Bitcoin server."
fi
fi

# Stop docker containers
yamlFiles=$(select_yaml_files)
eval "docker-compose $yamlFiles down"
eval "docker-compose $yamlFiles stop"
}

# Restart dojo
Expand Down
2 changes: 1 addition & 1 deletion docker/my-dojo/overrides/bitcoind.install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- ./.env
- ./conf/docker-common.conf
- ./conf/docker-bitcoind.conf
restart: on-failure
restart: always
command: "/wait-for-it.sh tor:9050 --timeout=720 --strict -- /restart.sh"
expose:
- "8333"
Expand Down

0 comments on commit 70f608e

Please sign in to comment.