[systemd-devel] Configuring units (Was: Re: Can I use an EnvironmentFile to configure a Timer?)
Gesh
gesh at gesh.uni.cx
Thu Aug 22 11:44:49 UTC 2024
On Thu, Aug 22, 2024 at 11:26:24AM GMT, Lennart Poettering wrote:
> We only do env var expansion in ExecStart= and related line
> types. Nothing else. (And I think it actually was a mistake there too.)
This and other recent discussions[1] make me wonder what the intended
balance is of which parts of units are configured where.
As far as I'm aware, there are five ways to modify a unit's behaviour:
- Instance names. These are relatively inflexible, but can be
supplemented by referring to files like `%E/%n/%i` to be able to
configure any given profile.
- Adding to its environment. This is sometimes supplemented by using
Exec*'s envvar expansion which you discourage above (could you
elaborate why you consider it a misfeature? Is it because envvars
are a hard-to-track bit of context?).
I myself abuse this to give names to "local variables", as in
```
[Service]
Environment="DUMP=%S/%N.dump"
ExecStartPost=sh -c 'pizauth restore < ${DUMP}'
ExecStop=
ExecStop=sh -c 'pizauth dump > ${DUMP}'
ExecStop=pizauth shutdown
```
- Drop-ins. On the one hand, these give near-complete control,
allowing you to overwrite most directives. On the other, the absence
of certain features (cf [2], [3]) suggests some usages are
discouraged, though it isn't clear which.
- Additional units whose runtime is scoped to lie within that of the
configured unit (cf [1]). The semantics of this are unclear to me,
but I get the vague sense this should be used for cases where extra
features can be implemented on top of the existing unit?
- Wrapping the executable in a script that'll parse a configuration
file and run the executable with a modified commandline/environment.
Most flexible, but would seem to fly in the face of the intent to
obsolete the use of shell scripts in the init process?
I would appreciate guidance on the recommended balance, especially in
the following usecases:
- The "local variables" case mentioned above
- Adding a state load/save feature, as mentioned in [1]
- OP's usecase of configuring the timer frequency
- (Academic, but possibly illustrative): cf [4] -- adding flags to an
Exec* command line
Thanks,
Gesh
[1]: https://github.com/systemd/systemd/issues/33984#issuecomment-2302712137
[2]: https://github.com/systemd/systemd/issues/14971
[3]: https://github.com/systemd/systemd/issues/4148
[4]: https://superuser.com/a/1282178
More information about the systemd-devel
mailing list