6

I asked a question yesterday and one of the comments answered was that it was shared that it is a 'user service' . Now how to distinguish between a 'user service' and a system service ?

7

According to this documentation, one can distinguish the unit file by its path.

For instance; if the unit file is in the

/etc/systemd/system
/usr/lib/systemd/system
/run/systemd/system

directories, this unit belongs to system.

If it is in the

~/.config/systemd/user/*
/etc/systemd/user/*
$XDG_RUNTIME_DIR/systemd/user/*
/run/systemd/user/*
~/.local/share/systemd/user/*
/usr/lib/systemd/user/*

directories, it belongs to user.

1
  • That manual page was missing several directories at the time that that answer was written, and is still missing some of them even today. One of those still-missing directories is stated in the other answer here. jdebp.uk./FGA/…
    – JdeBP
    Mar 19 '20 at 7:38
4

According to the systemd(1) man page for system unit directories:

The systemd system manager reads unit configuration from various directories. Packages that want to install unit files shall place them in the directory returned by:

pkg-config systemd --variable=systemdsystemunitdir

Other directories checked are:

/usr/local/lib/systemd/system
/usr/lib/systemd/system

User configuration always takes precedence.

pkg-config systemd --variable=systemdsystemconfdir

returns the path of the system configuration directory. Packages should alter the content of these directories only with the enable and disable commands of the systemctl(1) tool. Full list of directories is provided in systemd.unit(5).

Then for user unit directories:

Similar rules apply for the user unit directories. However, here the XDG Base Directory specification[6] is followed to find units. Applications should place their unit files in the directory returned by:

pkg-config systemd --variable=systemduserunitdir

Global configuration is done in the directory reported by:

pkg-config systemd --variable=systemduserconfdir

The enable and disable commands of the systemctl(1) tool can handle both global (i.e. for all users) and private (for one user) enabling/disabling of units. Full list of directories is provided in systemd.unit(5).

Note that these are systemd's rules instructing packagers of the proper locations to place different files and it's up to the packager to properly follow these rules.

3
  • Would you please include an example package/s rather than just sharing the syntax. I found the systemd syntax utterly confusing and hence your answer while well-meaning doesn't add much.
    – shirish
    Jan 12 '17 at 23:14
  • Sorry this wasn't more helpful to you, I didn't realize the systemd syntax was the point of confusion here. I'll try to think of an example that would allow me to walk through the syntax, but I'm not sure how I'll approach that right off. Is it the format of the unit files, the directory structure, the command-line syntax or all of the above that are unclear. Could you give an example or two and describe the points of confusion? I hope I'm following you correctly and not completely off base here.
    – airhuff
    Jan 12 '17 at 23:27
  • I am trying to get a pattern understanding. If for e.g. there are two three most common packages , say in GNOME world where systemd comes from which are 'user services' and which are 'systemd service' it would probably simplify things a bit more. As they say, real life examples are better than hypothetical ones.
    – shirish
    Jan 12 '17 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.