Skip to content

Instantly share code, notes, and snippets.

@wileyj
Last active January 26, 2022 04:09
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 wileyj/4959035d85ed5e358788e267745d1d4e to your computer and use it in GitHub Desktop.
Save wileyj/4959035d85ed5e358788e267745d1d4e to your computer and use it in GitHub Desktop.
stacks-node init-style script
#!/bin/sh
NETWORK=$1
OP=$2
BINARY=stacks-node
BASEDIR=$HOME/stacks-blockchain
usage () {
echo ""
echo "$0 (mocknet|testnet|mainnet) (start|stop|restart)"
echo " ex: $0 mocknet start"
echo ""
exit 0
}
if [ "$1" == "" ];then
echo
echo "** Missing network arg"
echo
usage
fi
if [ "$2" == "" ];then
echo
echo "** Missing operation arg"
echo
usage
fi
if [ ! -d ${BASEDIR}/logs ]; then
mkdir -p ${BASEDIR}/logs
fi
if [ ! -d ${BASEDIR}/${NETWORK} ]; then
mkdir -p ${BASEDIR}/${NETWORK}
fi
start () {
if [ ! -f ${BASEDIR}/${NETWORK}.toml ];then
echo "** missing file: ${BASEDIR}/${NETWORK}.toml"
exit 1
fi
if status; then
${BASEDIR}/$BINARY start --config=${BASEDIR}/${NETWORK}.toml >> ${BASEDIR}/logs/${NETWORK}.log 2>&1 &
if [ "$?" -eq "0" ];then
echo
echo "** Started stacks-node"
echo
fi
else
echo
echo "** stacks-node already running"
echo
fi
}
stop () {
if ! status; then
for PID in `ps -ef | grep stacks-node | grep -v grep | awk {'print $2'}`; do
echo "PID: $PID"
kill $PID
done
echo
echo "** Stopped stacks-node"
echo
else
echo
echo "** stacks-node not running"
echo
fi
}
status () {
COUNT=$(ps -ef | grep stacks-node | grep -v grep | awk {'print $2'} | wc -l)
return $COUNT
}
case $NETWORK in
mocknet|testnet|mainnet)
break
;;
*)
echo
echo "** Unknown network arg"
echo
usage
;;
esac
case $OP in
start)
start
;;
stop)
stop
;;
status)
if status; then
echo
echo "** stacks-node not running"
echo
else
echo
echo "** stacks-node running"
echo
fi
;;
restart)
stop
start
;;
*)
echo
echo "** Unknown operation arg"
echo
usage
;;
esac
exit 0
@wileyj
Copy link
Author

wileyj commented Jan 26, 2022

usage:

./run.sh <network> <operation>

ex:

./run.sh mainnet start

where <network> is one of:

  • mocknet
  • testnet
  • mainnet

and <operation> is one of:

  • start
  • stop
  • restart
  • status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment