我有一个带有 motion v 4.0 的 Web 服务器,但 motion 无法在启动时启动,每次我都必须告诉它启动,然后sudo motion -b
一切都很顺利,直到我需要重新启动。我尝试编辑配置文件/etc/motion/motion.conf
, /etc/defualt/motion
包含变量:start_motion_daemon=yes
哪个变量应该在启动时启动进程?
但是当我去检查时,该进程从未运行。我尝试设置 rc.local,但 ubuntu 似乎不再这样做了?
我尝试使用 systemctl 启用该服务:
sudo systemctl enable motion
motion.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable motion
但该服务从未启用,甚至从未打开。所以我查看了日志:
[1:ml1] [NTC] [VID] [Jun 16 07:26:10] v4l2_get_capability: - VIDEO_CAPTURE
[1:ml1] [NTC] [VID] [Jun 16 07:26:10] v4l2_get_capability: - STREAMING
[1:ml1] [NTC] [VID] [Jun 16 07:26:10] v4l2_select_input: name = "Camera 1", type 0x00000002, status 00000000
[0:web_control] [NTC] [STR] [Jun 16 07:26:10] http_bindsock: error binding on 127.0.0.1 port 8080
[1:ml1] [NTC] [VID] [Jun 16 07:26:10] v4l2_select_input: - CAMERA
[0:web_control] [NTC] [STR] [Jun 16 07:26:10] motion_web_control: motion-httpd thread exit
[1:ml1] [ERR] [VID] [Jun 16 07:26:10] v4l2_select_input: Error selecting input 0 VIDIOC_S_INPUT: Device or resource busy
[1:ml1] [NTC] [VID] [Jun 16 07:26:10] vid_v4lx_start: Using V4L1
[1:ml1] [NTC] [ALL] [Jun 16 07:26:10] image_ring_resize: Resizing pre_capture buffer to 1 items
[1:ml1] [ERR] [ALL] [Jun 16 07:26:20] motion_init: Error capturing first image
[1:ml1] [NTC] [STR] [Jun 16 07:26:20] http_bindsock: error binding on any IPv4 address port 8081
[1:ml1] [ERR] [ALL] [Jun 16 07:26:20] motion_init: Problem enabling motion-stream server in port 8081: Address already in use
[1:ml1] [NTC] [ALL] [Jun 16 07:26:20] motion_loop: Thread exiting
[1:ml1] [NTC] [VID] [Jun 16 07:26:20] vid_close: Closing video device /dev/video0
[0:motion] [NTC] [ALL] [Jun 16 07:26:21] main: Motion thread 1 restart
[1:ml1] [NTC] [ALL] [Jun 16 07:26:21] motion_init: Camera 0 started: motion detection Enabled
[1:ml1] [NTC] [VID] [Jun 16 07:26:21] vid_v4lx_start: Using videodevice /dev/video0 and input -1
[1:ml1] [NTC] [VID] [Jun 16 07:26:21] v4l2_get_capability:
------------------------
cap.driver: "uvcvideo"
cap.card: "HD Webcam C615"
cap.bus_info: "usb-ff540000.usb-1.1"
cap.capabilities=0x84200001
------------------------
[1:ml1] [NTC] [VID] [Jun 16 07:26:21] v4l2_get_capability: - VIDEO_CAPTURE
[1:ml1] [NTC] [VID] [Jun 16 07:26:21] v4l2_get_capability: - STREAMING
[1:ml1] [NTC] [VID] [Jun 16 07:26:21] v4l2_select_input: name = "Camera 1", type 0x00000002, status 00000000
[1:ml1] [NTC] [VID] [Jun 16 07:26:21] v4l2_select_input: - CAMERA
[1:ml1] [ERR] [VID] [Jun 16 07:26:21] v4l2_select_input: Error selecting input 0 VIDIOC_S_INPUT: Device or resource busy
[1:ml1] [NTC] [VID] [Jun 16 07:26:21] vid_v4lx_start: Using V4L1
[1:ml1] [NTC] [ALL] [Jun 16 07:26:21] image_ring_resize: Resizing pre_capture buffer to 1 items
(END)
阅读日志时,我认为该进程正在运行,但事实并非如此。
根据建议,我尝试设置一个 cron 作业,运行sudo crontab -e
并添加行 @reboot/usr/bin/motion -b
但重新启动时,运动守护进程仍然没有运行。
我只是想知道在启动时启动此过程的现代方法。Ubuntu 18.04,LXDE。
答案1
您可以使用 cron@reboot
sudo crontab -e
并添加行
@reboot /path/to/bin/motion -b
答案2
首先,尝试使用 手动运行它sudo -u motion motion
。如果成功,则问题是由 systemd 引起的。
这是违反直觉的,但是使用 systemd 您应该daemon off
在 motion.conf 中进行设置。
PS:/etc/defualt/motion
Ubuntu/Debian 可能不需要该文件。