[systemd-devel] Translating --machine parameter to a service file

Tomáš Hnyk tomashnyk at gmail.com
Tue Jan 25 13:04:48 UTC 2022


Hello,
I want to run a script invoked by udev to run a pactl script. I am now 
using a udev rule 
SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/my_script"

which calls (drew is my username):
systemctl --machine=drew at .host --user --now my.service


which has:
[Service]
Type=oneshot
ExecStart=/usr/local/bin/my_script.py

and in the my_script.py, I do what I need. I cannot call my_script.py 
directly
 from the udev rule because, if I understood it correctly, scripts 
triggered
by udev run in a limited environment and pactl runs as user.

Needless to say, this feels rather hackish. Ideally I would use something 
like 
TAG+="systemd",  ENV{SYSTEMD_WANTS}="my.service"

I can specify "User=" in the service file but I could not figure out
to translate the --machine=drew at .host parameter to it.


Is there a way to do this or am I just missing what --machine is for?
Kind regards,
Tomas 


More information about the systemd-devel mailing list