Starting A DBus Session Application from systemd User Mode











up vote
0
down vote

favorite
1












I have a simple need to run a systemd user service with access to all of the environment variables provided by the user DBus session. Here's my example unit:



[Unit]
Description=Environment Demo

[Service]
Type=simple
Environment=DISPLAY=:0
ExecStart=/bin/bash -c 'env > shell.env.sh'
Restart=on-failure
RestartSec=5s
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=default.target


The keys exported are:



_
DISPLAY
HOME
LANG
LOGNAME
MANAGERPID
PATH
PWD
SHELL
SHLVL
USER
XDG_RUNTIME_DIR


This is a far cry from the full list of environment variables present if I launch a desktop application from my tray or from my launcher (I'm on elementary OS Loki aka Ubuntu 16.04 xenial). If I launch my terminal emulator (pantheon-terminal) and I get a sorted list of my environment variables, I get the following:



_
DBUS_SESSION_BUS_ADDRESS
DEFAULTS_PATH
DESKTOP_SESSION
DISPLAY
EDITOR
GDM_LANG
GDMSESSION
GIO_LAUNCHED_DESKTOP_FILE
GIO_LAUNCHED_DESKTOP_FILE_PID
GNOME_DESKTOP_SESSION_ID
GPG_TTY
GSETTINGS_SCHEMA_DIR
GTK_CSD
GTK_MODULES
HOME
LANG
LANGUAGE
LESSCLOSE
LESSOPEN
LOGNAME
LS_COLORS
MANDATORY_PATH
PANTHEON_TERMINAL_ID
PATH
PROMPT_COMMAND
PWD
QT_ACCESSIBILITY
QT_IM_MODULE
QT_LINUX_ACCESSIBILITY_ALWAYS_ON
QT_STYLE_OVERRIDE
SESSION_MANAGER
SHELL
SHLVL
SSH_AGENT_PID
SSH_AUTH_SOCK
TERM
USER
VTE_VERSION
XAUTHORITY
XDG_CONFIG_DIRS
XDG_CURRENT_DESKTOP
XDG_DATA_DIRS
XDG_GREETER_DATA_DIR
XDG_MENU_PREFIX
XDG_RUNTIME_DIR
XDG_SEAT
XDG_SEAT_PATH
XDG_SESSION_DESKTOP
XDG_SESSION_ID
XDG_SESSION_PATH
XDG_SESSION_TYPE
XDG_VTNR
XMODIFIERS


To make things more clear:



diff --git a/systemd-user.env.txt b/pantheon-terminal.env.txt
index c684056..f6d0685 100644
--- a/systemd-user.env.txt
+++ b/pantheon-terminal.env.txt
@@ -1,12 +1,54 @@
_
+DBUS_SESSION_BUS_ADDRESS
+DEFAULTS_PATH
+DESKTOP_SESSION
DISPLAY
+EDITOR
+GDM_LANG
+GDMSESSION
+GIO_LAUNCHED_DESKTOP_FILE
+GIO_LAUNCHED_DESKTOP_FILE_PID
+GNOME_DESKTOP_SESSION_ID
+GPG_TTY
+GSETTINGS_SCHEMA_DIR
+GTK_CSD
+GTK_MODULES
HOME
LANG
+LANGUAGE
+LESSCLOSE
+LESSOPEN
LOGNAME
-MANAGERPID
+LS_COLORS
+MANDATORY_PATH
+PANTHEON_TERMINAL_ID
PATH
+PROMPT_COMMAND
PWD
+QT_ACCESSIBILITY
+QT_IM_MODULE
+QT_LINUX_ACCESSIBILITY_ALWAYS_ON
+QT_STYLE_OVERRIDE
+SESSION_MANAGER
SHELL
SHLVL
+SSH_AGENT_PID
+SSH_AUTH_SOCK
+TERM
USER
+VTE_VERSION
+XAUTHORITY
+XDG_CONFIG_DIRS
+XDG_CURRENT_DESKTOP
+XDG_DATA_DIRS
+XDG_GREETER_DATA_DIR
+XDG_MENU_PREFIX
XDG_RUNTIME_DIR
+XDG_SEAT
+XDG_SEAT_PATH
+XDG_SESSION_DESKTOP
+XDG_SESSION_ID
+XDG_SESSION_PATH
+XDG_SESSION_TYPE
+XDG_VTNR
+XMODIFIERS


There are somewhere around 30 more environment variables when starting something this way.





My use case is this: I want to be able to start processes with a full environment like in the context of launching my terminal application.



How can I expose a full(er) environment to my systemd user daemons?










share|improve this question


























    up vote
    0
    down vote

    favorite
    1












    I have a simple need to run a systemd user service with access to all of the environment variables provided by the user DBus session. Here's my example unit:



    [Unit]
    Description=Environment Demo

    [Service]
    Type=simple
    Environment=DISPLAY=:0
    ExecStart=/bin/bash -c 'env > shell.env.sh'
    Restart=on-failure
    RestartSec=5s
    StandardOutput=journal
    StandardError=journal

    [Install]
    WantedBy=default.target


    The keys exported are:



    _
    DISPLAY
    HOME
    LANG
    LOGNAME
    MANAGERPID
    PATH
    PWD
    SHELL
    SHLVL
    USER
    XDG_RUNTIME_DIR


    This is a far cry from the full list of environment variables present if I launch a desktop application from my tray or from my launcher (I'm on elementary OS Loki aka Ubuntu 16.04 xenial). If I launch my terminal emulator (pantheon-terminal) and I get a sorted list of my environment variables, I get the following:



    _
    DBUS_SESSION_BUS_ADDRESS
    DEFAULTS_PATH
    DESKTOP_SESSION
    DISPLAY
    EDITOR
    GDM_LANG
    GDMSESSION
    GIO_LAUNCHED_DESKTOP_FILE
    GIO_LAUNCHED_DESKTOP_FILE_PID
    GNOME_DESKTOP_SESSION_ID
    GPG_TTY
    GSETTINGS_SCHEMA_DIR
    GTK_CSD
    GTK_MODULES
    HOME
    LANG
    LANGUAGE
    LESSCLOSE
    LESSOPEN
    LOGNAME
    LS_COLORS
    MANDATORY_PATH
    PANTHEON_TERMINAL_ID
    PATH
    PROMPT_COMMAND
    PWD
    QT_ACCESSIBILITY
    QT_IM_MODULE
    QT_LINUX_ACCESSIBILITY_ALWAYS_ON
    QT_STYLE_OVERRIDE
    SESSION_MANAGER
    SHELL
    SHLVL
    SSH_AGENT_PID
    SSH_AUTH_SOCK
    TERM
    USER
    VTE_VERSION
    XAUTHORITY
    XDG_CONFIG_DIRS
    XDG_CURRENT_DESKTOP
    XDG_DATA_DIRS
    XDG_GREETER_DATA_DIR
    XDG_MENU_PREFIX
    XDG_RUNTIME_DIR
    XDG_SEAT
    XDG_SEAT_PATH
    XDG_SESSION_DESKTOP
    XDG_SESSION_ID
    XDG_SESSION_PATH
    XDG_SESSION_TYPE
    XDG_VTNR
    XMODIFIERS


    To make things more clear:



    diff --git a/systemd-user.env.txt b/pantheon-terminal.env.txt
    index c684056..f6d0685 100644
    --- a/systemd-user.env.txt
    +++ b/pantheon-terminal.env.txt
    @@ -1,12 +1,54 @@
    _
    +DBUS_SESSION_BUS_ADDRESS
    +DEFAULTS_PATH
    +DESKTOP_SESSION
    DISPLAY
    +EDITOR
    +GDM_LANG
    +GDMSESSION
    +GIO_LAUNCHED_DESKTOP_FILE
    +GIO_LAUNCHED_DESKTOP_FILE_PID
    +GNOME_DESKTOP_SESSION_ID
    +GPG_TTY
    +GSETTINGS_SCHEMA_DIR
    +GTK_CSD
    +GTK_MODULES
    HOME
    LANG
    +LANGUAGE
    +LESSCLOSE
    +LESSOPEN
    LOGNAME
    -MANAGERPID
    +LS_COLORS
    +MANDATORY_PATH
    +PANTHEON_TERMINAL_ID
    PATH
    +PROMPT_COMMAND
    PWD
    +QT_ACCESSIBILITY
    +QT_IM_MODULE
    +QT_LINUX_ACCESSIBILITY_ALWAYS_ON
    +QT_STYLE_OVERRIDE
    +SESSION_MANAGER
    SHELL
    SHLVL
    +SSH_AGENT_PID
    +SSH_AUTH_SOCK
    +TERM
    USER
    +VTE_VERSION
    +XAUTHORITY
    +XDG_CONFIG_DIRS
    +XDG_CURRENT_DESKTOP
    +XDG_DATA_DIRS
    +XDG_GREETER_DATA_DIR
    +XDG_MENU_PREFIX
    XDG_RUNTIME_DIR
    +XDG_SEAT
    +XDG_SEAT_PATH
    +XDG_SESSION_DESKTOP
    +XDG_SESSION_ID
    +XDG_SESSION_PATH
    +XDG_SESSION_TYPE
    +XDG_VTNR
    +XMODIFIERS


    There are somewhere around 30 more environment variables when starting something this way.





    My use case is this: I want to be able to start processes with a full environment like in the context of launching my terminal application.



    How can I expose a full(er) environment to my systemd user daemons?










    share|improve this question
























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I have a simple need to run a systemd user service with access to all of the environment variables provided by the user DBus session. Here's my example unit:



      [Unit]
      Description=Environment Demo

      [Service]
      Type=simple
      Environment=DISPLAY=:0
      ExecStart=/bin/bash -c 'env > shell.env.sh'
      Restart=on-failure
      RestartSec=5s
      StandardOutput=journal
      StandardError=journal

      [Install]
      WantedBy=default.target


      The keys exported are:



      _
      DISPLAY
      HOME
      LANG
      LOGNAME
      MANAGERPID
      PATH
      PWD
      SHELL
      SHLVL
      USER
      XDG_RUNTIME_DIR


      This is a far cry from the full list of environment variables present if I launch a desktop application from my tray or from my launcher (I'm on elementary OS Loki aka Ubuntu 16.04 xenial). If I launch my terminal emulator (pantheon-terminal) and I get a sorted list of my environment variables, I get the following:



      _
      DBUS_SESSION_BUS_ADDRESS
      DEFAULTS_PATH
      DESKTOP_SESSION
      DISPLAY
      EDITOR
      GDM_LANG
      GDMSESSION
      GIO_LAUNCHED_DESKTOP_FILE
      GIO_LAUNCHED_DESKTOP_FILE_PID
      GNOME_DESKTOP_SESSION_ID
      GPG_TTY
      GSETTINGS_SCHEMA_DIR
      GTK_CSD
      GTK_MODULES
      HOME
      LANG
      LANGUAGE
      LESSCLOSE
      LESSOPEN
      LOGNAME
      LS_COLORS
      MANDATORY_PATH
      PANTHEON_TERMINAL_ID
      PATH
      PROMPT_COMMAND
      PWD
      QT_ACCESSIBILITY
      QT_IM_MODULE
      QT_LINUX_ACCESSIBILITY_ALWAYS_ON
      QT_STYLE_OVERRIDE
      SESSION_MANAGER
      SHELL
      SHLVL
      SSH_AGENT_PID
      SSH_AUTH_SOCK
      TERM
      USER
      VTE_VERSION
      XAUTHORITY
      XDG_CONFIG_DIRS
      XDG_CURRENT_DESKTOP
      XDG_DATA_DIRS
      XDG_GREETER_DATA_DIR
      XDG_MENU_PREFIX
      XDG_RUNTIME_DIR
      XDG_SEAT
      XDG_SEAT_PATH
      XDG_SESSION_DESKTOP
      XDG_SESSION_ID
      XDG_SESSION_PATH
      XDG_SESSION_TYPE
      XDG_VTNR
      XMODIFIERS


      To make things more clear:



      diff --git a/systemd-user.env.txt b/pantheon-terminal.env.txt
      index c684056..f6d0685 100644
      --- a/systemd-user.env.txt
      +++ b/pantheon-terminal.env.txt
      @@ -1,12 +1,54 @@
      _
      +DBUS_SESSION_BUS_ADDRESS
      +DEFAULTS_PATH
      +DESKTOP_SESSION
      DISPLAY
      +EDITOR
      +GDM_LANG
      +GDMSESSION
      +GIO_LAUNCHED_DESKTOP_FILE
      +GIO_LAUNCHED_DESKTOP_FILE_PID
      +GNOME_DESKTOP_SESSION_ID
      +GPG_TTY
      +GSETTINGS_SCHEMA_DIR
      +GTK_CSD
      +GTK_MODULES
      HOME
      LANG
      +LANGUAGE
      +LESSCLOSE
      +LESSOPEN
      LOGNAME
      -MANAGERPID
      +LS_COLORS
      +MANDATORY_PATH
      +PANTHEON_TERMINAL_ID
      PATH
      +PROMPT_COMMAND
      PWD
      +QT_ACCESSIBILITY
      +QT_IM_MODULE
      +QT_LINUX_ACCESSIBILITY_ALWAYS_ON
      +QT_STYLE_OVERRIDE
      +SESSION_MANAGER
      SHELL
      SHLVL
      +SSH_AGENT_PID
      +SSH_AUTH_SOCK
      +TERM
      USER
      +VTE_VERSION
      +XAUTHORITY
      +XDG_CONFIG_DIRS
      +XDG_CURRENT_DESKTOP
      +XDG_DATA_DIRS
      +XDG_GREETER_DATA_DIR
      +XDG_MENU_PREFIX
      XDG_RUNTIME_DIR
      +XDG_SEAT
      +XDG_SEAT_PATH
      +XDG_SESSION_DESKTOP
      +XDG_SESSION_ID
      +XDG_SESSION_PATH
      +XDG_SESSION_TYPE
      +XDG_VTNR
      +XMODIFIERS


      There are somewhere around 30 more environment variables when starting something this way.





      My use case is this: I want to be able to start processes with a full environment like in the context of launching my terminal application.



      How can I expose a full(er) environment to my systemd user daemons?










      share|improve this question













      I have a simple need to run a systemd user service with access to all of the environment variables provided by the user DBus session. Here's my example unit:



      [Unit]
      Description=Environment Demo

      [Service]
      Type=simple
      Environment=DISPLAY=:0
      ExecStart=/bin/bash -c 'env > shell.env.sh'
      Restart=on-failure
      RestartSec=5s
      StandardOutput=journal
      StandardError=journal

      [Install]
      WantedBy=default.target


      The keys exported are:



      _
      DISPLAY
      HOME
      LANG
      LOGNAME
      MANAGERPID
      PATH
      PWD
      SHELL
      SHLVL
      USER
      XDG_RUNTIME_DIR


      This is a far cry from the full list of environment variables present if I launch a desktop application from my tray or from my launcher (I'm on elementary OS Loki aka Ubuntu 16.04 xenial). If I launch my terminal emulator (pantheon-terminal) and I get a sorted list of my environment variables, I get the following:



      _
      DBUS_SESSION_BUS_ADDRESS
      DEFAULTS_PATH
      DESKTOP_SESSION
      DISPLAY
      EDITOR
      GDM_LANG
      GDMSESSION
      GIO_LAUNCHED_DESKTOP_FILE
      GIO_LAUNCHED_DESKTOP_FILE_PID
      GNOME_DESKTOP_SESSION_ID
      GPG_TTY
      GSETTINGS_SCHEMA_DIR
      GTK_CSD
      GTK_MODULES
      HOME
      LANG
      LANGUAGE
      LESSCLOSE
      LESSOPEN
      LOGNAME
      LS_COLORS
      MANDATORY_PATH
      PANTHEON_TERMINAL_ID
      PATH
      PROMPT_COMMAND
      PWD
      QT_ACCESSIBILITY
      QT_IM_MODULE
      QT_LINUX_ACCESSIBILITY_ALWAYS_ON
      QT_STYLE_OVERRIDE
      SESSION_MANAGER
      SHELL
      SHLVL
      SSH_AGENT_PID
      SSH_AUTH_SOCK
      TERM
      USER
      VTE_VERSION
      XAUTHORITY
      XDG_CONFIG_DIRS
      XDG_CURRENT_DESKTOP
      XDG_DATA_DIRS
      XDG_GREETER_DATA_DIR
      XDG_MENU_PREFIX
      XDG_RUNTIME_DIR
      XDG_SEAT
      XDG_SEAT_PATH
      XDG_SESSION_DESKTOP
      XDG_SESSION_ID
      XDG_SESSION_PATH
      XDG_SESSION_TYPE
      XDG_VTNR
      XMODIFIERS


      To make things more clear:



      diff --git a/systemd-user.env.txt b/pantheon-terminal.env.txt
      index c684056..f6d0685 100644
      --- a/systemd-user.env.txt
      +++ b/pantheon-terminal.env.txt
      @@ -1,12 +1,54 @@
      _
      +DBUS_SESSION_BUS_ADDRESS
      +DEFAULTS_PATH
      +DESKTOP_SESSION
      DISPLAY
      +EDITOR
      +GDM_LANG
      +GDMSESSION
      +GIO_LAUNCHED_DESKTOP_FILE
      +GIO_LAUNCHED_DESKTOP_FILE_PID
      +GNOME_DESKTOP_SESSION_ID
      +GPG_TTY
      +GSETTINGS_SCHEMA_DIR
      +GTK_CSD
      +GTK_MODULES
      HOME
      LANG
      +LANGUAGE
      +LESSCLOSE
      +LESSOPEN
      LOGNAME
      -MANAGERPID
      +LS_COLORS
      +MANDATORY_PATH
      +PANTHEON_TERMINAL_ID
      PATH
      +PROMPT_COMMAND
      PWD
      +QT_ACCESSIBILITY
      +QT_IM_MODULE
      +QT_LINUX_ACCESSIBILITY_ALWAYS_ON
      +QT_STYLE_OVERRIDE
      +SESSION_MANAGER
      SHELL
      SHLVL
      +SSH_AGENT_PID
      +SSH_AUTH_SOCK
      +TERM
      USER
      +VTE_VERSION
      +XAUTHORITY
      +XDG_CONFIG_DIRS
      +XDG_CURRENT_DESKTOP
      +XDG_DATA_DIRS
      +XDG_GREETER_DATA_DIR
      +XDG_MENU_PREFIX
      XDG_RUNTIME_DIR
      +XDG_SEAT
      +XDG_SEAT_PATH
      +XDG_SESSION_DESKTOP
      +XDG_SESSION_ID
      +XDG_SESSION_PATH
      +XDG_SESSION_TYPE
      +XDG_VTNR
      +XMODIFIERS


      There are somewhere around 30 more environment variables when starting something this way.





      My use case is this: I want to be able to start processes with a full environment like in the context of launching my terminal application.



      How can I expose a full(er) environment to my systemd user daemons?







      systemd environment-variables d-bus systemd-user






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 2 '17 at 6:40









      Naftuli Kay

      12k55156250




      12k55156250






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          0
          down vote













          You may find some help in the ArchLinux wiki page which discusses setting the environment for user Units. In particular,



          systemctl --user import-environment 


          will export all the current environment variables into your systemd user environment. You can provide an explicit list of variables instead. You can check by running



          systemctl --user show-environment


          before and after. There is also



          systemctl --user set-environment MYVAR=myvalue ...
          systemctl --user unset-environment MYVAR ...


          See the systemctl man page.
          The wiki also mentions a dbus specific alternative with which I had less success:



          dbus-update-activation-environment --systemd --all





          share|improve this answer

















          • 1




            OP might also want to look at ~/.config/environment.d. See unix.stackexchange.com/a/403196/23305.
            – Jack O'Connor
            Nov 7 '17 at 23:42




















          up vote
          0
          down vote













          My solution takes into account @meuh's solution above and some digging.



          Step one is to create a dummy user unit called dbus-environment.service:



          [Unit]
          Description=Environment Imported Target

          [Service]
          Type=oneshot
          RemainAfterExit=true
          ExecStart=/bin/true


          Next step is to create a Bash script:



          #!/bin/bash

          systemctl --user import-environment
          systemctl --user start dbus-environment.service


          Next, add this script to your window manager's startup applications which are guaranteed to run within the DBUS session and the window manager, X, etc.



          On session login, the script will be called, importing everything into the systemd user daemon.



          Next, for all units depending on these environment variables, simply have them depend on dbus-environment.service:



          [Unit]
          Description=Duplicity Backup Service
          Requires=dbus-environment.service
          After=dbus-environment.service

          [Service]
          Type=oneshot
          ExecStart=/home/naftuli/.local/bin/duply home backup


          At this point, when this service starts, it is guaranteed to have the environment imported. Perhaps I should be using a target rather than a service, but that exercise will have to wait.






          share|improve this answer




























            up vote
            0
            down vote













            @Naftuli:
            Would it not have been better to instead use something like this in all your services unit files?



            ExecStartPre=usrbinsh -c "systemctl --user import-environment"





            share|improve this answer























            • That would not solve it. The current execution context is systemd, which doesn't have the display manager environment variables. Executing a shell will not have it automatically inherit these environment variables. You need something that is guaranteed to inherit these variables, so a normal shell won't have them.
              – Naftuli Kay
              Jul 30 at 14:30










            • Thanks! I am a newbie. Still trying to understand systemd. I am actually also stuck in a similar situation where in I would like to import all environment variable available to the user to the system service daemon.. There is no possibility for me to use a script to import these variables. Have you come across another solution so that all the variables which have been set for the users becomes visible to service daemon? Thanks!
              – Robin
              Jul 30 at 14:37












            • dbus-launch might be able to do something. I was originally crawling the /proc/PID/env of the dbus session to get its address and then call dbus-launch
              – Naftuli Kay
              Jul 30 at 14:39











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f368730%2fstarting-a-dbus-session-application-from-systemd-user-mode%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            You may find some help in the ArchLinux wiki page which discusses setting the environment for user Units. In particular,



            systemctl --user import-environment 


            will export all the current environment variables into your systemd user environment. You can provide an explicit list of variables instead. You can check by running



            systemctl --user show-environment


            before and after. There is also



            systemctl --user set-environment MYVAR=myvalue ...
            systemctl --user unset-environment MYVAR ...


            See the systemctl man page.
            The wiki also mentions a dbus specific alternative with which I had less success:



            dbus-update-activation-environment --systemd --all





            share|improve this answer

















            • 1




              OP might also want to look at ~/.config/environment.d. See unix.stackexchange.com/a/403196/23305.
              – Jack O'Connor
              Nov 7 '17 at 23:42

















            up vote
            0
            down vote













            You may find some help in the ArchLinux wiki page which discusses setting the environment for user Units. In particular,



            systemctl --user import-environment 


            will export all the current environment variables into your systemd user environment. You can provide an explicit list of variables instead. You can check by running



            systemctl --user show-environment


            before and after. There is also



            systemctl --user set-environment MYVAR=myvalue ...
            systemctl --user unset-environment MYVAR ...


            See the systemctl man page.
            The wiki also mentions a dbus specific alternative with which I had less success:



            dbus-update-activation-environment --systemd --all





            share|improve this answer

















            • 1




              OP might also want to look at ~/.config/environment.d. See unix.stackexchange.com/a/403196/23305.
              – Jack O'Connor
              Nov 7 '17 at 23:42















            up vote
            0
            down vote










            up vote
            0
            down vote









            You may find some help in the ArchLinux wiki page which discusses setting the environment for user Units. In particular,



            systemctl --user import-environment 


            will export all the current environment variables into your systemd user environment. You can provide an explicit list of variables instead. You can check by running



            systemctl --user show-environment


            before and after. There is also



            systemctl --user set-environment MYVAR=myvalue ...
            systemctl --user unset-environment MYVAR ...


            See the systemctl man page.
            The wiki also mentions a dbus specific alternative with which I had less success:



            dbus-update-activation-environment --systemd --all





            share|improve this answer












            You may find some help in the ArchLinux wiki page which discusses setting the environment for user Units. In particular,



            systemctl --user import-environment 


            will export all the current environment variables into your systemd user environment. You can provide an explicit list of variables instead. You can check by running



            systemctl --user show-environment


            before and after. There is also



            systemctl --user set-environment MYVAR=myvalue ...
            systemctl --user unset-environment MYVAR ...


            See the systemctl man page.
            The wiki also mentions a dbus specific alternative with which I had less success:



            dbus-update-activation-environment --systemd --all






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 3 '17 at 19:17









            meuh

            31.2k11754




            31.2k11754








            • 1




              OP might also want to look at ~/.config/environment.d. See unix.stackexchange.com/a/403196/23305.
              – Jack O'Connor
              Nov 7 '17 at 23:42
















            • 1




              OP might also want to look at ~/.config/environment.d. See unix.stackexchange.com/a/403196/23305.
              – Jack O'Connor
              Nov 7 '17 at 23:42










            1




            1




            OP might also want to look at ~/.config/environment.d. See unix.stackexchange.com/a/403196/23305.
            – Jack O'Connor
            Nov 7 '17 at 23:42






            OP might also want to look at ~/.config/environment.d. See unix.stackexchange.com/a/403196/23305.
            – Jack O'Connor
            Nov 7 '17 at 23:42














            up vote
            0
            down vote













            My solution takes into account @meuh's solution above and some digging.



            Step one is to create a dummy user unit called dbus-environment.service:



            [Unit]
            Description=Environment Imported Target

            [Service]
            Type=oneshot
            RemainAfterExit=true
            ExecStart=/bin/true


            Next step is to create a Bash script:



            #!/bin/bash

            systemctl --user import-environment
            systemctl --user start dbus-environment.service


            Next, add this script to your window manager's startup applications which are guaranteed to run within the DBUS session and the window manager, X, etc.



            On session login, the script will be called, importing everything into the systemd user daemon.



            Next, for all units depending on these environment variables, simply have them depend on dbus-environment.service:



            [Unit]
            Description=Duplicity Backup Service
            Requires=dbus-environment.service
            After=dbus-environment.service

            [Service]
            Type=oneshot
            ExecStart=/home/naftuli/.local/bin/duply home backup


            At this point, when this service starts, it is guaranteed to have the environment imported. Perhaps I should be using a target rather than a service, but that exercise will have to wait.






            share|improve this answer

























              up vote
              0
              down vote













              My solution takes into account @meuh's solution above and some digging.



              Step one is to create a dummy user unit called dbus-environment.service:



              [Unit]
              Description=Environment Imported Target

              [Service]
              Type=oneshot
              RemainAfterExit=true
              ExecStart=/bin/true


              Next step is to create a Bash script:



              #!/bin/bash

              systemctl --user import-environment
              systemctl --user start dbus-environment.service


              Next, add this script to your window manager's startup applications which are guaranteed to run within the DBUS session and the window manager, X, etc.



              On session login, the script will be called, importing everything into the systemd user daemon.



              Next, for all units depending on these environment variables, simply have them depend on dbus-environment.service:



              [Unit]
              Description=Duplicity Backup Service
              Requires=dbus-environment.service
              After=dbus-environment.service

              [Service]
              Type=oneshot
              ExecStart=/home/naftuli/.local/bin/duply home backup


              At this point, when this service starts, it is guaranteed to have the environment imported. Perhaps I should be using a target rather than a service, but that exercise will have to wait.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                My solution takes into account @meuh's solution above and some digging.



                Step one is to create a dummy user unit called dbus-environment.service:



                [Unit]
                Description=Environment Imported Target

                [Service]
                Type=oneshot
                RemainAfterExit=true
                ExecStart=/bin/true


                Next step is to create a Bash script:



                #!/bin/bash

                systemctl --user import-environment
                systemctl --user start dbus-environment.service


                Next, add this script to your window manager's startup applications which are guaranteed to run within the DBUS session and the window manager, X, etc.



                On session login, the script will be called, importing everything into the systemd user daemon.



                Next, for all units depending on these environment variables, simply have them depend on dbus-environment.service:



                [Unit]
                Description=Duplicity Backup Service
                Requires=dbus-environment.service
                After=dbus-environment.service

                [Service]
                Type=oneshot
                ExecStart=/home/naftuli/.local/bin/duply home backup


                At this point, when this service starts, it is guaranteed to have the environment imported. Perhaps I should be using a target rather than a service, but that exercise will have to wait.






                share|improve this answer












                My solution takes into account @meuh's solution above and some digging.



                Step one is to create a dummy user unit called dbus-environment.service:



                [Unit]
                Description=Environment Imported Target

                [Service]
                Type=oneshot
                RemainAfterExit=true
                ExecStart=/bin/true


                Next step is to create a Bash script:



                #!/bin/bash

                systemctl --user import-environment
                systemctl --user start dbus-environment.service


                Next, add this script to your window manager's startup applications which are guaranteed to run within the DBUS session and the window manager, X, etc.



                On session login, the script will be called, importing everything into the systemd user daemon.



                Next, for all units depending on these environment variables, simply have them depend on dbus-environment.service:



                [Unit]
                Description=Duplicity Backup Service
                Requires=dbus-environment.service
                After=dbus-environment.service

                [Service]
                Type=oneshot
                ExecStart=/home/naftuli/.local/bin/duply home backup


                At this point, when this service starts, it is guaranteed to have the environment imported. Perhaps I should be using a target rather than a service, but that exercise will have to wait.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 6 '17 at 2:53









                Naftuli Kay

                12k55156250




                12k55156250






















                    up vote
                    0
                    down vote













                    @Naftuli:
                    Would it not have been better to instead use something like this in all your services unit files?



                    ExecStartPre=usrbinsh -c "systemctl --user import-environment"





                    share|improve this answer























                    • That would not solve it. The current execution context is systemd, which doesn't have the display manager environment variables. Executing a shell will not have it automatically inherit these environment variables. You need something that is guaranteed to inherit these variables, so a normal shell won't have them.
                      – Naftuli Kay
                      Jul 30 at 14:30










                    • Thanks! I am a newbie. Still trying to understand systemd. I am actually also stuck in a similar situation where in I would like to import all environment variable available to the user to the system service daemon.. There is no possibility for me to use a script to import these variables. Have you come across another solution so that all the variables which have been set for the users becomes visible to service daemon? Thanks!
                      – Robin
                      Jul 30 at 14:37












                    • dbus-launch might be able to do something. I was originally crawling the /proc/PID/env of the dbus session to get its address and then call dbus-launch
                      – Naftuli Kay
                      Jul 30 at 14:39















                    up vote
                    0
                    down vote













                    @Naftuli:
                    Would it not have been better to instead use something like this in all your services unit files?



                    ExecStartPre=usrbinsh -c "systemctl --user import-environment"





                    share|improve this answer























                    • That would not solve it. The current execution context is systemd, which doesn't have the display manager environment variables. Executing a shell will not have it automatically inherit these environment variables. You need something that is guaranteed to inherit these variables, so a normal shell won't have them.
                      – Naftuli Kay
                      Jul 30 at 14:30










                    • Thanks! I am a newbie. Still trying to understand systemd. I am actually also stuck in a similar situation where in I would like to import all environment variable available to the user to the system service daemon.. There is no possibility for me to use a script to import these variables. Have you come across another solution so that all the variables which have been set for the users becomes visible to service daemon? Thanks!
                      – Robin
                      Jul 30 at 14:37












                    • dbus-launch might be able to do something. I was originally crawling the /proc/PID/env of the dbus session to get its address and then call dbus-launch
                      – Naftuli Kay
                      Jul 30 at 14:39













                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    @Naftuli:
                    Would it not have been better to instead use something like this in all your services unit files?



                    ExecStartPre=usrbinsh -c "systemctl --user import-environment"





                    share|improve this answer














                    @Naftuli:
                    Would it not have been better to instead use something like this in all your services unit files?



                    ExecStartPre=usrbinsh -c "systemctl --user import-environment"






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jul 30 at 14:59









                    peterh

                    4,09692956




                    4,09692956










                    answered Jul 30 at 14:28









                    Robin

                    1




                    1












                    • That would not solve it. The current execution context is systemd, which doesn't have the display manager environment variables. Executing a shell will not have it automatically inherit these environment variables. You need something that is guaranteed to inherit these variables, so a normal shell won't have them.
                      – Naftuli Kay
                      Jul 30 at 14:30










                    • Thanks! I am a newbie. Still trying to understand systemd. I am actually also stuck in a similar situation where in I would like to import all environment variable available to the user to the system service daemon.. There is no possibility for me to use a script to import these variables. Have you come across another solution so that all the variables which have been set for the users becomes visible to service daemon? Thanks!
                      – Robin
                      Jul 30 at 14:37












                    • dbus-launch might be able to do something. I was originally crawling the /proc/PID/env of the dbus session to get its address and then call dbus-launch
                      – Naftuli Kay
                      Jul 30 at 14:39


















                    • That would not solve it. The current execution context is systemd, which doesn't have the display manager environment variables. Executing a shell will not have it automatically inherit these environment variables. You need something that is guaranteed to inherit these variables, so a normal shell won't have them.
                      – Naftuli Kay
                      Jul 30 at 14:30










                    • Thanks! I am a newbie. Still trying to understand systemd. I am actually also stuck in a similar situation where in I would like to import all environment variable available to the user to the system service daemon.. There is no possibility for me to use a script to import these variables. Have you come across another solution so that all the variables which have been set for the users becomes visible to service daemon? Thanks!
                      – Robin
                      Jul 30 at 14:37












                    • dbus-launch might be able to do something. I was originally crawling the /proc/PID/env of the dbus session to get its address and then call dbus-launch
                      – Naftuli Kay
                      Jul 30 at 14:39
















                    That would not solve it. The current execution context is systemd, which doesn't have the display manager environment variables. Executing a shell will not have it automatically inherit these environment variables. You need something that is guaranteed to inherit these variables, so a normal shell won't have them.
                    – Naftuli Kay
                    Jul 30 at 14:30




                    That would not solve it. The current execution context is systemd, which doesn't have the display manager environment variables. Executing a shell will not have it automatically inherit these environment variables. You need something that is guaranteed to inherit these variables, so a normal shell won't have them.
                    – Naftuli Kay
                    Jul 30 at 14:30












                    Thanks! I am a newbie. Still trying to understand systemd. I am actually also stuck in a similar situation where in I would like to import all environment variable available to the user to the system service daemon.. There is no possibility for me to use a script to import these variables. Have you come across another solution so that all the variables which have been set for the users becomes visible to service daemon? Thanks!
                    – Robin
                    Jul 30 at 14:37






                    Thanks! I am a newbie. Still trying to understand systemd. I am actually also stuck in a similar situation where in I would like to import all environment variable available to the user to the system service daemon.. There is no possibility for me to use a script to import these variables. Have you come across another solution so that all the variables which have been set for the users becomes visible to service daemon? Thanks!
                    – Robin
                    Jul 30 at 14:37














                    dbus-launch might be able to do something. I was originally crawling the /proc/PID/env of the dbus session to get its address and then call dbus-launch
                    – Naftuli Kay
                    Jul 30 at 14:39




                    dbus-launch might be able to do something. I was originally crawling the /proc/PID/env of the dbus session to get its address and then call dbus-launch
                    – Naftuli Kay
                    Jul 30 at 14:39


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f368730%2fstarting-a-dbus-session-application-from-systemd-user-mode%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Accessing regular linux commands in Huawei's Dopra Linux

                    Can't connect RFCOMM socket: Host is down

                    Kernel panic - not syncing: Fatal Exception in Interrupt