On Sun, 2019-12-08 at 15:55:45 -0800, Russ Allbery wrote: > Guillem Jover <guil...@debian.org> writes: > > But here you do have another option, but I'm not sure it might be > > described as nicer TBH, :) something like this, or variations on this > > theme: > > > [Service] > > Type=simple > > EnvironmentFile=/etc/default/service-static-vars > > EnvironmentFile=-/run/service-dynamic-vars > > ExecStartPre=-/bin/sh -c 'echo NAME=$(hostname) > > >/run/service-dynamic-vars' > > ExecStart=/usr/bin/daemon --option ${NAME} > > This is a nice approach, but I don't think it quite preserves the original > behavior. As you wrote it above, if someone changed the setting in the > /etc/default file, that would have no effect and the default would still > be used. If you reverse the order of EnvironmentFile, it avoids that > problem, but now the legacy setting with $(hostname) will be used if it > hasn't been changed, and that will result in a literal $(hostname) in the > value.
Right, it was more about showing the concept than a proper implementation, but it's true that as is, it's not helpful. :) I guess the following which starts to get a bit into ugly territory would do instead: [Service] Type=simple EnvironmentFile=-/run/service-dynamic-vars ExecStartPre=-/usr/bin/env -i /bin/sh -a -c '. /etc/default/service-static-vars && env -uPWD >/run/service-dynamic-vars' ExecStart=/usr/bin/daemon --option ${NAME} Thanks, Guillem