Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
auto-restart scripts for IdexD

Get Started

Create cronjob.env.sh to load nvm

#!/bin/bash

# NVM needs the ability to modify your current shell session's env vars,
# which is why it's a sourced function
export NVM_DIR="/home/<username>/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

Create script.sh

#!/bin/bash

IDEX=$(which idex)
IDEX_STATUS=$(${IDEX} status)
IS_OFFLINE=$(echo "${IDEX_STATUS}" | grep offline | wc -l)
LOG_MESSAGE=$(echo $(date):Idexd)

if [ ${IS_OFFLINE} -eq 1 ]; then
	${IDEX} stop
	${IDEX} start --rpc https://mainnet.infura.io/v3/<YOUR API KEY>
	LOG_MESSAGE=$(echo ${LOG_MESSAGE} restarted)
else
	LOG_MESSAGE=$(echo ${LOG_MESSAGE} is online)
fi
echo ${LOG_MESSAGE}
echo "${IDEX_STATUS}" | grep "My Period Credits"

Add job to crontab

$ crontab -e
*/10 * * * * (. /home/<username>/cronjob.env.sh; . /home/<username>/script.sh >> /home/<username>/idexd.log; )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment