systemd: start service at boot in user context


thx

Recommended Posts

Hi,

I just solved an issue I had - just wnated to document it in case it's of some use?

I had trouble to automatically start Sync under my user on my Fedora 23 laptop at boot. Although I had enabled btsync as systemd service under my user, it did not start up even after I entered my graphical session. In addition I enabled lingering for my user, i.e., to start a user manager for my user at boot and after logout - so that services under my user will survive me logging out...

> sudo loginctl enable-linger $USER
> systemctl --user enable btsync
> systemctl --user start btsync

Still, btsync did not start at boot.

Remedy was to change the target for the btsync target from multi-user to default in the [Install] section in /usr/lib/systemd/user/btsync.service

> /usr/lib/systemd/user/btsync.service
# WantedBy=multi-user.target #original target
WantedBy=default.target # working target

After disabling and enabling again btsync with systemctl for my user for resetting the link to match the target, i.e.,

$HOME/.config/systemd/user/default.target.wants/btsync.service

btysnc starts finally at boot under my user.

I suspect, that maybe the network may be was an obstacle for multi-user as target, since not necessarily I have a network at start (is multi-user coupled with network-online??)

Maybe somebody has an idea, what possible drawback could be with default as target? From what I see, it can change at some point (current graphical). Maybe graphical is not the optimal target.

Anyway, I had thought that graphical downstream of multi-user, so I wonder why it is working O.o

Cheers,
  Thomas

Link to comment
Share on other sites

I just learnd, that systemd user instances indeed have no multi-user as target!
See

man 7 systemd.special #SPECIAL USER UNITS

so, for user instances default would be the correct target I suppose - combined with lingering

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.