feat(kadenios): Add management script
All checks were successful
build configuration / build_vault01 (push) Successful in 1m29s
build configuration / build_storage01 (push) Successful in 1m37s
build configuration / build_web02 (push) Successful in 1m56s
build configuration / build_compute01 (push) Successful in 2m0s
build configuration / build_web01 (push) Successful in 1m58s
lint / check (push) Successful in 29s
build configuration / build_rescue01 (push) Successful in 1m34s
build configuration / push_to_cache (push) Successful in 3m12s

This commit is contained in:
Tom Hubrecht 2024-07-09 14:32:04 +02:00
parent 954ba45281
commit 1bf5ad93a2

View file

@ -50,6 +50,19 @@ let
ps.loadcredential ps.loadcredential
]); ]);
manage = pkgs.writeShellApplication {
name = "kadenios-manage";
runtimeInputs = [ pythonEnv ];
text = ''
MainPID=0
eval "$(${lib.getExe' config.systemd.package "systemctl"} show -pMainPID django-kadenios.service)"
${lib.getExe' pkgs.util-linux "nsenter"} -e -a -t "$MainPID" -G follow -S follow python ${sources.kadenios}/manage.py "$@"
'';
};
staticDrv = pkgs.stdenv.mkDerivation { staticDrv = pkgs.stdenv.mkDerivation {
name = "kadenios-static"; name = "kadenios-static";
@ -88,6 +101,7 @@ let
in in
{ {
environment.systemPackages = [ manage ];
systemd.services = { systemd.services = {
django-kadenios = { django-kadenios = {
description = "ENS simple voting server"; description = "ENS simple voting server";
@ -105,7 +119,6 @@ in
}; };
StateDirectory = "django-kadenios"; StateDirectory = "django-kadenios";
User = "kadenios"; User = "kadenios";
WorkingDirectory = sources.kadenios;
}; };
inherit environment; inherit environment;
@ -113,7 +126,7 @@ in
path = [ pythonEnv ]; path = [ pythonEnv ];
script = '' script = ''
python3 manage.py migrate python3 ${sources.kadenios}/manage.py migrate
gunicorn app.wsgi --pythonpath ${sources.kadenios} -b 127.0.0.1:${builtins.toString port} --workers=2 --threads=4 gunicorn app.wsgi --pythonpath ${sources.kadenios} -b 127.0.0.1:${builtins.toString port} --workers=2 --threads=4
''; '';
}; };