微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

DietPi - 手动运行脚本有效 - 但从 postboot.d 开始会引发 I/O 错误

如何解决DietPi - 手动运行脚本有效 - 但从 postboot.d 开始会引发 I/O 错误

我正在尝试在使用 DietPi 启动 RaspBerry自动运行脚本。 我的脚本启动一个 python3 程序,然后在最后启动一个外部程序 MP4Box,它将 2 个视频文件合并到我的 lighttp 网络服务器文件夹中的一个 mp4。

当我手动启动脚本时,一切正常。但是当脚本在启动时自动启动,当涉及到外部程序 MP4Box 时,我得到一个错误

Cannot open destination file /var/www/Videos/20201222_151210.mp4: I/O Error

启动我的 python 的脚本是“startcam”——它位于文件夹 /var/lib/dietpi/postboot.d

#!/bin/sh -e
# Autostart RaspiCam
cd /home/dietpi
rm -f trigger/*
python3 -u record_v0.1.py > record.log 2>&1 &
python3 -u motioninterrupt.py > motion.log 2>&1 &

postboot.d 中的 readme.txt 说:

# /var/lib/dietpi/postboot.d is implemented by DietPi and allows to run scripts at the end of the boot process:
# - /etc/systemd/system/dietpi-postboot.service => /boot/dietpi/postboot => /var/lib/dietpi/postboot.d/*
# There are nearly no restrictions about file names and permissions:
# - All files (besides this "readme.txt" and dot files ".filename") are executed as root user.
# - Execute permissions are automatically added.
# NB: This delays the login prompt by the time the script takes,hence it must not be used for long-term processes,but only for oneshot tasks.

所以它也应该以 root 权限启动我的脚本。这就是引发错误的(部分)脚本“record_v0.1.py”:

import os
os.system('MP4Box -fps 15 -cat /home/dietpi/b-file001.h264 -cat /home/dietpi/a-file001.h264 -new /var/www/Videos/file001.mp4 -tmp ~ -quiet')

当我手动启动 python 程序时(以 root 身份登录):

/var/lib/dietpi/postboot.d/startcam

一切正常,我收到消息而不是错误

Appending file /home/dietpi/Videos/b-20201222_153124.h264
No suitable destination track found - creating new one (type vide)
Appending file /home/dietpi/Videos/a-20201222_153124.h264
Saving /var/www/Videos/20201222_153124.mp4: 0.500 secs Interleaving

感谢每一个提示

解决方法

与描述相反,postboot.d 中的脚本不会以 root 身份执行。所以我把我的脚本改成了:

#!/bin/sh -e
# Autostart RaspiCam
cd /home/dietpi
rm -f trigger/*
sudo python3 -u record_v0.1.py > record.log 2>&1 &
sudo python3 -u motioninterrupt.py > motion.log 2>&1 &

现在他们以 root 身份运行,一切正常。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。