mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/netbox: move migration into the preStart netbox.service, reindex
Now migrations are run only on upgrade / downgrade and first start, which makes netbox much faster on a normal start. add the reindex for NetBox > 3.5.0, to populate the index, preventing empty search results. Migrations were moved out of netbox-migration.service into netbox.service, to prevent service dependency issues when upgrading NixOS.
This commit is contained in:
parent
a57a322b8d
commit
d1b0a9543d
1 changed files with 22 additions and 22 deletions
|
@ -264,39 +264,39 @@ in {
|
||||||
RestartSec = 30;
|
RestartSec = 30;
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
netbox-migration = {
|
|
||||||
description = "NetBox migrations";
|
|
||||||
wantedBy = [ "netbox.target" ];
|
|
||||||
|
|
||||||
environment = {
|
|
||||||
PYTHONPATH = pkg.pythonPath;
|
|
||||||
};
|
|
||||||
|
|
||||||
serviceConfig = defaultServiceConfig // {
|
|
||||||
Type = "oneshot";
|
|
||||||
ExecStart = ''
|
|
||||||
${pkg}/bin/netbox migrate
|
|
||||||
'';
|
|
||||||
PrivateTmp = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
netbox = {
|
netbox = {
|
||||||
description = "NetBox WSGI Service";
|
description = "NetBox WSGI Service";
|
||||||
documentation = [ "https://docs.netbox.dev/" ];
|
documentation = [ "https://docs.netbox.dev/" ];
|
||||||
|
|
||||||
wantedBy = [ "netbox.target" ];
|
wantedBy = [ "netbox.target" ];
|
||||||
|
|
||||||
after = [ "network-online.target" "netbox-migration.service" ];
|
after = [ "network-online.target" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
|
|
||||||
|
environment.PYTHONPATH = pkg.pythonPath;
|
||||||
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
|
# On the first run, or on upgrade / downgrade, run migrations and related.
|
||||||
|
# This mostly correspond to upstream NetBox's 'upgrade.sh' script.
|
||||||
|
versionFile="${cfg.dataDir}/version"
|
||||||
|
|
||||||
|
if [[ -e "$versionFile" && "$(cat "$versionFile")" == "${cfg.package.version}" ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
${pkg}/bin/netbox migrate
|
||||||
${pkg}/bin/netbox trace_paths --no-input
|
${pkg}/bin/netbox trace_paths --no-input
|
||||||
${pkg}/bin/netbox collectstatic --no-input
|
${pkg}/bin/netbox collectstatic --no-input
|
||||||
${pkg}/bin/netbox remove_stale_contenttypes --no-input
|
${pkg}/bin/netbox remove_stale_contenttypes --no-input
|
||||||
'';
|
# TODO: remove the condition when we remove netbox_3_3
|
||||||
|
${lib.optionalString
|
||||||
|
(lib.versionAtLeast cfg.package.version "3.5.0")
|
||||||
|
"${pkg}/bin/netbox reindex --lazy"}
|
||||||
|
${pkg}/bin/netbox clearsessions
|
||||||
|
${pkg}/bin/netbox clearcache
|
||||||
|
|
||||||
environment.PYTHONPATH = pkg.pythonPath;
|
echo "${cfg.package.version}" > "$versionFile"
|
||||||
|
'';
|
||||||
|
|
||||||
serviceConfig = defaultServiceConfig // {
|
serviceConfig = defaultServiceConfig // {
|
||||||
ExecStart = ''
|
ExecStart = ''
|
||||||
|
@ -331,7 +331,7 @@ in {
|
||||||
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" "netbox.service" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
|
|
||||||
environment.PYTHONPATH = pkg.pythonPath;
|
environment.PYTHONPATH = pkg.pythonPath;
|
||||||
|
@ -351,7 +351,7 @@ in {
|
||||||
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" "netbox.service" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
|
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue