Remove diagram script; Add postgres-update script

This commit is contained in:
Tobias Reisinger 2023-12-09 20:51:45 +01:00
parent 1cb92e3825
commit 063b422426
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
3 changed files with 39 additions and 121 deletions

4
.gitignore vendored
View file

@ -2,9 +2,6 @@
.lego/
serguzim.net.png
diagram_assets/
# services already handled by ansible
/acme-dns/
/coder/
@ -12,6 +9,7 @@ diagram_assets/
/forgejo-runner/
/gitea/
/gitea-runner/
/healthcheck/
/homebox/
/influxdb/
/jellyfin/

38
_utils/postgres-update.sh Normal file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env sh
# shellcheck disable=SC2162
printf "\nWARNING: This script is work in progress and not tested yet. "; read
printf "\nStep 1: Backup done? "; read
printf "\nStep 2: Stop services - continue? "; read
systemctl stop postgresql.service
systemctl status postgresql.service --no-pager
printf "\nStep 3: Create directories and move data - continue? "; read
[ -d /var/lib/postgres/data ] && mv /var/lib/postgres/data /var/lib/postgres/olddata
mkdir /var/lib/postgres/data /var/lib/postgres/tmp
chown postgres:postgres /var/lib/postgres/data /var/lib/postgres/tmp
cd /var/lib/postgres/tmp || exit
printf "\nStep 4: Init new database - continue? "; read
sudo -u postgres initdb -D /var/lib/postgres/data --locale=en_US.UTF-8 --encoding=UTF8
printf "\nStep 5: Upgrade to new version - continue? "; read
printf "Old version: "; read -r pg_version
pg_path="/opt/pgsql-$pg_version/bin"
[ -d "$pg_path" ] || exit
sudo -u postgres pg_upgrade -b "$pg_path" -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data
printf "\nStep 6: Restart database - continue? "; read
systemctl start postgresql.service
systemctl status postgresql.service --no-pager
printf "\nStep 7: Cleanup - continue? "; read
sudo -u postgres vacuumdb --all --analyze-in-stages
rm -r /var/lib/postgres/olddata /var/lib/postgres/tmp
printf "\nDone. "; read

View file

@ -1,118 +0,0 @@
""" Diagram to visualize serguzim.net """
# pragma pylint: disable=pointless-statement
import glob
import mimetypes
import os
from urllib.request import urlretrieve
from diagrams import Cluster, Diagram
from diagrams.custom import Custom
from diagrams.oci.storage import ObjectStorage
from diagrams.onprem.database import Influxdb, Postgresql
from diagrams.onprem.inmemory import Redis
from diagrams.onprem.monitoring import Grafana, Prometheus
from diagrams.onprem.network import Caddy
from diagrams.onprem.vcs import Gitea
import requests
ASSETS_DIR = "./diagram_assets/"
os.makedirs(ASSETS_DIR, exist_ok=True)
def add_to_groups(service, *groups):
""" Add a service to groups like 'db_users' """
for group in groups:
group.append(service)
def get_custom_icon(name, url):
""" Download icon for service to location. Reuses existing icons. """
icon_no_extension = os.path.join(ASSETS_DIR, name)
exisiting_icons = glob.glob(icon_no_extension + ".*")
if exisiting_icons:
return exisiting_icons[0]
response = requests.head(url, allow_redirects=True)
extension = mimetypes.guess_extension(response.headers['Content-Type'])
icon = icon_no_extension + extension
urlretrieve(url, icon)
return icon
with Diagram("serguzim.net", show=False):
node001 = Cluster("node001.serguzim.net")
node002 = Cluster("node002.serguzim.net")
exoscale_objectstore = ObjectStorage("Exoscale Object Storage")
with node002:
services = []
db_users = []
objectstore_users = []
proxy = Caddy()
ICON_URL = "https://avatars.githubusercontent.com/u/105618662"
analytics = Custom("analytics.serguzim.me", get_custom_icon("umami", ICON_URL))
add_to_groups(analytics, services, db_users)
ICON_URL = "https://avatars.githubusercontent.com/u/84780935"
ci = Custom("ci.serguzim.me", get_custom_icon("woodpecker-ci", ICON_URL))
add_to_groups(ci, services, db_users)
db_time = Influxdb("tick.serguzim.me")
add_to_groups(db_time, services, db_users)
db = Postgresql("db.serguzim.me")
graph = Grafana("graph.serguzim.me")
add_to_groups(graph, services, db_users)
ICON_URL = "https://avatars.githubusercontent.com/u/40275816"
harbor = Custom("registry.serguzim.me", get_custom_icon("harbor", ICON_URL))
add_to_groups(harbor, services, db_users, objectstore_users)
ICON_URL = "https://avatars.githubusercontent.com/u/23747925"
mail = Custom("mail.serguzim.me", get_custom_icon("mailcow", ICON_URL))
add_to_groups(mail, services)
ICON_URL = "https://avatars.githubusercontent.com/u/8418310"
matrix = Custom("matrix.serguzim.me", get_custom_icon("matrix", ICON_URL))
add_to_groups(matrix, services, db_users, objectstore_users)
prometheus = Prometheus("prometheus.serguzim.me")
add_to_groups(prometheus, services)
ICON_URL = "https://github.com/TandoorRecipes/recipes/raw/develop/cookbook/static/assets/logo_color512.png"
recipies = Custom("recipies.serguzim.me", get_custom_icon("tandoor", ICON_URL))
add_to_groups(recipies, services, db_users)
vcs = Gitea("git.serguzim.me\nregistry.serguzim.me")
add_to_groups(vcs, services, db_users, objectstore_users)
webdis = Redis("webdis.huck.serguzim.me")
add_to_groups(webdis, services)
db_users >> db
proxy >> services
objectstore_users >> exoscale_objectstore
with node001:
services = []
proxy = Caddy()
ICON_URL = "https://icon-icons.com/downloadimage.php?id=168974&root=2699/PNG/256/&file=minecraft_logo_icon_168974.png"
minecraft = Custom("minecraft.serguzim.me", get_custom_icon("minecraft", ICON_URL))
add_to_groups(minecraft, services)
proxy >> services