drdeath
drdeath

Reputation: 133

process started by systemd does not see environment variables

I have the following system file:

[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
Environment=AWS_CONFIG_FILE='/etc/letsencrypt/aws_creds_prod.ini'
ExecStart=-/usr/bin/certbot renew --quiet --agree-tos --noninteractive

When it runs, the route-53-plugin complains that it can't find any config values.

If I do AWS_CONFIG_FILE='/etc/letsencrypt/aws_creds_prod.ini' /usr/bin/certbot renew --quiet --agree-tos --noninteractive in the commandline, it works.

If I create a service file looking like this:

[Unit]
Description=Environment Test

[Service]
Type=oneshot
Environment=AWS_CONFIG_FILE='/etc/letsencrypt/aws_creds_prod.ini'
ExecStart=-/bin/echo $AWS_CONFIG_FILE

I get the entry Apr 13 09:35:13 host.local echo[29756]: /etc/letsencrypt/aws_creds_prod.ini in the journal.

What am I overlooking? Why does the environment variable (which is obviously being set correctly) appear to be unset to the process?

Upvotes: 0

Views: 2695

Answers (1)

callmebob
callmebob

Reputation: 6323

Syntax for Environment in systemd can be one of the below 3 versions:

Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"

This will produce 3 variables:

VAR1 with value "word1 word2"

VAR2 with value "word3"

VAR3 with value "$word 5 6"

So the syntax you used (VAR='value') is incorrect.

You can see more details HERE

Upvotes: 2

Related Questions