You are not logged in.

#1 2016-02-08 14:07:38

Registered: 2016-01-12
Posts: 4

systemd user services not reading local user.conf

I'm trying to run per user backup jobs with systemd but it appears not to be reading the local user.conf file.  Settings in /etc/systemd/user.conf and /etc/systemd/user.conf.d/user.conf are read (but the /etc/systemd/user/ directory installed by the package is ignored).  I'm currently using an EnvironmentFile (not shown) as in the service here, which works fine.


You can use DefaultEnvironment in user.conf, and place that either in
/etc/systemd/user.conf, or in ~/.config/systemd/user.conf

$ cat ~/.config/systemd/user.conf
DefaultEnvironment=ENCRYPTKEY=user.conf LOGS=/backup/logs

$ cat ~/.config/systemd/user/duplicity-home.service 
Description=Backup Home Directory with Duplicity


# Use either %h or ${HOME} but not in file names because of the /
ExecStart=/usr/bin/duplicity --encrypt-key $ENCRYPTKEY \
        --name %H_%u_${JOB1} \
        --log-file ${LOGS}/backup_%H_%u_${JOB1}.log \
        --exclude %h/.cache \
        %h/ file:///backup/%H/%u/${JOB1}


$ cat ~/.config/systemd/user/duplicity-home.timer
Description=Backup with Duplicity



Also, if a variable in DefaultEnvironment is removed, then the last value used is kept, even after systemctl --user daemon-reload.

This is systemd 228.  I tried it on OpenSUSE with systemd 210 & it was no better, indeed worse as it didn't take any notice of /etc/systemd/user.conf.d/user.conf

In case it helps anyone else, I had a problem where the timers weren't being enabled after a reboot.  This was because of target.wants directories for wrong targets, as here for, which is not a valid user target.  That directory dates from an earlier version of the timer and service files and is still there because I changed the target in the unit file without first disabling the unit.  Maybe systemctl should check the current target against the new target before changing a unit.

$ ls -rt *                                 
-rw------- 1 test users   66 Feb  7 07:03 duplicity.env                         
-rw-r--r-- 1 test users  420 Feb  7 21:00 duplicity-home.service                
-rw-r--r-- 1 test users  159 Feb  8 04:00 duplicity-home.timer                  
total 0
lrwxrwxrwx 1 test users 52 Feb  7 07:47 duplicity-home.timer -> ~/.config/systemd/user/duplicity-home.timer
lrwxrwxrwx 1 test users 54 Feb  7 07:50 duplicity-home.service -> ~/.config/systemd/user/duplicity-home.service

To fix this, check that the targets are correct in the unit files, disable each timer and service linked to the wrong target, delete the target.wants directory if necessary then enable them again.


#2 2016-02-10 16:55:00

Registered: 2016-01-12
Posts: 4

Re: systemd user services not reading local user.conf

Is anyone successfully using ~/.config/systemd/user.conf ?  Apart from in man systemd.unit, I've only found the ref above and this in the ArchWIki suggesting its use.

On the other hand,
At many places it is stated that you can put the environment variables into the DefaultEnvironment of the ~/.config/systemd/user.conf file. This didn’t work for me and I don’t know why.

For what it's worth, /usr/share/pkgconfig/systemd.pc has only

Last edited by nobby (2016-02-10 17:05:23)


#3 2016-11-08 18:58:32

Registered: 2016-11-08
Posts: 1

Re: systemd user services not reading local user.conf

I have the same problem. I would like to set some environment variables for my user profile without worrying how i log in to the system (ssh, console, graphical):

% cat ~/.config/systemd/user.conf 

Systemd seems not to pick up this configuration: the command systemctl --user show-environment does not show the configured variable.

Also we seem not to be the only ones having this problem: … rminals-or

I also found references for the user.conf file in the user profile from the systemd developers:

Anyone using "~/.config/systemd/user.conf" for setting environment variables?


#4 2016-11-09 09:58:07

From: France
Registered: 2007-02-12
Posts: 1,283

Re: systemd user services not reading local user.conf

From 'man systemd':

Global configuration is done in the directory reported by
pkg-config systemd --variable=systemduserconfdir

$ pkg-config systemd --variable=systemduserconfdir

So copy the user.conf in this directory.


Board footer

Powered by FluxBB