Results 1 to 7 of 7

Thread: How to check environment variables for a systemd process

  1. #1
    Join Date
    Jun 2008
    Location
    Düsseldorf/Germany
    Posts
    250

    Default How to check environment variables for a systemd process

    Hi,
    my problems seems to be a little more tricky.....I have a systemd-service, that runs under a system user, which is set as nologin-user (for safety reasons).
    When I start the service, it receives a config file for the environment:
    #Set the environment variables that GNU Health needs
    EnvironmentFile=/etc/tryton/gnuhealthrc
    How can I check that the service really uses the environment variables in that configfile?
    systemctl status .... does not give the right answers.....
    TIA!

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    27,231
    Blog Entries
    15

    Default Re: How to check environment variables for a systemd process

    Quote Originally Posted by DocB View Post
    Hi,
    my problems seems to be a little more tricky.....I have a systemd-service, that runs under a system user, which is set as nologin-user (for safety reasons).
    When I start the service, it receives a config file for the environment:

    How can I check that the service really uses the environment variables in that configfile?
    systemctl status .... does not give the right answers.....
    TIA!
    Hi
    Does it use the variables during startup, or just needs them at runtime?

    This is my htop one, it uses the variables else it won't start
    https://github.com/malcolmlewis/syst...r/htop.service
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,385

    Default Re: How to check environment variables for a systemd process

    It is not quite clear to me where you set that process environment variable. Putting the statement in a config file does not do much.What is done with that config file. In other words, what reads that config file and then executes that setting so that it is in the environment of a process and its offspring?

    The env command prints the environment, thus
    Code:
    env | grep EnvironmentFile
    will show if that variable is defined and what the value is of the current shell process where you are executing the env command. Of course it will then also be available to all child processes started from that shell.
    Henk van Velden

  4. #4
    Join Date
    Jun 2008
    Location
    Düsseldorf/Germany
    Posts
    250

    Default Re: How to check environment variables for a systemd process

    @Malcolm: it needs them at runtime. BTW, what does the '-' in front of the path (EnvironmentFile=-/etc/sysconfig/htop) do?

    @hcvv: The settings are triggered during the startup of the service, see https://build.opensuse.org/package/v...rvice?expand=1

    I have no idea how I could get into the process that runs the service, in order to see the the env for that process.
    The definitions in that rc file are:
    test@linux-q6gm:~> more /etc/tryton/gnuhealthrc
    alias cdlogs='cd /var/log/tryton'
    alias cdexe='cd $(ls -d /usr/lib/python3.* )/site-packages/trytond'
    alias cdconf='cd /etc/tryton'
    alias cdmods='cd $(ls -d /usr/lib/python3.* )/site-packages/trytond/modules'
    alias editconf='${EDITOR} /etc/tryton/trytond.conf'
    alias cdutil='cd /usr/bin'
    export GNUHEALTH_VERSION=3.4.0
    Actually, the client should read the GNUHEALTH_VERSION from the server's environment, but that seems to fail somehow. So, I'm checkeing step for step....

  5. #5
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    27,231
    Blog Entries
    15

    Default Re: How to check environment variables for a systemd process

    Quote Originally Posted by DocB View Post
    @Malcolm: it needs them at runtime. BTW, what does the '-' in front of the path (EnvironmentFile=-/etc/sysconfig/htop) do?

    @hcvv: The settings are triggered during the startup of the service, see https://build.opensuse.org/package/v...rvice?expand=1

    I have no idea how I could get into the process that runs the service, in order to see the the env for that process.
    The definitions in that rc file are:

    Actually, the client should read the GNUHEALTH_VERSION from the server's environment, but that seems to fail somehow. So, I'm checkeing step for step....
    Hi
    That "-" just means skip it if it doesn't exist...

    All the definitions used are in (I hate to say, the man page...) man systemd.exec which I think will give you the pointers you need.

    You can set the version in your service file via;
    Code:
    Environment=GNUHEALTH_VERSION=3.4.0
    The others are aliases and should be sourced in your start script (trytond) rather than via the service file;

    Code:
    <shebang>
    
    <add a test to check it exists, else exit>
    <if it exists then source it, {the period will do that}>
    . /etc/tryton/gnuhealthrc
    Last edited by malcolmlewis; 11-Dec-2018 at 14:38.
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  6. #6
    Join Date
    Sep 2012
    Posts
    5,230

    Default Re: How to check environment variables for a systemd process

    Quote Originally Posted by DocB View Post
    I have no idea how I could get into the process that runs the service, in order to see the the env for that process.
    Code:
    tr '\0' '\n' < /proc/$PID/environ

  7. #7
    Join Date
    Jun 2008
    Location
    Düsseldorf/Germany
    Posts
    250

    Default Re: How to check environment variables for a systemd process

    @arvidjar: Excellent hint, thanks!

    @malcolmlewis: sure, setting this in the service file would be an option (may do this for testing purposes).
    For the moment, all the settings in the gnuhealthrc are copied from /etc/bash.bashrc.local , which is generated in the specfile during the build process. Subject to improvement, but first getting it running.

    After some fiddeling I found that the entry in the configuration file is just
    variable = value (and no EXPORT or similar like on the bash side of life)

    Thanks Gentlemen!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •