I am migrating an existing udev rule that bound to the change action of a block device and runs a given script.
SUBSYSTEM=="block", ENV{DEVNAME}=="/dev/sr0", ACTION=="change", RUN+="/usr/local/bin/script"
In this configuration udev passed the environment variables associated to the hardware device such as ID_CDROM_MEDIA-0
and ID_FS_LABEL
. I've since updated the udev rule to use systemd to start a service on the hardware change.
SUBSYSTEM=="block", ENV{DEVNAME}=="/dev/sr0", ACTION=="change", TAG+="systemd", ENV{SYSTEMD_WANTS}=="drive-change.service"
The systemd service file:
[Unit]
Description=changes to dvd drive
[Service]
Type=oneshot
ExecStart=/usr/local/bin/script
[Install]
WantedBy=multi-user.target
At this point the service is run on change events but the environment variables passed by the RUN command in udev are not passed to the execution of the service.
Is it possible to pass the environment from udev to the execution environment of systemd or do I need to explicitly pass parameters?