systemd - 使用自定义 Systemd 服务在启动时执行珊瑚板演示模型
问题描述
我正在尝试将我的珊瑚板配置为使用自定义 systemd 服务启动到 Coco 对象检测模型。我已经创建了可执行文件、单元文件,然后启用了该服务。目的是让摄像机源显示到监视器,但是当我打开电路板电源时,监视器只显示蓝色背景(我假设电路板的“主屏幕”)。
可执行文件:
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
我很想知道我的可执行文件是否不能像我所做的那样简单地包含我通常用来启动模型的代码,或者我的单元文件是否配置正确,或者还有什么可能是错误的的。
任何帮助表示赞赏!
解决方案
我相信我已经通过珊瑚支持回答了你,我们讨论过你很可能只是错过了几件事:
1)当启动一个systemd服务时,特别是在启动时,有时不是所有的环境变量都被加载,在这种情况下,您可能需要添加以下行:
Environment=DISPLAY=:0
在执行开始之前。但是,我不怀疑这是问题所在,因为该进程确实在等待 weston.target,它应该已经在等待环境变量。
2) 这个比上一个复杂很多,但是你拼错了
"target" in "WantedBy=multi-user.targer" (joking, of course)
我在这里再次展示这些步骤作为将来参考的示例。
1)创建一个文件调用detect.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
推荐阅读
- python - 为什么这个 Python 代码不匹配欧式看涨期权的公式?
- class - 获取接口本身的名称而不是扩展类的名称
- maven - 检查器框架无法解析符号
${org.checkerframework:jdk8:jar} 问题 - vim - .vimrc 自动命令在打开新文件时添加文本
- ios - 移动设备管理 iOS
- asp.net - 在 ASP.NET GridView 中搜索标签值
- java - 带有斑马 jar 的应用程序无法在带有 INSTALL_FAILED_NO_MATCHING_ABIS 的非斑马设备上构建
- ios - 当 Appdelegate 中未设置 rootcontroller 时,视图隐藏在状态栏后面
- sql - 使用 OPNQRYF 按字段的子字符串排序
- c - 将 fftw3 与 fftw 复杂类型一起使用