5

I'm new-ish to systemd. I've got a service that's been working fine with the ExecStart command line hard-coded. Now I'm trying to parameterize it, and I found EnvironmentFile written up online. So I modified my service file as follows (some things obfuscated for privacy):

[Service]
Type=simple
EnvironmentFile=/etc/my-service/my-service-systemd.cfg
ExecStart=/usr/local/bin/my-service -port=$PORT -log-level=$LOG_LEVEL -creds=$CREDENTIALS_FILE
ExecStop=/bin/kill -15 $MAINPID

I checked, and the environment file /etc/my-service/my-service-systemd.cfg is definitely there:

CREDENTIALS_FILE=/etc/my-service/my-service.pwd
LOG_LEVEL=2
PORT=443

But when I run the service, it fails, and the logs indicate that all parameters are coming in empty, i.e. the service file is not passing in values from the EnvironmentFile.

What am I doing wrong?

0

2 Answers 2

6

There are rules on the expansion of the $ prefix in ExecStart and so on. There is a difference between $var and ${var}. The former will only be interpolated if it occurs as a word on its own (surrounded by whitespace). The latter does not have this restriction. So use, for example,

-port=${PORT}

The reference for this is under the heading COMMAND LINES in man systemd.service.

0
1

It may be related to file permissions. See if this fixes it:

chown root:root /etc/my-service/my-service-systemd.cfg 
chmod 0640 /etc/my-service/my-service-systemd.cfg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.