From 393767257676f0161fb22a0247306478daf0416c Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Wed, 24 Jul 2024 17:07:30 +0200 Subject: [PATCH] Initial commit, with README and deploy script --- README.md | 22 ++++++++++++++++++++++ deploy.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 README.md create mode 100755 deploy.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..7dd4f34 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# App server configuration + +This repository contains the running configuration files for App server's services (containers). + +## Use +* all modifications to services' configurations should be done in this repository and then deployed +(see [below](#deployment)) +* then, after it's been tested and validated, a change can be commit and pushed +* this way, it is easy to revert to last working state + +### Deployment +Script `deploy.sh` copies configuration files for selected or all of below services, and then reloads Systemd and +restarts said services. + +## Services + +### Nspawn containers +We use Systemd Nspawn containers to host our applications. They reside in standard directory `/var/lib/machines`, +each mounted from a BTRFS subvolume (see [this repository](https://gitea.kto.black/adminconf/containers) for more +details). These containers' configuration thus reside in 2 places: +* `fstab` lists the subvolumes to mount +* `/etc/systemd/nspawn/` contains each container's configuration file diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..7c109f2 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +if [ "$1" = "" ]; then + echo "Please specify one of nspawn or all. Exiting." + exit 0 +fi + +nspawn=0 +for arg in "$@"; do + if [[ $arg = "nspawn" || $arg = "all" ]]; then + nspawn=1 + fi +done + +if [[ $nspawn -eq 0 ]]; then + echo "Please specify one of nspawn or all. Exiting." + exit 0 +fi + +run_directory=$(dirname $(readlink -f "$0")) + +if [[ $user != 'root' ]]; then + sudo="sudo" +else + sudo="" +fi + +if [[ $nspawn -eq 1 ]]; then + echo "Deploying nspawn containers configuration..." + echo "WARNING: Mind that containers will not be stopped or started, neither will subvolumes be mounted or unmounted." + $sudo rm /etc/systemd/nspawn/* + $sudo cp $run_directory/nspawn/*.nspawn /etc/systemd/nspawn/ + $sudo cp $run_directory/nspawn/fstab /etc/fstab +fi + +echo "Reloading Systemd..." +$sudo systemctl daemon-reload + +echo "Finished deployment. Exiting..." +exit 0