使用自定义 Systemd 服务在启动时执行 Coral Board 演示模型
Executing Coral Board Demonstration Model on Boot with Custom Systemd Service
我正在尝试将我的珊瑚板配置为使用自定义 systemd 服务启动到 Coco 对象检测模型。我已经创建了可执行文件、单元文件,然后启用了该服务。目的是让摄像头显示在监视器上,但是当我打开电路板时,监视器只显示蓝色背景(我假设电路板的 "home screen")。
可执行文件:
edgetpu_detect \
--model mobilenet_ssd...
--labels coco...
单元文件:
[Unit]
Description=systemd service.
After=weston.target
[Service]
PAMName=login
Type=simple
User=mendel
WorkingDirectory=/home/mendel
ExecStart=/bin/bash /usr/bin/test_service.sh
Restart=always
[Install]
WantedBy=multi-user.targer
启用后和开机后的服务状态:
mendel@jumbo-tang:/etc/system$ sudo systemctl status myservice.service
myservice.service - systemd service.
Loaded: loaded (/etc/systemd/system/system/myservice.service; enabled; vendor preset
Active: active (running) since Mon 2020-01-06 03:32:03 UTC; 1s ago
Main PID: 4847 (bash)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/myservice.service
4847 /bin/bash /usr/bin/test_service.sh
Jan 06 03:32:03 jumbo-tang systemd[1]: myservice.service: Service hold-off time
Jan 06 03:32:03 jumbo-tang systemd[1]: Stopped Example systemd service..
Jan 06 03:32:03 jumbo-tang systemd[1]: Started Example systemd service..
Jan 06 03:32:03 jumbo-tang systemd[4847]: pam_unix(login:session): session opene
可执行文件保存到 /usr/bin
,并通过 sudo chmod +x /usr/bin/test_service.sh
变为可执行文件
单元文件已保存到 /etc/systemd/system
,并获得了 sudo chmod 644 /etc/systemd/system/myservice.service
的权限
我很想知道我的可执行文件是否不能简单地包含我通常用来启动模型的代码,就像我做的那样,或者我的单元文件是否配置正确,或者还有什么问题我没想到。
感谢任何帮助!
我相信我已经通过 coral-support 回答了你,我们讨论过你很可能只是遗漏了几件事:
1) 启动 systemd 服务时,尤其是在开机时,有时不会加载所有环境变量,在这种情况下,您可能需要添加以下行:
Environment=DISPLAY=:0
在 ExecStart 之前。但是,我不怀疑这是问题所在,因为进程确实在等待 weston.target,它应该已经在等待环境变量。
2) 这个比上一个复杂很多但是你拼错了
"target" in "WantedBy=multi-user.targer" (joking, of course)
我在这里再次展示这些步骤作为示例以供将来参考。
1) 创建一个包含以下内容的文件调用 detects.service:
[Unit]
Description=systemd auto face 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
2) mv 文件 /lib/systemd/system/detects.service
$ sudo mv detects.service /lib/systemd/system/detects.service
3) 使用以下内容创建文件调用 detect_service.sh
edgetpu_detect --model fullpath/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --label fullpath/coco_labels.txt
4) 使其可执行并将其 mv 到 /usr/bin
$ sudo chmod u+x detect_service.sh
$ sudo mv detect_service.sh /usr/bin
5) 使用systemctl启用服务
$ sudo systemctl enable detects.service
我正在尝试将我的珊瑚板配置为使用自定义 systemd 服务启动到 Coco 对象检测模型。我已经创建了可执行文件、单元文件,然后启用了该服务。目的是让摄像头显示在监视器上,但是当我打开电路板时,监视器只显示蓝色背景(我假设电路板的 "home screen")。
可执行文件:
edgetpu_detect \
--model mobilenet_ssd...
--labels coco...
单元文件:
[Unit]
Description=systemd service.
After=weston.target
[Service]
PAMName=login
Type=simple
User=mendel
WorkingDirectory=/home/mendel
ExecStart=/bin/bash /usr/bin/test_service.sh
Restart=always
[Install]
WantedBy=multi-user.targer
启用后和开机后的服务状态:
mendel@jumbo-tang:/etc/system$ sudo systemctl status myservice.service
myservice.service - systemd service.
Loaded: loaded (/etc/systemd/system/system/myservice.service; enabled; vendor preset
Active: active (running) since Mon 2020-01-06 03:32:03 UTC; 1s ago
Main PID: 4847 (bash)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/myservice.service
4847 /bin/bash /usr/bin/test_service.sh
Jan 06 03:32:03 jumbo-tang systemd[1]: myservice.service: Service hold-off time
Jan 06 03:32:03 jumbo-tang systemd[1]: Stopped Example systemd service..
Jan 06 03:32:03 jumbo-tang systemd[1]: Started Example systemd service..
Jan 06 03:32:03 jumbo-tang systemd[4847]: pam_unix(login:session): session opene
可执行文件保存到 /usr/bin
,并通过 sudo chmod +x /usr/bin/test_service.sh
单元文件已保存到 /etc/systemd/system
,并获得了 sudo chmod 644 /etc/systemd/system/myservice.service
我很想知道我的可执行文件是否不能简单地包含我通常用来启动模型的代码,就像我做的那样,或者我的单元文件是否配置正确,或者还有什么问题我没想到。
感谢任何帮助!
我相信我已经通过 coral-support 回答了你,我们讨论过你很可能只是遗漏了几件事:
1) 启动 systemd 服务时,尤其是在开机时,有时不会加载所有环境变量,在这种情况下,您可能需要添加以下行:
Environment=DISPLAY=:0
在 ExecStart 之前。但是,我不怀疑这是问题所在,因为进程确实在等待 weston.target,它应该已经在等待环境变量。
2) 这个比上一个复杂很多但是你拼错了
"target" in "WantedBy=multi-user.targer" (joking, of course)
我在这里再次展示这些步骤作为示例以供将来参考。
1) 创建一个包含以下内容的文件调用 detects.service:
[Unit]
Description=systemd auto face 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
2) mv 文件 /lib/systemd/system/detects.service
$ sudo mv detects.service /lib/systemd/system/detects.service
3) 使用以下内容创建文件调用 detect_service.sh
edgetpu_detect --model fullpath/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --label fullpath/coco_labels.txt
4) 使其可执行并将其 mv 到 /usr/bin
$ sudo chmod u+x detect_service.sh
$ sudo mv detect_service.sh /usr/bin
5) 使用systemctl启用服务
$ sudo systemctl enable detects.service