be more leniant on startup time of *arr services

This commit is contained in:
2026-03-27 23:05:39 -07:00
parent 35c6d1b821
commit c5ff0808d2
3 changed files with 243 additions and 8 deletions

View File

@@ -219,6 +219,21 @@ let
'';
};
apiTimeout = lib.mkOption {
type = lib.types.ints.positive;
default = 90;
description = ''
Seconds to wait for the application API to become available before
considering the init attempt failed. When the API is not reachable
within this window, the service exits non-zero and systemd's
Restart=on-failure will schedule another attempt after RestartSec.
The systemd start limit is computed from this value to allow 5 full
retry cycles before the unit enters permanent failure (which would
trigger any configured OnFailure= target).
'';
};
naming = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = { };
@@ -279,6 +294,21 @@ let
description = "API port of Bazarr.";
};
apiTimeout = lib.mkOption {
type = lib.types.ints.positive;
default = 90;
description = ''
Seconds to wait for the Bazarr API to become available before
considering the init attempt failed. When the API is not reachable
within this window, the service exits non-zero and systemd's
Restart=on-failure will schedule another attempt after RestartSec.
The systemd start limit is computed from this value to allow 5 full
retry cycles before the unit enters permanent failure (which would
trigger any configured OnFailure= target).
'';
};
sonarr = lib.mkOption {
type = bazarrProviderModule;
default = {
@@ -547,14 +577,14 @@ let
BASE_URL="http://127.0.0.1:${builtins.toString inst.port}/api/${inst.apiVersion}"
# Wait for API to become available
echo "Waiting for ${name} API..."
for i in $(seq 1 90); do
echo "Waiting for ${name} API (timeout: ${builtins.toString inst.apiTimeout}s)..."
for i in $(seq 1 ${builtins.toString inst.apiTimeout}); do
if ${curl} -sf --connect-timeout 5 "$BASE_URL/system/status" -H "X-Api-Key: $API_KEY" > /dev/null 2>&1; then
echo "${name} API is ready"
break
fi
if [ "$i" -eq 90 ]; then
echo "${name} API not available after 90 seconds" >&2
if [ "$i" -eq ${builtins.toString inst.apiTimeout} ]; then
echo "${name} API not available after ${builtins.toString inst.apiTimeout} seconds" >&2
exit 1
fi
sleep 1
@@ -625,14 +655,14 @@ let
BASE_URL="http://127.0.0.1:${builtins.toString bazarrCfg.port}"
# Wait for API to become available
echo "Waiting for Bazarr API..."
for i in $(seq 1 90); do
echo "Waiting for Bazarr API (timeout: ${builtins.toString bazarrCfg.apiTimeout}s)..."
for i in $(seq 1 ${builtins.toString bazarrCfg.apiTimeout}); do
if ${curl} -sf --connect-timeout 5 "$BASE_URL/api/system/status" -H "X-API-KEY: $API_KEY" > /dev/null 2>&1; then
echo "Bazarr API is ready"
break
fi
if [ "$i" -eq 90 ]; then
echo "Bazarr API not available after 90 seconds" >&2
if [ "$i" -eq ${builtins.toString bazarrCfg.apiTimeout} ]; then
echo "Bazarr API not available after ${builtins.toString bazarrCfg.apiTimeout} seconds" >&2
exit 1
fi
sleep 1
@@ -686,6 +716,12 @@ in
++ (lib.optional (inst.networkNamespacePath != null) "wg.service");
requires = [ "${inst.serviceName}.service" ] ++ (getDownloadClientDeps inst);
wantedBy = [ "multi-user.target" ];
unitConfig = {
# Allow 5 full retry cycles (apiTimeout + RestartSec each) before
# entering permanent failure, which is what triggers OnFailure=.
StartLimitIntervalSec = 5 * (inst.apiTimeout + 30);
StartLimitBurst = 5;
};
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
@@ -706,6 +742,10 @@ in
after = bazarrDeps;
requires = bazarrDeps;
wantedBy = [ "multi-user.target" ];
unitConfig = {
StartLimitIntervalSec = 5 * (bazarrCfg.apiTimeout + 30);
StartLimitBurst = 5;
};
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;