I have a service that looks something like this:
[Unit]
Description=someApplication
...
[Service]
EnvironmentFile=/path/to/environment.file
Type=simple
User=$APPLICATION_USER
Group=$APPLICATION_GROUP
ExecStart=/bin/bash -c "$APPLICATION_HOME/app.sh $APPLICATION_OPTS"
PIDFile=$APPLICATION_HOME/application.pid
...
in my environment.file I have
APPLICATION_USER=test_user
APPLICATION_GROUP=test_group
APPLICATION_HOME=/opt/application
APPLICATION_OPTS= -d test
If I try starting this I get the message "Unit application.service entered failed state." if I move the properties for User and Group into the service it works.
Working example:
[Unit]
Description=someApplication
...
[Service]
EnvironmentFile=/path/to/environment.file
Type=simple
User=test_user
Group=test_group
ExecStart=/bin/bash -c "$APPLICATION_HOME/app.sh $APPLICATION_OPTS"
PIDFile=$APPLICATION_HOME/application.pid
Is there a way to move the User and Group into an environment file?
Systemd does not support environment substition for User and Group Options. See systemd.exec
You have to provide a literal string or id