You are not logged in.
I've been searching for an elegant way of automating a very tedious process.
I've managed to start a systemd service when I plug in a USB external drive by editing the service and adding some udev rules (more below) but I've been struggling with other parts of the automation.
This is the workflow I want to achieve:
Plug in the USB Disk (single partition)
sdX1 gets automatically mounted to /mnt/data with some mounting options
Some systemd services are started (which interact with the files in the mountpoint.
I manually issue a command to unmount the drive.
Services get automatically terminated.
I've been experimenting with Transmission, so I have the following service:
[Unit]
Description=Transmission BitTorrent Daemon
After=network.target
After=mnt-data.mount
[Service]
User=transmission
Type=notify
ExecStart=/usr/bin/transmission-daemon -f --log-error
ExecReload=/bin/kill -s HUP $MAINPID
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
WantedBy=mnt-data.mountAnd this is my udev rules file:
SUBSYSTEMS=="usb", ATTRS{idProduct}=="1153", ACTION=="add", ENV{SYSTEMD_WANTS}=="transmission.service"I managed to get the service started when the drive gets mounted, but it's the automount part, and killing the services after the unmount that's eluding me.
I appreciate your help.
Offline