Add deploy script for all cluster
This commit is contained in:
parent
252fffa6c2
commit
d70f9e2564
1 changed files with 45 additions and 11 deletions
|
|
@ -1,13 +1,47 @@
|
||||||
#! /usr/bin/env bash
|
if [ -z "$1" ]; then
|
||||||
|
# If no mode is specified it is local by default
|
||||||
if [ -z "${NODE:-}" ]
|
MODE="local"
|
||||||
then
|
else
|
||||||
echo "Erreur : Si c'est la première fois que vous déployez le serveur, merci de faire: sudo NODE='votre_node' ./deploy_nix.sh"
|
if [ "$1" = "local" ] || [ "$1" = "all" ]; then
|
||||||
|
MODE="$1"
|
||||||
|
else
|
||||||
|
echo "Mode $1 not recognized. Use either \`local\` for deployement on this node or \`all\` for deployement on the cluster."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
cp configuration.nix /etc/nixos/configuration.nix
|
# Get hostname for local deployement
|
||||||
cp cluster/nodes/$NODE.nix /etc/nixos/node.nix
|
HOSTNAME=$(hostname)
|
||||||
cp wgautomesh.nix /etc/nixos/wgautomesh.nix
|
|
||||||
cp cluster.nix /etc/nixos/cluster.nix
|
if [ "$MODE" = "local" ]; then
|
||||||
nixos-rebuild switch
|
echo "====== Started deployement for LOCAL NODE... ======"
|
||||||
|
echo "Copying files ..."
|
||||||
|
sudo cp ./configuration.nix /etc/nixos/
|
||||||
|
sudo cp ./cluster.nix /etc/nixos/
|
||||||
|
sudo cp ./wgautomesh.nix /etc/nixos/
|
||||||
|
sudo cp ./cluster/nodes/$HOSTNAME.nix /etc/nixos/node.nix
|
||||||
|
echo "Rebuilding nixOs ..."
|
||||||
|
sudo nixos-rebuild switch
|
||||||
|
elif [ "$MODE" = "all" ]; then
|
||||||
|
echo "====== Started deployement for ALL CLUSTER... ======"
|
||||||
|
read -r -s -p "Enter remote sudo password: " ROOT_PASS
|
||||||
|
# Get list of files in ./cluster/nodes to get hostnames of nodes
|
||||||
|
NIXHOSTLIST=$(ls cluster/nodes | grep '\.nix$')
|
||||||
|
for NIXHOST in $NIXHOSTLIST; do
|
||||||
|
NIXHOST=${NIXHOST%.*}
|
||||||
|
echo ""
|
||||||
|
echo "====== doing $NIXHOST ======"
|
||||||
|
echo "Copying files ..."
|
||||||
|
# Creating files and folder in /tmp/nixcfg with user permissions
|
||||||
|
# Because we cannot scp to root folder
|
||||||
|
echo "mkdir -p /tmp/nixcfg && rm -R /tmp/nixcfg/*" | ssh -p 1972 $NIXHOST.node.chokbar.bzh sh -
|
||||||
|
scp -P 1972 ./configuration.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/
|
||||||
|
scp -P 1972 ./cluster.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/
|
||||||
|
scp -P 1972 ./wgautomesh.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/
|
||||||
|
scp -P 1972 ./cluster/nodes/$NIXHOST.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/node.nix
|
||||||
|
echo "Moving them to /etc/nixos ..."
|
||||||
|
echo "sudo -S <<< $ROOT_PASS mv /tmp/nixcfg/* /etc/nixos/" | ssh -p 1972 $NIXHOST.node.chokbar.bzh sh -
|
||||||
|
echo "Rebuilding nixOs ..."
|
||||||
|
echo "sudo -S <<< $ROOT_PASS nixos-rebuild switch" | ssh -p 1972 $NIXHOST.node.chokbar.bzh sh -
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue