首先是第一件事。我正在尝试为运行最新jessie raspbian的覆盆子pi编写自定义udev规则。我试图编写的规则包含一个运行脚本以启动Flask Web应用程序的脚本。但问题是webapp永远不会启动。我可以从终端运行usbinsert,它工作得很好。我可以从终端运行runWebApp.sh并且它可以工作。我现在会接受任何指导或建议。
我尝试过使用不同的USB设备并根据需要更改规则。我尝试过只使用一个动作,内核,并在udev规则中运行。我知道的很多。 udev规则运行,我可以看到它应该运行的脚本运行。
这是规则(/etc/udev/rules.d/99-z.rules):
ACTION=="add", KERNEL=="sda*", SUBSYSTEM=="block", ATTRS{idVendor}=="05e3", ATTRS{idProduct}=="0743", RUN+="/lib/udev/usbinsert"
这是通过运行udevadm monitor --environment:
来捕获监视器KERNEL[7892.634962] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4 (usb)
ACTION=add
BUSNUM=001
DEVNAME=/dev/bus/usb/001/024
DEVNUM=024
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4
DEVTYPE=usb_device
MAJOR=189
MINOR=23
PRODUCT=5e3/743/819
SEQNUM=1492
SUBSYSTEM=usb
TYPE=0/0/0
KERNEL[7892.650572] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0 (usb)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0
DEVTYPE=usb_interface
INTERFACE=8/6/80
MODALIAS=usb:v05E3p0743d0819dc00dsc00dp00ic08isc06ip50in00
PRODUCT=5e3/743/819
SEQNUM=1493
SUBSYSTEM=usb
TYPE=0/0/0
KERNEL[7892.659504] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17 (scsi)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17
DEVTYPE=scsi_host
SEQNUM=1494
SUBSYSTEM=scsi
KERNEL[7892.659883] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/scsi_host/host17 (scsi_host)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/scsi_host/host17
SEQNUM=1495
SUBSYSTEM=scsi_host
UDEV [7892.692301] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4 (usb)
ACTION=add
BUSNUM=001
DEVNAME=/dev/bus/usb/001/024
DEVNUM=024
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=USB_Storage
ID_MODEL_ENC=USB\x20Storage
ID_MODEL_FROM_DATABASE=SDXC and microSDXC CardReader
ID_MODEL_ID=0743
ID_REVISION=0819
ID_SERIAL=Generic_USB_Storage_000000000819
ID_SERIAL_SHORT=000000000819
ID_USB_INTERFACES=:080650:
ID_VENDOR=Generic
ID_VENDOR_ENC=Generic
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
ID_VENDOR_ID=05e3
MAJOR=189
MINOR=23
PRODUCT=5e3/743/819
SEQNUM=1492
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=92636029
UDEV [7892.705663] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0 (usb)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0
DEVTYPE=usb_interface
ID_MODEL_FROM_DATABASE=SDXC and microSDXC CardReader
ID_VENDOR_FROM_DATABASE=Genesys Logic, Inc.
INTERFACE=8/6/80
MODALIAS=usb:v05E3p0743d0819dc00dsc00dp00ic08isc06ip50in00
PRODUCT=5e3/743/819
SEQNUM=1493
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=653207
UDEV [7892.715238] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17 (scsi)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17
DEVTYPE=scsi_host
SEQNUM=1494
SUBSYSTEM=scsi
USEC_INITIALIZED=669795
UDEV [7892.725906] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/scsi_host/host17 (scsi_host)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/scsi_host/host17
SEQNUM=1495
SUBSYSTEM=scsi_host
USEC_INITIALIZED=670426
KERNEL[7893.652232] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0 (scsi)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0
DEVTYPE=scsi_target
SEQNUM=1496
SUBSYSTEM=scsi
KERNEL[7893.652473] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0 (scsi)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0
DEVTYPE=scsi_device
MODALIAS=scsi:t-0x00
SEQNUM=1497
SUBSYSTEM=scsi
KERNEL[7893.652666] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_disk/17:0:0:0 (scsi_disk)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_disk/17:0:0:0
SEQNUM=1498
SUBSYSTEM=scsi_disk
KERNEL[7893.652840] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_device/17:0:0:0 (scsi_device)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_device/17:0:0:0
SEQNUM=1499
SUBSYSTEM=scsi_device
UDEV [7893.657235] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0 (scsi)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0
DEVTYPE=scsi_target
SEQNUM=1496
SUBSYSTEM=scsi
USEC_INITIALIZED=653154
KERNEL[7893.658401] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_generic/sg0 (scsi_generic)
ACTION=add
DEVNAME=/dev/sg0
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_generic/sg0
MAJOR=21
MINOR=0
SEQNUM=1500
SUBSYSTEM=scsi_generic
KERNEL[7893.664483] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/bsg/17:0:0:0 (bsg)
ACTION=add
DEVNAME=/dev/bsg/17:0:0:0
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/bsg/17:0:0:0
MAJOR=252
MINOR=0
SEQNUM=1501
SUBSYSTEM=bsg
UDEV [7893.673356] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0 (scsi)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0
DEVTYPE=scsi_device
MODALIAS=scsi:t-0x00
SEQNUM=1497
SUBSYSTEM=scsi
USEC_INITIALIZED=653491
UDEV [7893.685914] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_disk/17:0:0:0 (scsi_disk)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_disk/17:0:0:0
SEQNUM=1498
SUBSYSTEM=scsi_disk
USEC_INITIALIZED=653657
UDEV [7893.696161] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_device/17:0:0:0 (scsi_device)
ACTION=add
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_device/17:0:0:0
SEQNUM=1499
SUBSYSTEM=scsi_device
USEC_INITIALIZED=93653853
UDEV [7893.705375] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_generic/sg0 (scsi_generic)
ACTION=add
DEVNAME=/dev/sg0
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/scsi_generic/sg0
MAJOR=21
MINOR=0
SEQNUM=1500
SUBSYSTEM=scsi_generic
USEC_INITIALIZED=93667362
UDEV [7893.708119] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/bsg/17:0:0:0 (bsg)
ACTION=add
DEVNAME=/dev/bsg/17:0:0:0
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/bsg/17:0:0:0
MAJOR=252
MINOR=0
SEQNUM=1501
SUBSYSTEM=bsg
USEC_INITIALIZED=93667594
KERNEL[7894.054150] add /devices/virtual/bdi/8:0 (bdi)
ACTION=add
DEVPATH=/devices/virtual/bdi/8:0
SEQNUM=1502
SUBSYSTEM=bdi
UDEV [7894.056350] add /devices/virtual/bdi/8:0 (bdi)
ACTION=add
DEVPATH=/devices/virtual/bdi/8:0
SEQNUM=1502
SUBSYSTEM=bdi
USEC_INITIALIZED=54531
KERNEL[7894.067936] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda (block)
ACTION=add
DEVNAME=/dev/sda
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda
DEVTYPE=disk
MAJOR=8
MINOR=0
SEQNUM=1503
SUBSYSTEM=block
KERNEL[7894.069129] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda/sda1 (block)
ACTION=add
DEVNAME=/dev/sda1
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda/sda1
DEVTYPE=partition
MAJOR=8
MINOR=1
SEQNUM=1504
SUBSYSTEM=block
UDEV [7894.322991] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda (block)
ACTION=add
DEVLINKS=/dev/disk/by-id/usb-Generic_STORAGE_DEVICE_000000000819-0:0 /dev/disk/by-path/platform-20980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0
DEVNAME=/dev/sda
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda
DEVTYPE=disk
ID_BUS=usb
ID_INSTANCE=0:0
ID_MODEL=STORAGE_DEVICE
ID_MODEL_ENC=STORAGE\x20DEVICE\x20\x20
ID_MODEL_ID=0743
ID_PART_TABLE_TYPE=dos
ID_PATH=platform-20980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0
ID_PATH_TAG=platform-20980000_usb-usb-0_1_4_1_0-scsi-0_0_0_0
ID_REVISION=0819
ID_SERIAL=Generic_STORAGE_DEVICE_000000000819-0:0
ID_SERIAL_SHORT=000000000819
ID_TYPE=disk
ID_USB_DRIVER=usb-storage
ID_USB_INTERFACES=:080650:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Generic
ID_VENDOR_ENC=Generic\x20
ID_VENDOR_ID=05e3
MAJOR=8
MINOR=0
SEQNUM=1503
SUBSYSTEM=block
TAGS=:systemd:
UDISKS_PARTITION_TABLE=1
UDISKS_PARTITION_TABLE_COUNT=1
UDISKS_PARTITION_TABLE_SCHEME=mbr
UDISKS_PRESENTATION_NOPOLICY=0
USEC_INITIALIZED=73494
UDEV [7894.728158] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda/sda1 (block)
ACTION=add
DEVLINKS=/dev/disk/by-id/usb-Generic_STORAGE_DEVICE_000000000819-0:0-part1 /dev/disk/by-path/platform-20980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0-part1 /dev/disk/by-uuid/166E-33D9
DEVNAME=/dev/sda1
DEVPATH=/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda/sda1
DEVTYPE=partition
ID_BUS=usb
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=166E-33D9
ID_FS_UUID_ENC=166E-33D9
ID_FS_VERSION=FAT32
ID_INSTANCE=0:0
ID_MODEL=STORAGE_DEVICE
ID_MODEL_ENC=STORAGE\x20DEVICE\x20\x20
ID_MODEL_ID=0743
ID_PART_ENTRY_DISK=8:0
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=8192
ID_PART_ENTRY_SCHEME=dos
ID_PART_ENTRY_SIZE=60866560
ID_PART_ENTRY_TYPE=0xc
ID_PART_TABLE_TYPE=dos
ID_PATH=platform-20980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0
ID_PATH_TAG=platform-20980000_usb-usb-0_1_4_1_0-scsi-0_0_0_0
ID_REVISION=0819
ID_SERIAL=Generic_STORAGE_DEVICE_000000000819-0:0
ID_SERIAL_SHORT=000000000819
ID_TYPE=disk
ID_USB_DRIVER=usb-storage
ID_USB_INTERFACES=:080650:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Generic
ID_VENDOR_ENC=Generic\x20
ID_VENDOR_ID=05e3
MAJOR=8
MINOR=1
SEQNUM=1504
SUBSYSTEM=block
TAGS=:systemd:
UDISKS_PARTITION=1
UDISKS_PARTITION_ALIGNMENT_OFFSET=0
UDISKS_PARTITION_NUMBER=1
UDISKS_PARTITION_OFFSET=4194304
UDISKS_PARTITION_SCHEME=mbr
UDISKS_PARTITION_SIZE=31163678720
UDISKS_PARTITION_SLAVE=/sys/devices/platform/soc/20980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/host17/target17:0:0/17:0:0:0/block/sda
UDISKS_PARTITION_TYPE=0x0c
UDISKS_PRESENTATION_NOPOLICY=0
USEC_INITIALIZED=73822
我知道脚本正在运行,因为我在top:
的输出中看到了它usbinsert 945 root 0.0 0.6 0 0 74
usb-storage 918 root 0.0 0.0 0 0 0
udisksd 835 root 0.0 1.5 0 2 729
udev规则,usbinsert脚本和runWebapp.sh的权限分别如下:
pi@IT:~ $ ls -la /etc/udev/rules.d/99-z.rules
-rw-r--r-- 1 root root 130 Feb 1 07:27 /etc/udev/rules.d/99-z.rules
pi@IT:~ $ ls -la /lib/udev/usbinsert
-rwxrwxrwx 1 pi pi 58 Feb 1 06:20 /lib/udev/usbinsert
pi@IT:~ $ lla /home/pi/Documents/scripts/runWebApp.sh
-rwxrwxrwx 1 root root 55 Feb 1 07:08 /home/pi/Documents/scripts/runWebApp.sh
usbinsert的内容:
#!/bin/sh
/home/pi/Documents/scripts/runWebApp.sh & exit
runWebApp.sh的内容(我试过这四种方法):
1
#!/bin/sh
lxterminal -e python /home/pi/webapp/app.py
2
#!/bin/bash
lxterminal -e python /home/pi/webapp/app.py
3
#!/bin/sh
python /home/pi/webapp/app.py
4
#!/bin/bash
python /home/pi/webapp/app.py
答案 0 :(得分:0)
访问显示器可能会出现问题。尝试在脚本中设置显示
export DISPLAY=:0.0