Skip to content

Instantly share code, notes, and snippets.

@yukihirai0505
Last active June 14, 2019 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukihirai0505/609937f97441fa0ef31e397ca3aac6cc to your computer and use it in GitHub Desktop.
Save yukihirai0505/609937f97441fa0ef31e397ca3aac6cc to your computer and use it in GitHub Desktop.
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