Newer
Older
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p jp
#
# Tell all servers belonging to a certain grid that they should update
# themselves to the latest configuration associated with that grid.
#
set -euxo pipefail
# Get the path to the ssh key which authorizes us to deliver this
# notification.
# Get the name of the grid to which we're going to deliver notification. This
# corresponds to the name of one of the directories in the top-level `morph`
# directory.
update_one_node() {
deploy_key=$1
shift
node=$1
shift
ssh -i "${deploy_key}" "deployment@${node}"
}
# Tell all servers belonging to one grid to update themselves.
update_grid_nodes() {
deploy_key=$1
shift
gridname=$1
shift
# Find the names of all hosts that belong to this grid. This list includes
# one extra string, "network", which is morph configuration stuff and we need
# to filter out later.
nodes=$(nix eval --json '(builtins.attrNames (import ./morph/${gridname}/grid.nix))')
# Tell every server in the network to update itself.
for node in ${nodes}; do
if [ "${node}" = "network" ]; then
# This isn't a server, it's part of the morph configuration.
continue
fi
update_one_node "${deploy_key}" "${node}"
}
update_grid_nodes "${DEPLOY_KEY}" "${GRIDNAME}"