Discussion:
Systemd -- Using Environment variable in a Unit file from Environment File
(too old to reply)
Raghavendra. H. R
2017-05-26 09:36:30 UTC
Permalink
Raw Message
Hi All,

I'm in the situation where path of my server changes due to version change.
I don't want to modify my systemd unit file everytime, instead I want to go
ahead with my environement file for modification.

My Env file system.env contains environment variables

system.env
========
SERVER_PATH=/home/raghu/TAP/server/V110

In my systemd unit file I have included this enviroment file.

Tap.service
========
[Unit]
Description=Starting TAP server

[Service]
EnvironmentFile=/home/raghu/system.env
*WorkingDirectory=${SERVER_PATH}*
*ExecStart=/home/raghu/TAP/out "./server.js"*

[Install]
WantedBy=multi-user.target

I'm stuck with the below error

*error: Cannot find module '/server.js'*

${SERVER_PATH} is not set to my WorkingDirectory. Instead of using this
variable, if I give the absolute path, my unit file works well.

Need help in resoling this issue.

--
Regards,

Raghavendra. H. R
(Raghu)
Raghavendra. H. R
2017-05-29 02:51:56 UTC
Permalink
Raw Message
Guys,

Any suggestions about this kind of problem ?


--
Regards,

Raghavendra. H. R
(Raghu)
Post by Raghavendra. H. R
Hi All,
I'm in the situation where path of my server changes due to version
change. I don't want to modify my systemd unit file everytime, instead I
want to go ahead with my environement file for modification.
My Env file system.env contains environment variables
system.env
========
SERVER_PATH=/home/raghu/TAP/server/V110
In my systemd unit file I have included this enviroment file.
Tap.service
========
[Unit]
Description=Starting TAP server
[Service]
EnvironmentFile=/home/raghu/system.env
*WorkingDirectory=${SERVER_PATH}*
*ExecStart=/home/raghu/TAP/out "./server.js"*
[Install]
WantedBy=multi-user.target
I'm stuck with the below error
*error: Cannot find module '/server.js'*
${SERVER_PATH} is not set to my WorkingDirectory. Instead of using this
variable, if I give the absolute path, my unit file works well.
Need help in resoling this issue.
--
Regards,
Raghavendra. H. R
(Raghu)
Lennart Poettering
2017-05-29 09:12:24 UTC
Permalink
Raw Message
Post by Raghavendra. H. R
Hi All,
I'm in the situation where path of my server changes due to version change.
I don't want to modify my systemd unit file everytime, instead I want to go
ahead with my environement file for modification.
Please do not use environment files for that. Simply add or remove
unit drop-in files. i.e. if you want to make minor changes to a unit
file foobar.service then add
/etc/systemd/system/foobar.service.d/50-quux.conf or so, and add the
necessary settings there. "systemctl edit" helps you in doing so, and
make this easy.
Post by Raghavendra. H. R
EnvironmentFile=/home/raghu/system.env
*WorkingDirectory=${SERVER_PATH}*
Please read the documentation about EnvironmentFile=, its environment
variables configured what is passed to the executed processes, and may
be referenced in the ExecXYZ= line, but not in any other configuration
lines. THis is because the precise environment is determined at the
moment of activation, and settings generally have a broader definition
than that.

Lennart
--
Lennart Poettering, Red Hat
Loading...