You are not logged in.

#1 2016-07-17 05:37:54

nbd
Member
Registered: 2014-08-04
Posts: 389

[SOLVED] Can we have instantiated 'systemd --user' services?

I successfuly set up email notifications for root services, following this wiki. This is done by creating an instantiating service (a service with a variable part in the name) which sends an email, and specifying this service in other services' OnFailure section. The service looks like this:

/etc/systemd/system/status-email-user@.service

[Unit]
Description=status email for %I to user

[Service]
Type=oneshot
ExecStart=/usr/local/bin/systemd-email address %i
User=nobody
Group=systemd-journal

The variable part in the name is intended for specifying the calling service. This is done by specifying the OnFailure section like this:

OnFailure=status-email-user@%n.service

Doing the same for --user services fails. The 'enable' command returns an error :

[al ~ ]$ systemctl --user enable /home/al/.config/systemd/user/status-email-al@.service
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.

The exact service file is this:

[Unit]
Description=status email for %I to Al

[Service]
Type=oneshot
ExecStart=/mnt/lib/shbin/service-status-mail.sh al %i

[Install]
WantedBy=default.target

Why this error happens? Can instantiating services be installed as --user services?



Thanks.
Albert.

Last edited by nbd (2016-07-17 13:05:34)


bing different

Offline

#2 2016-07-17 05:41:26

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Can we have instantiated 'systemd --user' services?

If it is a user service, why would you want to make a variable of that user?

Not a Sysadmin issue, moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2016-07-17 06:01:42

nbd
Member
Registered: 2014-08-04
Posts: 389

Re: [SOLVED] Can we have instantiated 'systemd --user' services?

The variable is not of the user name, but of service name:

OnFailure=status-email-user@%n.service

%n here designates the name of service which calls the emailing service in case of failure.


bing different

Offline

#4 2016-07-17 09:17:36

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: [SOLVED] Can we have instantiated 'systemd --user' services?

Are the services with the 'OnFailure=' lines, system services or user services?
If they are system services the search path is not the same as for user services.
To call a user service from the 'OnFailure=' lines, they need to be in user services too.

And template services cannot be enabled directly; you are in the 4th case:

4) In case of template units, the unit is meant to be enabled with some instance name specified.

But you don't need to enable such service. So the [Install] part is useless here.

Offline

#5 2016-07-17 13:04:14

nbd
Member
Registered: 2014-08-04
Posts: 389

Re: [SOLVED] Can we have instantiated 'systemd --user' services?

Thanks, I checked again and the problem was in the mail script which called "systemd status service". After changing to "systemd --user status service", it works.


bing different

Offline

Board footer

Powered by FluxBB