Reiniciar Geth desde otro proceso

Quiero hacer un script para reiniciar mi servidor y sus requisitos previos, cuál de ellos es geth. No veo una línea de comando para reiniciarlo. quiero algo como

geth --restart --xxxx --yyyyy

¿Existe esto?

En caso negativo, ¿es seguro acabar con el proceso y volver a ejecutarlo?

Respuestas (2)

Esto es lo que uso en mi entorno Linux. Guardo lo siguiente en/home/user/bin/runGeth

#!/bin/sh

# Graceful exit, like pressing Control-C on a program
killall -q --signal SIGINT geth
sleep 10

# Hard kill, only to stop a process that refuses to terminate
killall -q geth

# Clear IPC as this can sometimes cause problems
rm -f /home/user/.ethereum/geth.ipc

DATE=`date +%Y%m%d_%H%M%S`
mv /home/user/ethlogs/geth.log /home/user/logarchive/geth.log_$DATE

# Message <= 32 bytes
MESSAGE="BokkyPooBah wuz here!"

# Use 6 for full details
VERBOSITY=3

geth --support-dao-fork --rpc --rpcaddr "192.168.7.123" --rpcport 8545 --extradata "$MESSAGE" --verbosity $VERBOSITY 2>> /home/user/ethlogs/geth.log &

entonces chmod 700 /home/user/bin/runGeth_

Y en /etc/rc.local, agrego:

sudo -u user /home/user/bin/runGeth

También reinicio gethperiódicamente ya que he tenido varios casos en los que se bloquea o muere. Agrego lo siguiente acrontab -e

# m h  dom mon dow   command
10 1,7,13,19 * * * sudo -u user /home/user/bin/runGeth 


P : En caso de que no, ¿es seguro acabar con el proceso y ejecutarlo de nuevo?

La salida airosa para gethes necesaria. Dejo algo de tiempo para gethque se apague con gracia. Luego trato de matar gethcon fuerza como en el pasado se negó a salir con gracia.

Utilicé solo el hard kill antes y los datos de la cadena de bloques se corrompieron.


También utilizo scripts similares para enviarme correos electrónicos periódicos que informan sobre el saldo de la base de monedas, el ethminerhashrate, la temperatura de la GPU, los precios de ETH y otras estadísticas. Y un script de vigilancia para cerrar ethminerlos procesos si las GPU alcanzan una temperatura específica.

Agregué killall -s SIGKILL -q geth por si acaso.

Uso un par de scripts para administrar mis instancias de geth

Para comenzar con geth (aquí proporciono como parámetro la verbosidad, pero puede proporcionar más si lo desea)

verbosity=3
while [ "$1" != "" ]; do
    case $1 in
    -v | --verbosity )  shift
                        verbosity=$1
                        ;;
    esac
    shift
done
if test -z `ps -ef | grep 'SCREEN -dmS geth' | grep -v grep | awk '{print $2}'`
then
echo "Starting Geth..."
screen -dmS geth /usr/bin/geth --networkid "189" --identity "firstMiner" --nodiscover --rpc --rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcaddr "0.0.0.0" --rpcport "8545" --rpccorsdomain "*"  --maxpeers "25" --mine --etherbase "3a4ac889777bce619ad88eef2ad7b9cace99273e" --gasprice "0" --targetgaslimit "9999999" --verbosity "$verbosity"
echo "Geth started with verbosity $verbosity"
else
echo "Geth is alreay running"
fi

por detener a geth

if test -z `ps -ef | grep 'SCREEN -dmS geth' | grep -v grep | awk '{print $2}'`
then
echo "Geth is already Stopped"
else
echo "Stopping Geth..."
ps -ef | grep 'SCREEN -dmS geth' | grep -v grep | awk '{print $2}' | xargs kill
echo "Geth stopped"
fi

Para verificar el estado de geth

if test -z `ps -ef | grep 'SCREEN -dmS geth' | grep -v grep | awk '{print $2}'`
then
echo "Geth is stopped"
else
echo "Geth is running"
fi

Para adjuntar a la consola geth (proporciono una ruta relativa al ipc aquí, pero puede poner una ruta absoluta)

if test -z `ps -ef | grep 'SCREEN -dmS geth' | grep -v grep | awk '{print $2}'`
then
echo "Geth is not running"
else
geth attach ipc:../.ethereum/geth.ipc
fi

Para reiniciar, puede poner los scripts geth stop y geth start juntos en otro script.