Saying that I have two services, which are to start two processes automatically while the system (Ubuntu 16.04.3) starts up.
One service file:
[Unit]
Description=service 1
Requires=init_mdc.service
After=rc.local.service init_mdc.service
[Service]
ExecStart=someCmd
ExecReload=someCmd
KillMode=process
Restart=on-failure
Type=simple
The other service file:
[Unit]
Description=service 2
Requires=init_mdc.service
After=rc.local.service init_mdc.service
[Service]
ExecStart=someCmd2
ExecReload=someCmd2
KillMode=process
Restart=on-failure
Type=simple
The two services need some same env variables.
For now my solution is not good, because the someCmd
s of the two services are two different bash scripts, in which I set the same env variables.
I'm thinking if I can set some env variables in some place in some way so that the two services can share them, in other words, I want to set the env variables only once, instead of two times.
I've tried to export these env variables from /etc/profile
, from /etc/rc.local
, but they don't work. I think it's because the system runs my two services first and then /etc/profile
and /etc/rc.local
are read by the system.
Is there some way to allow me to set some env variables for more than one service file? I've known that we can set EnvironmentFile=XXX
in the service file to import some env variables but I don't like this because I still have to set more than once EnvironmentFile=XXX
for each service service...