Last active
May 18, 2025 10:02
-
-
Save kianenigma/d0d5f4c05c745537aef6b8a96206dbc6 to your computer and use it in GitHub Desktop.
Cron job spec to run Polkadot nodes in a crontab for a few mins every hour, enough to keep them synced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create these functions in some bash file to be imported in the crontab | |
# crontab in macos is weird and cannot load normal zsh functions. | |
# cat ~/.shell_functions | |
function base_run_chain() { | |
chain=$1 | |
port=$2 | |
sync=$3 | |
polkadot --chain $chain \ | |
--sync $sync \ | |
--database paritydb \ | |
--blocks-pruning 256 \ | |
--state-pruning 256 \ | |
--base-path ~/chains-data \ | |
--rpc-max-request-size 1000000 \ | |
--rpc-max-response-size 1000000 \ | |
--rpc-port $port | |
} | |
function run_chain() { | |
base_run_chain $1 $2 "fast-unsafe" | |
} | |
function warp_chain() { | |
base_run_chain $1 $2 "warp" | |
} | |
# --------------------------------- | |
# create file update-chians.sh somehwere with this content | |
# cat ~/update-chains.sh | |
#! /bin/bash | |
source ~/.shell_functions | |
export -f run_chain | |
export -f base_run_chain | |
PATH=$PATH:where-you-have-polkadot-binaries | |
timeout $1m bash -c 'run_chain "$@"' _ polkadot 9999 | |
timeout $1m bash -c 'run_chain "$@"' _ kusama 9998 | |
timeout $1m bash -c 'run_chain "$@"' _ westend 9997 | |
# --------------------------------- | |
# finally, in `crontab -e`, put: | |
1 * * * * ~/update-chains.sh 3 2>&1 | while read line; do echo "$(date) == $line"; done > ~/cron.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment