You are not logged in.
Hello,
I'm trying to set up my env and have found systemd user services to be pretty neat when it comes to organizing the dependencies and so on. However, I would like to have a service restart based on the udev rule ideally. If not it could also be that I trigger the regular systemd service which would then execute mine or some kind of dependency chain like that. Is something like that doable?
Offline
From https://www.man7.org/linux/man-pages/man7/udev.7.html
udev(7) — Linux manual page
The udev rules are read from the files located in the system rules directories /usr/lib/udev/rules.d and /usr/local/lib/udev/rules.d,
the volatile runtime directory /run/udev/rules.d and the local administration directory /etc/udev/rules.d.
...
Every line in the rules file contains at least one key-value pair.
...
A matching rule may rename a network interface, add symlinks pointing to the device node, or run a specified program as part of the event handling.
...
Keys
PROGRAM
Execute a program to determine whether there is a match; the key is true if the program returns successfully. The device
properties are made available to the executed program in the environment. The program's standard output is available in the RESULT key.
This can only be used for very short-running foreground tasks. For details, see RUN. Note that multiple PROGRAM keys may be specified
RUN{type}
Specify a program to be executed after processing of all the rules for the event. With "+=", this invocation is added to the
list, and with "=" or ":=", it replaces any previous contents of the list. Please note that both "program" and "builtin" types
described below use a single list, so clearing the list with ":=" and "=" affects both types.
type may be:
"program"
...
This can only be used for very short-running foreground tasks. Running an event process for a long period of time may block all
further events for this or a dependent device.
*****
Note that running programs that access the network or mount/unmount filesystems is not allowed inside of udev rules,
due to the default sandbox that is enforced on systemd-udevd.service.
*****
Starting daemons or other long-running processes is not allowed; the forked processes, detached or not, will be unconditionally
killed after the event handling has finished. In order to activate long-running processes from udev rules, provide a
service unit and pull it in from a udev device using the SYSTEMD_WANTS device property. See systemd.device(5) for details.
*****I think udev may not be the best place for this, you could follow the manpage references or the Arch Linux wiki infos.
https://wiki.archlinux.org/index.php/Systemd/User
https://wiki.archlinux.org/index.php/Autostarting
There's more links to follow around here:
https://wiki.archlinux.org/index.php/Ud … _processes
Last edited by chaseleif (2020-11-27 23:26:32)
Offline
Maybe there is some context missing. What I'm trying to do is basically react to udev event, but I would like to react with restarting systemd user service. I'm using one of those to set up my monitor setup and polybar and would like to keep them as user services and just restart them after this udev event
Offline