[systemd-devel] Variables in the [Unit] section of a server
Armin K.
krejzi at email.com
Sat Jan 23 08:33:01 PST 2016
On 23.01.2016 17:28, Armin K. wrote:
>> On 01/13/2016 10:51 AM, Steve Dickson wrote:
>>> Hello,
>>>
>>> Is is possible to set a variable in the [Unit]
>>> section of a service?
>>>
>>> For example in rpc-gssd.service there is
>>> ConditionPathExists=/etc/krb5.keytab
>>>
>>> but for some installation the krb5.keytab
>>> is in a different place. The rpc.gssd daemon
>>> can be told this by setting a command line
>>> argument from the EnvironmentFile.
>>>
>>> So people have to edit both the EnvironmentFile
>>> and the rpc-gssd.service to make this change.
>>>
>>> So it would be nice if only the EnvironmentFile
>>> need to be edit and the change would happen
>>> in both places.
>>>
>>> Possible?
>>>
>>> steved.
>
> I'm sorry I'm not responding to the original mail, as I just subscribed
> yesterday to this list.
>
> I am not sure I fully understand what you want, but I think this might do it:
>
> [Unit]
> Description=test
>
> [Service]
> Type=oneshot
> Environment=TEST=blah
> EnvironmentFile=-/etc/systemd/system/test-env
> ExecStart=/etc/systemd/system/test ${TEST}
> TimeoutSec=0
> RemainAfterExit=yes
>
> The /etc/systemd/system/test is a script that prints $1, depending on what is
> being passed to it. When env file is not present, it prints the TEST from the
> unit file. When env file is present, and TEST is set to something else, it
> prints its value. Is that what you are looking for?
>
> Cheers
>
Ugh, sorry. You asked for the [Unit] section, not the [Service] section.
From what I see, it doesn't yet seem to be possible:
[/etc/systemd/system/test.service:2] Unknown lvalue 'Environment' in section 'Unit'
[/etc/systemd/system/test.service:4] Path in condition not absolute, ignoring: $TEST
You can always use some kind of hackery in ExecStartPre, but I don't think that's
what anyone wants.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20160123/ecf9a4c0/attachment.sig>
More information about the systemd-devel
mailing list