Possible update scripts and their sequence, always run as root
:
pre_update.sh
runs (if exists)- Following this,
pip install pioreactor...whl
runs update.sh
runs (if exists)update.sql
to update sqlite schema runs (if exists)post_update.sh
runs (if exists). Useful for restarting jobs, adding data to new db tables, or rebooting RPis.
It's very important that update scripts are idempotent. Some tips:
- Use ChatGPT to inspect if a script is idempotent, or make suggestions.
- the scripts are run as
root
user, sopios sync-configs
fails with auth problems. Usesudo -u pioreactor pios sync-configs
- use
|| :
if a command may fail, but you want to continue anyways - use
trap
andEXIT
semantics (like try / expect) to force some code block to always run. - https://arslan.io/2019/07/03/how-to-write-idempotent-bash-scripts/
# Get the hostname
HOSTNAME=$(hostname)
# Get the leader hostname
# Don't use `leader_address`, as users do change that.
LEADER_HOSTNAME=$(crudini --get $PIO_DIR/config.ini cluster.topology leader_hostname)
if [ "$HOSTNAME" = "$LEADER_HOSTNAME" ]; then
...
fi
- use
IF EXISTS