Skip to content

Instantly share code, notes, and snippets.

@imylomylo
Last active March 8, 2019 05:59
Show Gist options
  • Save imylomylo/1011ca329621ce1c4b86cbc3e0de7ac5 to your computer and use it in GitHub Desktop.
Save imylomylo/1011ca329621ce1c4b86cbc3e0de7ac5 to your computer and use it in GitHub Desktop.
Iguana restart terminates unexpectedly from script (hypothesis)
#############
ENV different
#############
My cron restarts iguana like this:
13 0 * * 1 . $HOME/.profile;/home/me/cron_rotate.sh 2>&1
The `. $HOME/.profile` is needed because the cron ENV is not the same as the logged in user ENV.
##########################
Full path vs relative path
##########################
This is what the cron script calls (contents of cron_rotate.sh)
#!/bin/bash
cd /home/me
/home/me/rotate.sh >/home/me/rotate.log &
Maybe it's an intermediate step that is not required for this stage, however maybe I want to add a telegram bot command or some other backup/notification script pre/post rotation.
The partial contents of rotate.sh are more exhaustive. Whenever I'm logged into the console and want to call rotate, this is the script that is used when logged in.
#!/bin/bash
#/home/me/contrib/auto_sendawaynn.sh 2>&1
#sleep 10
DATENOW=$(date +%s)
SPLITAMOUNT=55
KMDADDRESS=$(cat ADDRESSKMD |jq -r '.address')
PIONEERPAPER="_my_paper_wallet_address_"
TELEGRAMDIR=/home/me/bin/telegram
#${TELEGRAMDIR}/telegram_send.sh "${MESSAGE}"
PROC_IGUANA=$(ps aux | grep iguana | grep -v "SCREEN\|grep" | awk -F " " '{print $2}')
if [ -z ${PROC_IGUANA} ]; then
echo "Iguana already dead"
else
echo "Iguana process is: ${PROC_IGUANA}"
echo "Killing iguana"
kill -15 ${PROC_IGUANA}
${TELEGRAMDIR}/telegram_send.sh "**Rotate** Iguana running pid ${PROC_IGUANA} killed."
sleep 5
# SHOULD KEEP CHECKING IGUANA IS DEAD
fi
# Unlock locked utxo so we can send away
komodo-cli lockunspent true `komodo-cli listlockunspent | jq -c .`
# Save height
BLOCKS=$(komodo-cli getinfo | jq '.blocks')
echo ${BLOCKS} > /home/me/blocks
${TELEGRAMDIR}/telegram_send.sh "**Rotate** KMD height: ${BLOCKS}"
TX_SENDTOSELF=$(/home/me/bin/komodo-cli sendtoaddress ${PIONEERPAPER} $(komodo-cli getbalance) "" "" true)
echo ${TX_SENDTOSELF} > /home/me/tx_sendtoself
echo "Sent to self please check /home/me/tx_sendtoself: ${TX_SENDTOSELF}"
${TELEGRAMDIR}/telegram_send.sh "**Rotate** check tx to paper: https://www.kmdexplorer.io/tx/${TX_SENDTOSELF}"
#CHECK HERE WE GET A TX ID
sleep 3
/home/me/bin/komodo-cli stop
while [ -z $(tail ~/.komodo/debug.log | grep -m 1 -o -i shutdown) ]
do
echo "still shutting down"
sleep 3
done
mv /home/me/.komodo/wallet.dat /home/me/.komodo/wallet.dat.bak-${DATENOW}
echo "Wallet backed up to wallet.dat.bak-${DATENOW}"
${TELEGRAMDIR}/telegram_send.sh "**Rotate** Wallet backed up to wallet.dat.bak-${DATENOW}"
/home/me/bin/komodod -exportdir=/home/me/backups -gen -genproclimit=1 -notary -pubkey=_my_pubkey_ &
echo "Komodo restarts, waiting 60s"
...
Snipped
...
At this point we have just killed iguana and komodod. Nothing too exciting.
Further on in the script we restart komodod, import a wallet and then restart iguana.
This is where the relative path thing gets interesting. Iguana comes with a restart script, but from what I've discovered, it expects you to be in the homedir of iguana. So when you start it from non-homedir with a full path, it will fail.
So restarting iguana with my full-path-customized after komodod restarts and a wallet imported
...
...
CHECK_IGUANA=$(ps aux | grep iguana | grep -v "SCREEN\|grep" | awk -F " " '{print $2}')
if [ -z ${CHECK_IGUANA} ] || [ "${CHECK_IGUANA}" != "${PROC_IGUANA}" ]; then
echo "Iguana dead. Restarting"
cd /home/me/SuperNET/iguana
/home/me/SuperNET/iguana/mylo_iguana_start &
echo "Iguana restart"
${TELEGRAMDIR}/telegram_send.sh "**Rotate** Iguana restart."
echo "Waiting 30"
sleep 30
echo "Waiting another 30"
while [ -z $(head -n 1500 /home/me/SuperNET/iguana/iguana.log | grep -m 1 -o "INIT with 64 notaries") ]
do
echo "Waiting for iguana to INIT with 64 notaries"
sleep 3
done
SPLITRESULT=$(/home/me/SuperNET/iguana/acsplit KMD ${SPLITAMOUNT})
...
...
We get the mylo_iguana_start.sh script.
This is just the m_notary_run file with all relative paths replaced by full paths.
e.g.
iguana_arg="notary_nosplit"
stdbuf -oL $1 /home/me/SuperNET/agents/iguana $iguana_arg > /home/me/SuperNET/iguana/iguana.log 2> /home/me/SuperNET/iguana/error.log &
And all the compilation stuff the preceeds it commented out - because I control when the git pull happens and when it compiles because i don't want any nasty surprises on rotation.
More examples in that mylo_iguana_start.sh script are
source /home/me/SuperNET/iguana/pubkey.txt
instead of just
source ./pubkey.txt
...
...
and then all the coins files
...
...
#tests/addnotarys_7776
/home/me/SuperNET/iguana/coins/btc_7776
#coins/ltc_7776
/home/me/SuperNET/iguana/coins/kmd_7776
/home/me/SuperNET/iguana/coins/chips_7776
/home/me/SuperNET/iguana/coins/game_7776
/home/me/SuperNET/iguana/coins/emc2_7776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment