[systemd-devel] Variables in the [Unit] section of a server

Armin K. krejzi at email.com
Sat Jan 23 08:28:51 PST 2016


> 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

-------------- 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/90fbaade/attachment.sig>


More information about the systemd-devel mailing list