2023-10-17 10:35:38 -04:00
|
|
|
#!/usr/bin/env bash
|
2019-06-27 14:37:42 -04:00
|
|
|
|
|
|
|
# A useful script for testing out changes to PVC by building the debs and deploying them out to a
|
|
|
|
# set of hosts automatically, including restarting the daemon (with a pause between) on the remote
|
|
|
|
# side. Mostly just useful for quickly testing/debugging changes as Ansible should be used for
|
|
|
|
# production upgrades.
|
|
|
|
|
|
|
|
# Check if we're root, or not
|
|
|
|
if [[ $( id -u ) -eq 0 ]]; then
|
|
|
|
SUDO=""
|
|
|
|
else
|
|
|
|
SUDO="sudo"
|
|
|
|
fi
|
|
|
|
|
2021-10-11 16:41:00 -04:00
|
|
|
KEEP_ARTIFACTS=""
|
2024-08-25 20:45:52 -04:00
|
|
|
API_ONLY=""
|
2024-08-19 17:44:13 -04:00
|
|
|
PRIMARY_NODE=""
|
2021-10-11 16:41:00 -04:00
|
|
|
if [[ -n ${1} ]]; then
|
|
|
|
for arg in ${@}; do
|
|
|
|
case ${arg} in
|
|
|
|
-k|--keep)
|
|
|
|
KEEP_ARTIFACTS="y"
|
|
|
|
shift
|
|
|
|
;;
|
2024-08-25 20:45:52 -04:00
|
|
|
-a|--api-only)
|
|
|
|
API_ONLY="y"
|
|
|
|
shift
|
|
|
|
;;
|
2024-08-19 17:44:13 -04:00
|
|
|
-p=*|--become-primary=*)
|
|
|
|
PRIMARY_NODE=$( awk -F'=' '{ print $NF }' <<<"${arg}" )
|
|
|
|
shift
|
|
|
|
;;
|
2021-10-11 16:41:00 -04:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2019-06-27 14:37:42 -04:00
|
|
|
HOSTS=( ${@} )
|
2024-01-10 14:22:12 -05:00
|
|
|
echo "Deploying to host(s): ${HOSTS[@]}"
|
2024-08-19 17:44:13 -04:00
|
|
|
if [[ -n ${PRIMARY_NODE} ]]; then
|
|
|
|
echo "Will become primary on ${PRIMARY_NODE} after updating it"
|
|
|
|
fi
|
2019-06-27 14:37:42 -04:00
|
|
|
|
2021-11-06 03:16:02 -04:00
|
|
|
# Move to repo root if we're not
|
|
|
|
pushd $( git rev-parse --show-toplevel ) &>/dev/null
|
|
|
|
|
2021-11-06 03:10:17 -04:00
|
|
|
# Prepare code
|
2024-01-10 14:22:12 -05:00
|
|
|
echo "> Preparing code (format and lint)..."
|
2021-11-06 13:34:33 -04:00
|
|
|
./format || exit 1
|
|
|
|
./lint || exit 1
|
2021-10-27 13:25:14 -04:00
|
|
|
|
2019-06-27 14:37:42 -04:00
|
|
|
# Build the packages
|
2024-01-10 14:22:12 -05:00
|
|
|
echo -n "> Building packages..."
|
2020-08-26 11:04:58 -04:00
|
|
|
version="$( ./build-unstable-deb.sh 2>/dev/null )"
|
2023-10-23 22:23:48 -04:00
|
|
|
echo " done. Package version ${version}."
|
2019-06-27 14:37:42 -04:00
|
|
|
|
|
|
|
# Install the client(s) locally
|
2024-01-10 14:22:12 -05:00
|
|
|
echo -n "> Installing client packages locally..."
|
2023-11-30 02:01:22 -05:00
|
|
|
$SUDO dpkg -i --force-all ../pvc-client*_${version}*.deb &>/dev/null
|
2023-10-23 22:23:48 -04:00
|
|
|
echo " done".
|
2019-06-27 14:37:42 -04:00
|
|
|
|
2024-01-10 14:22:12 -05:00
|
|
|
echo "> Copying packages..."
|
2019-06-27 14:37:42 -04:00
|
|
|
for HOST in ${HOSTS[@]}; do
|
2024-01-10 14:22:12 -05:00
|
|
|
echo -n ">>> Copying packages to host ${HOST}..."
|
2020-08-26 11:04:58 -04:00
|
|
|
ssh $HOST $SUDO rm -rf /tmp/pvc &>/dev/null
|
|
|
|
ssh $HOST mkdir /tmp/pvc &>/dev/null
|
|
|
|
scp ../pvc-*_${version}*.deb $HOST:/tmp/pvc/ &>/dev/null
|
2023-10-23 22:23:48 -04:00
|
|
|
echo " done."
|
2023-11-29 14:46:59 -05:00
|
|
|
done
|
|
|
|
if [[ -z ${KEEP_ARTIFACTS} ]]; then
|
|
|
|
rm ../pvc*_${version}*
|
|
|
|
fi
|
|
|
|
|
|
|
|
for HOST in ${HOSTS[@]}; do
|
2024-01-10 14:22:12 -05:00
|
|
|
echo "> Deploying packages on host ${HOST}"
|
|
|
|
echo -n ">>> Installing packages..."
|
2023-11-30 02:01:22 -05:00
|
|
|
ssh $HOST $SUDO dpkg -i --force-all /tmp/pvc/*.deb &>/dev/null
|
2020-08-26 11:04:58 -04:00
|
|
|
ssh $HOST rm -rf /tmp/pvc &>/dev/null
|
2023-10-23 22:23:48 -04:00
|
|
|
echo " done."
|
2024-01-10 14:22:12 -05:00
|
|
|
echo -n ">>> Restarting PVC daemons..."
|
2020-08-26 11:04:58 -04:00
|
|
|
ssh $HOST $SUDO systemctl restart pvcapid &>/dev/null
|
2023-11-29 16:14:45 -05:00
|
|
|
sleep 2
|
2023-11-15 19:13:48 -05:00
|
|
|
ssh $HOST $SUDO systemctl restart pvcworkerd &>/dev/null
|
2024-08-25 20:45:52 -04:00
|
|
|
if [[ -z ${API_ONLY} ]]; then
|
2023-11-29 16:14:45 -05:00
|
|
|
sleep 2
|
2023-11-29 15:36:49 -05:00
|
|
|
ssh $HOST $SUDO systemctl restart pvchealthd &>/dev/null
|
2024-01-10 14:22:12 -05:00
|
|
|
sleep 2
|
|
|
|
ssh $HOST $SUDO systemctl restart pvcnoded &>/dev/null
|
2023-10-23 22:23:48 -04:00
|
|
|
echo " done."
|
2024-01-10 14:22:12 -05:00
|
|
|
echo -n ">>> Waiting for node daemon to be running..."
|
2023-11-16 18:30:32 -05:00
|
|
|
while [[ $( ssh $HOST "pvc -q node list -f json ${HOST%%.*} | jq -r '.[].daemon_state'" 2>/dev/null ) != "run" ]]; do
|
2023-10-23 22:23:48 -04:00
|
|
|
sleep 5
|
|
|
|
echo -n "."
|
|
|
|
done
|
2024-08-25 20:45:52 -04:00
|
|
|
fi
|
2023-10-23 22:23:48 -04:00
|
|
|
echo " done."
|
2024-08-19 17:44:13 -04:00
|
|
|
if [[ -n ${PRIMARY_NODE} && ${PRIMARY_NODE} == ${HOST} ]]; then
|
2024-08-25 15:57:07 -04:00
|
|
|
echo -n ">>> Setting node $HOST to primary coordinator state... "
|
|
|
|
ssh $HOST pvc -q node primary --wait &>/dev/null
|
2024-08-25 14:18:18 -04:00
|
|
|
ssh $HOST $SUDO systemctl restart pvcworkerd &>/dev/null
|
2024-08-25 15:57:07 -04:00
|
|
|
echo "done."
|
2024-08-19 17:44:13 -04:00
|
|
|
fi
|
2019-06-27 14:37:42 -04:00
|
|
|
done
|
2021-11-06 03:16:02 -04:00
|
|
|
|
|
|
|
popd &>/dev/null
|