feat(kadenios): Add management script

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
''; '';
}; };