disk plug cache after first time

58 views Asked by At

I need to develop one feature that likes disk hotplug. I write some udev rules to monitor disk to execute one python script when udev triggered.

Question:

when I pull the disk first time, lsblk, lsscsi, udev, megacli all can monitor, /dev/sda change to be /dev/sdg, udev also can be triggered and py script be executed successfully, first time disk plug is also normal.

But the second time or more, I pull the previous /dev/sdg, lsblk, lsscsi, udev all can not sense, the std output list also contain dev/sdg, and udev doesn't find remove event, the script is also not executed, megacli can find the lack of disk

Now I need udev monitor disk plug real time to execute script, is someone has experience in this question ?

my udev rules:

KERNEL=="sd[a-z]", ACTION=="add", SUBSYSTEM=="block", RUN+="/usr/bin/python /root/disk_plug.py %k add"
KERNEL=="sd[a-z]", ACTION=="remove", SUBSYSTEM=="block", RUN+="/usr/bin/python /root/disk_plug.py %k remove"

This is my test script: /root/disk_plug.py

import sys
import time
disk = sys.argv[1]
event = sys.argv[2]
with open('/root/disk.txt', 'a') as f:
    msg = event + '-' + disk + '-' + str(time.time())
    f.write(msg + "\n")
1

There are 1 answers

0
QuantumEnergy On BEST ANSWER

Try to umount before pulling out