[systemd-devel] Set environment for user at .service

Lennart Poettering lennart at poettering.net
Sun Mar 2 13:43:46 PST 2014

On Sun, 02.03.14 11:22, subi.the.dream.walker at gmail.com (subi.the.dream.walker at gmail.com) wrote:

> Hi,
> Before systemd 209, I put 'Environment=ENV=%h/.somedir' in
> /etc/user at .service.d/env.conf to set some variables. Now since %h is not
> available for system units anymore, I take the workaround by adding a
> user unit set-my-env.service:
> -------------
> [Unit]
> Description=Set systemd environment
> Before=default.target
> [Service]
> Type=oneshot
> RemainAfterExit=yes
> ExecStart=-/usr/bin/systemctl --user set-environment ENV=%h/.somedir
> [Install]
> WantedBy=basic.target
> ------------
> The problem is that set-my-env.service may not affect the early units
> pulled in by default.target. I wonder how we can execute
> set-my-env.service as soon as user at .service is started. Thanks.

You can use DefaultEnvironment in user.conf, and place that either in
/etc/systemd/user.conf, or in ~/.config/systemd/user.conf. Do you need
anything else?

Alternatively you can use pam_env for this?


Lennart Poettering, Red Hat

More information about the systemd-devel mailing list