Allow a unit to declare "triggers" that force a restart

The triggers are just arbitrary strings that are included in the unit
under X-Restart-Triggers.  The idea is that if they change between
reconfigurations, switch-to-configuration will restart the unit
because its store path changed.  This is mostly useful for services
that implicitly depend on generated files in /etc.  Thus you can say

  restartTriggers = [ confFile ];

where ‘confFile’ is the derivation that generated the /etc file in
question.
This commit is contained in:
Eelco Dolstra 2012-10-11 17:54:43 -04:00
parent 285f587025
commit b606165bd9
2 changed files with 10 additions and 0 deletions

View file

@ -83,6 +83,15 @@ rec {
'';
};
restartTriggers = mkOption {
default = [];
description = ''
An arbitrary list of items such as derivations. If any item
in the list changes between reconfigurations, the service will
be restarted.
'';
};
};

View file

@ -176,6 +176,7 @@ let
Before = concatStringsSep " " config.before;
BindsTo = concatStringsSep " " config.bindsTo;
PartOf = concatStringsSep " " config.partOf;
"X-Restart-Triggers" = toString config.restartTriggers;
} // optionalAttrs (config.description != "") {
Description = config.description;
};