forked from DGNum/colmena
Use nixops implementation of key services
This commit is contained in:
parent
64c46fa016
commit
691ac99e4d
1 changed files with 19 additions and 8 deletions
|
@ -78,19 +78,30 @@ with builtins; {
|
||||||
systemd.services = lib.mapAttrs' (name: val: {
|
systemd.services = lib.mapAttrs' (name: val: {
|
||||||
name = "${name}-key";
|
name = "${name}-key";
|
||||||
value = {
|
value = {
|
||||||
bindsTo = [ "${name}-key.path" ];
|
enable = true;
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Restart = "on-failure";
|
TimeoutStartSec = "infinity";
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = "100ms";
|
||||||
};
|
};
|
||||||
path = [ pkgs.inotify-tools ];
|
path = [ pkgs.inotify-tools ];
|
||||||
script = ''
|
preStart = ''
|
||||||
if [[ ! -e "${val.path}" ]]; then
|
(while read f; do if [ "$f" = "${val.name}" ]; then break; fi; done \
|
||||||
>&2 echo "${val.path} does not exist"
|
< <(inotifywait -qm --format '%f' -e create,move ${val.destDir}) ) &
|
||||||
|
if [[ -e "${val.path}" ]]; then
|
||||||
|
echo 'flapped down'
|
||||||
|
kill %1
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
wait %1
|
||||||
inotifywait -qq -e delete_self "${val.path}"
|
'';
|
||||||
>&2 echo "${val.path} disappeared"
|
script = ''
|
||||||
|
inotifywait -qq -e delete_self "${val.path}" &
|
||||||
|
if [[ ! -e "${val.path}" ]]; then
|
||||||
|
echo 'flapped up'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
wait %1
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}) config.deployment.keys;
|
}) config.deployment.keys;
|
||||||
|
|
Loading…
Reference in a new issue