我如何 运行 在 Google Coral 上启动 python 脚本?

How do I run a python script on boot on Google Coral?

我在 python 中编写了一个简单的测试代码,以每隔几秒打开和关闭两个 I/O 引脚。我希望能够在电路板启动时 运行 这段代码,这样我就不需要在任何我想 运行 简单测试的地方带上键盘、鼠标和显示器。我如何在 Mendel OS 上对 google 珊瑚执行此操作?

我有同样的问题。 这可能对您有用。 https://askubuntu.com/questions/919054/how-do-i-run-a-single-command-at-startup-using-systemd 我能够向 systemd 添加新服务,但脚本没有正确 运行,但也许这不是你的问题。

我一直在使用 crontab,您可能想在 python 文件的开头添加一个 time.sleep

编辑 crontab crontab -e

select 纳米编辑器

添加

@reboot sudo python3 <path_to_your_script>

在 Mendel OS 上,您的 systemd 服务应如下所示:

myservice.service:

[Unit]
Description=Example systemd service.
After=weston.target

[Service]
Environment=DISPLAY=:0
PAMName=login
Type=simple
User=mendel
WorkingDirectory=/home/mendel
ExecStart=/bin/bash /usr/bin/test_service.sh
Restart=always

[Install]
WantedBy=multi-user.target

关于如何创建服务,如何部署,可以参考this文章。

将 'ExecStart' 行更改为您要执行的 python 文件。

我从the Nam Vu's note in Gist. This is like the details of Nanoj's answer above复制了指令。


这是在 Coral 开发板上启动时启动 systemd 对象检测服务的示例。

  1. 创建一个名为“detects.service”的文件,内容类似:
[Unit]
Description=systemd object detection service
After=weston.target

[Service]
PAMName=login
Type=simple
User=mendel
WorkingDirectory=/home/mendel
Environment=DISPLAY=:0
ExecStart=/bin/bash /usr/bin/detect_service.sh
Restart=always

[Install]
WantedBy=multi-user.target

  1. 复制文件到“/lib/systemd/system/detects.service”
    $ sudo cp -i detects.service /lib/systemd/system

  2. 创建一个名为“detect_service.sh”的文件,其内容类似于以下内容:
    edgetpu_detect --model fullpath/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --label fullpath/coco_labels.txt

    python detect.py --model fullpath/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --label fullpath/coco_labels.txt

  3. 使其可执行并将其复制到“/usr/bin”:
    $ sudo chmod u+x detect_service.sh
    $ sudo cp -i detect_service.sh /usr/bin

  4. 使用systemctl命令启用服务:
    $ sudo systemctl enable detects.service

当您的 python 代码调用 the Google "gstreamer code" example. The gstreamer code not able to be executed with sudo command, so you may not able to use with "sudo crontab -e" method for example 时,这会很有用。