#! /bin/sh self=${NIMBUS_SESSION_SELF:-`basename "$0"`} # Network name (used below for easy setup) name=${NIMBUS_SESSION_NAME:-kiln} # Unique Nimbus TCP/UDP communication port port=${NIMBUS_SESSION_PORT:-30308} # Terminal Total Difficulty ttd=${NIMBUS_SESSION_TTD:-1000000000000} # May be set to 1 for a single peer to be enough min_peers=${NIMBUS_SESSION_MIN_PEERS:-2} # Unique log data and database folder (relative to current directory) datadir=${NIMBUS_SESSION_DATADIR:-./datadir-$name} optargs=${NIMBUS_SESSION_OPTARGS} # -------- no need to change, below ------------- # Name of custom genesis and bootstrap files genesis_json=$name.json bootstrap_txt=$name-enode.txt # Log spooler capacity settings logfile_max=80000000 num_backlogs=40 # Base directory for finding objects in the Nimbus file system find_prefix="`dirname $0` . .. ../.. nimbus-eth1 nimbus-eth1-blobs" # Sub-find directory for various items find_nimbus=". .. build" find_genesis=". .. customgenesis" find_bootstrap=". .. custom-network" # ------------------------------------------------------------------------------ # Helpers # ------------------------------------------------------------------------------ # Find executable file find_exe() { # Syntax: ... exe="$1" shift { for pfx in $find_prefix; do for sub; do find -L \ "$pfx/$sub" \ -maxdepth 3 -type f -name "$exe" -perm /111 -print \ 2>/dev/null done done | # Beware, this is slow. On the other hand, uncommenting the # next line dumps all possible matches to the console. #tee /dev/tty | xargs -n1 realpath 2>/dev/null # provide argument file name as default echo "$exe" } | sed -eq } # Find non-executable file find_file() { # Syntax: ... file="$1" shift { for pfx in $find_prefix; do for sub; do find -L \ "$pfx/$sub" \ -maxdepth 3 -type f -name "$file" -print \ 2>/dev/null done | # Beware, this is slow. On the other hand, uncommenting the # next line dumps all possible matches to the console. #tee /dev/tty | xargs -n1 realpath 2>/dev/null done # provide argument file name as default echo "$file" } | sed -eq } stripColors() { if ansi2txt /dev/null then ansi2txt else cat fi } # Find pid of running svlogd command get_pid_svlogd() { ps x| grep \ -e "svlogd $datadir/log" \ | grep -v \ -e vim \ -e grep \ | awk '$1 != '"$$"'{print $1}' } # Find pid of running svlogd and nimbus command get_pids() { ps x| grep \ -e "nimbus .* --tcp-port:$port" \ -e "svlogd $datadir/log" \ | grep -v \ -e vim \ -e grep \ | awk '$1 != '"$$"'{print $1}' } # ------------------------------------------------------------------------------ # Command line parsing and man page # ------------------------------------------------------------------------------ nohup=no start=no stop=no flush=no logs=no help=no test $# -ne 0 || help=yes for arg do case "$arg" in stop) stop=yes ;; flush) flush=yes ;; start) start=yes ;; daemon) nohup=yes start=yes ;; logs) logs=yes ;; help|'') help=yes ;; *) exec >&2 echo "Usage: $self [help] [stop] [flush] [daemon|start] [logs]" exit 2 esac done test yes != "$help" || { cat <&1|grep -i 'usage: svlogd' >/dev/null) || { exec >&2 echo "*** $self: This script needs a working \"svlogd\" program. On Debian," echo " this is provided by the \"runit\" package." exit 2 } # Stop running sessions by sending termination signal test yes != "$stop" || { # set -x pids=`get_pids` test -z "$pids" || { (set -x; kill -TERM $pids) sleep 1 pids=`get_pids` test -z "$pids" || { (set -x; kill -KILL $pids) sleep 1 } echo } } # Clean up test yes != "$flush" || { d=`basename $datadir` test \! -d $datadir || (set -x; rm -rf $datadir) } # Stop here after clean up when terminating a session test yes != "$stop" || { exit } if [ yes = "$nohup" ] then # Restore console after disabling ctrl-C for nimbus stty_save=`stty --save /dev/null || true { echo s$logfile_max echo n$num_backlogs } >./log/config set -x ${nimbus:-nimbus} \ --data-dir:./data \ --custom-network:"$genesis" \ --bootstrap-file:"$bootstrap" \ --terminal-total-difficulty:$ttd \ --min-sync-peers:$min_peers \ --tcp-port:$port \ $optargs \ --prune-mode:full \ --log-level:TRACE \ 2>&1 ) | stripColors | svlogd $datadir/log ) & # After starting a session, make sure that svlogd is re-loaded in order # to read the config file (woul not tdo it right on the start) test yes != "$start" || { sleep 1 pid=`get_pid_svlogd` test -z "$pid" || kill -HUP $pid echo } # Restore console after disabling ctrl-C for nimbus test yes != "$nohup" || { stty $stty_save >> [pf][io]' \ -e '<<< [pf][io]' } # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------