You are not logged in.

#1 2019-08-11 10:05:37

Yann
Member
Registered: 2017-11-23
Posts: 235

[systemd] environment variable in called scripts

Hi everyone,

I am fighting with systemd, I ExecStart a script but can not access any environment variable from it. How can I get back in my script any global environment variable, such as $HOME (and others)..
there is my service:

[Unit]
Description=xxx
Before=sleep.target

[Service]
User=%i
Type=forking
Environment=DISPLAY=:0
ExecStart=myscript

[Install]
WantedBy=sleep.target

I already dug a lot, I can not use any variable with the environment.d way. And I can not find a way to get back an os global environment variable from a script called from systemd, I would like something similar to os.environ in python.

Thanks for your time.

Last edited by Yann (2019-08-11 15:43:24)


all different - all equal

Offline

#2 2019-08-15 09:57:08

ebal
Member
From: Athens, Greece
Registered: 2009-05-26
Posts: 224
Website

Re: [systemd] environment variable in called scripts

not sure, but can you try something like this:

Environment=User=%i

https://balaskas.gr
Linux System Engineer - Registered Linux User #420129

Offline

#3 2019-08-15 11:15:35

loqs
Member
Registered: 2014-03-06
Posts: 18,859

Re: [systemd] environment variable in called scripts

$HOME is a shell environment variable so it will not be set by systemd or a service started by systemd which does not have a shell as its parent.

Offline

#4 2019-08-15 11:30:14

nl6720
The Evil Wiki Admin
Registered: 2016-07-02
Posts: 714

Re: [systemd] environment variable in called scripts

$HOME is only set if you specify User=, see https://github.com/systemd/systemd/issu … -441452963 .

Offline

#5 2019-08-18 17:05:15

Yann
Member
Registered: 2017-11-23
Posts: 235

Re: [systemd] environment variable in called scripts

Thanks for the answers.
%i will represent the user calling the script, however, as it needs to be root, I will be root. But I would like to be me in this case smile
Also, I am talking about any shell environment variable, $HOME was an example.
I do agree with the loqs comment .. Any tips to perform that?
Thanks for your time.


all different - all equal

Offline

Board footer

Powered by FluxBB