UDev Rule Raspberry PI不会启动Web应用

2024-05-19 18:18:29 发布

您现在位置:Python中文网/ 问答频道 /正文

所以首先要做的是。我正试图为运行最新jessie raspbian的raspberry pi编写一个自定义udev规则。我正在尝试编写的规则包含一个脚本来运行一个脚本来启动Flask web应用程序。但问题是,webapp永远不会启动。我可以在终端运行usbinsert,它工作得很好。我能跑运行webapp.sh从终端开始工作。在这一点上,我会接受任何指导或建议。在

我尝试过使用不同的usb设备并改变规则以适应需要。我尝试过在udev规则中只使用一个action、kernel和run。我知道很多。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:

^{pr2}$

我知道脚本正在运行,因为我在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脚本和运行webapp.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

内容运行webapp.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

Tags: py脚本apphomebin规则libsh