[systemd-devel] Installing user unit files.

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Mon Dec 8 10:40:14 PST 2014


On Mon, Dec 08, 2014 at 07:31:07PM +0100, Rüdiger Sonderfeld wrote:
> Hello,
> 
> I'm currently in the process of adding a service file to GNU Emacs: 
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16507#26
> 
> The major point of discussion is how and where to install that file.  Systemd 
> has guidelines for system service files in daemon(7).  One could follow them 
> for user service files by simply replacing `systemdsystemunitdir' with 
> `systemduserunitdir'.  Which is basically what the patch does so far.  However 
> this would cause problems when (a) installing several versions of GNU Emacs in 
> parallel and (b) user installations.
> 
> (a) could be solved by applying `program_transform_name' (from autoconf's 
> AC_ARG_PROGRAM) to the service file name.  E.g., turning emacs.service into 
> emacs24.service.
Sound like the best option, if you really want to support multiple versions.
Otherwise you might "cop out" and say that whatever version gets the 'emacs'
name, wins, and will be used by the service file. Normally you wouldn't want
multiple versions except for development, so covering multiple versions might
be overkill for the final user.
 
> I'm not sure how to solve (b).  For a system service it might not make sense 
> to install it somewhere outside of /usr (or /usr/local) and simply following 
> `systemdsystemunitdir' makes sense.  But for a user application like GNU Emacs 
> it should be possible to install it to any $prefix (e.g., ~/usr) without 
> requiring root access.  Right now, I'm thinking of either setting the default 
> to not install the service file or installing it to `datadir'.
This destination must be know to systemd. So anything generic like ~/usr
is unlikely to work, unless systemd is modified to check that directory too.
When installed as a user, it should go to $HOME/.local/share/systemd/user/.
Please see [1] for an up-to-date list of directories where user units are
loaded from. The ones in $XDG_CONFIG_HOME are for user overrides, so
.local/share/ seems the most appropriate.

[1] http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Unit%20Load%20Path

> What is the best practice for user unit files?  How are other projects 
> handling this?
This is all still new, so the best practices are still being developed ;)

Zbyszek


More information about the systemd-devel mailing list