restart sabnzbd service after init config generation
This commit is contained in:
+39
-13
@@ -9,11 +9,7 @@ with lib; let
|
|||||||
defaultPort = 8080;
|
defaultPort = 8080;
|
||||||
nixarr = config.nixarr;
|
nixarr = config.nixarr;
|
||||||
|
|
||||||
setDirsCmds = ''
|
edited-flag = "edited by nixarr";
|
||||||
| initool set - misc download_dir ${nixarr.mediaDir}/usenet/.incomplete \
|
|
||||||
| initool set - misc complete_dir ${nixarr.mediaDir}/usenet/manual \
|
|
||||||
| initool set - misc dirscan_dir ${nixarr.mediaDir}/usenet/.watch \
|
|
||||||
'';
|
|
||||||
|
|
||||||
mkSetHostWhitelistCmd = with lib.strings; (hosts: ''
|
mkSetHostWhitelistCmd = with lib.strings; (hosts: ''
|
||||||
| initool set - misc host_whitelist ${concatStringsSep "," hosts} \
|
| initool set - misc host_whitelist ${concatStringsSep "," hosts} \
|
||||||
@@ -23,8 +19,6 @@ with lib; let
|
|||||||
| initool set - misc local_ranges ${concatStringsSep "," ranges} \
|
| initool set - misc local_ranges ${concatStringsSep "," ranges} \
|
||||||
'');
|
'');
|
||||||
|
|
||||||
# todo: need to figure out what to do on first sabnzbd boot when no config file exists
|
|
||||||
|
|
||||||
mkINIInitScript = (
|
mkINIInitScript = (
|
||||||
{
|
{
|
||||||
sabnzbd-state-dir,
|
sabnzbd-state-dir,
|
||||||
@@ -36,12 +30,17 @@ with lib; let
|
|||||||
name = "set-sabnzbd-ini-values";
|
name = "set-sabnzbd-ini-values";
|
||||||
runtimeInputs = with pkgs; [initool];
|
runtimeInputs = with pkgs; [initool];
|
||||||
text = with lib.strings; (
|
text = with lib.strings; (
|
||||||
''
|
|
||||||
cat ${sabnzbd-state-dir}/sabnzbd.ini \
|
|
||||||
'' +
|
|
||||||
|
|
||||||
# set download dirs
|
# set download dirs
|
||||||
setDirsCmds +
|
''
|
||||||
|
if [ ! -f ${sabnzbd-state-dir}/sabnzbd.ini ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
initool set ${sabnzbd-state-dir}/sabnzbd.ini "" __comment__ '${edited-flag}' \
|
||||||
|
| initool set - misc download_dir "${nixarr.mediaDir}/usenet/.incomplete" \
|
||||||
|
| initool set - misc complete_dir "${nixarr.mediaDir}/usenet/manual" \
|
||||||
|
| initool set - misc dirscan_dir "${nixarr.mediaDir}/usenet/.watch" \
|
||||||
|
'' +
|
||||||
|
|
||||||
# set host to 0.0.0.0 if remote access needed
|
# set host to 0.0.0.0 if remote access needed
|
||||||
optionalString access-externally ''
|
optionalString access-externally ''
|
||||||
@@ -59,7 +58,8 @@ with lib; let
|
|||||||
) +
|
) +
|
||||||
|
|
||||||
''
|
''
|
||||||
> ${sabnzbd-state-dir}/sabnzbd.ini
|
> ${sabnzbd-state-dir}/sabnzbd.ini.tmp \
|
||||||
|
&& mv ${sabnzbd-state-dir}/sabnzbd.ini{.tmp,}
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -168,6 +168,32 @@ in {
|
|||||||
} + "/bin/set-sabnzbd-ini-values"
|
} + "/bin/set-sabnzbd-ini-values"
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
ExecStartPost = mkBefore [
|
||||||
|
(
|
||||||
|
"+" + pkgs.writeShellApplication {
|
||||||
|
name = "ensure-sabnzbd-config-edits";
|
||||||
|
runtimeInputs = with pkgs; [initool coreutils systemd];
|
||||||
|
text = ''
|
||||||
|
until [ -f "${cfg.stateDir}/sabnzbd.ini" ]
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
if ! initool get "${cfg.stateDir}/sabnzbd.ini" "" __comment__; then
|
||||||
|
# force sabnzbd.service restart for ExecStartPre to run now
|
||||||
|
# that sabnzbd.ini has been created by the instance
|
||||||
|
systemctl restart -f sabnzbd.service
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit
|
||||||
|
'';
|
||||||
|
} + "/bin/ensure-sabnzbd-config-edits"
|
||||||
|
)
|
||||||
|
];
|
||||||
|
Restart = "on-failure";
|
||||||
|
StartLimitInterval = 15;
|
||||||
|
StartLimitBurst = 5;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Enable and specify VPN namespace to confine service in.
|
# Enable and specify VPN namespace to confine service in.
|
||||||
|
|||||||
Reference in New Issue
Block a user