0

Up until May 2021, motion was working successfully on my Raspberry Pi 4. After May 2021, when motion is running and my web camera is enabled, as soon as it detects any motion, the camera disables itself.

I've reviewed the following related questions before posting, but they did not offer any solution:

What permissions does Motion require to write to specific directory?

Motion ffmpeg_open: url_fopen - error opening file (check access rights to target directory)

I checked /var/log/motion/motion.log and it reports the following:

[1:ml1] [ERR] [ALL] [Nov 23 11:05:46] myfopen: Error opening file /media/samba_disk/motion/01-20211123110546-snapshot.jpg with mode w: Permission denied
[1:ml1] [ERR] [ALL] [Nov 23 11:05:46] put_picture: Can't write picture to file /media/samba_disk/motion/01-20211123110546-snapshot.jpg - check access rights to target directory
Thread is going to finish due to this fatal error: Permission denied
[1:ml1] [ERR] [EVT] [Nov 23 11:05:46] event_image_snapshot: Could not create symbolic link [01-20211123110546-snapshot.jpg]: Permission denied
[1:ml1] [NTC] [ALL] [Nov 23 11:05:46] motion_loop: Thread exiting
[1:ml1] [NTC] [STR] [Nov 23 11:05:46] stream_stop: Closing motion-stream listen socket & active motion-stream sockets
[1:ml1] [NTC] [STR] [Nov 23 11:05:46] stream_stop: Closed motion-stream listen socket & active motion-stream sockets
[1:ml1] [NTC] [VID] [Nov 23 11:05:46] vid_close: Cleaning up V4L2 device
[1:ml1] [NTC] [VID] [Nov 23 11:05:46] v4l2_cleanup: Closing video device /dev/video0

To confirm, the target directory in /etc/motion/motion.conf:

more /etc/motion/motion.conf | grep target_dir
target_dir /media/samba_disk/motion

Checking the permissions of the target directory, the owner and group is motion and permissions are 777:

ls -la /media/samba_disk/
drwxrwxrwx 51 motion              motion              12288 Nov 14 14:58 motion

My local user is also a member of the motion group:

$ groups
tv adm dialout cdrom sudo audio video plugdev users input netdev debian-transmission motion gpio i2c spi

I also made sure that the disk of the target directory is mounted and has free space:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       916G  340G  531G  40% /media/samba_disk

Everything appears to be set correctly for files to be written to motion's target directory. So why do I still receive write permission errors?

jimjamz
  • 73
  • 2
  • 8

1 Answers1

1

From your description, it seems a distinct possibility that something changed in May, 2021. That something could have been in your RPi configuration (perhaps as the result of an update), or it could have been that motion was changed.

You didn't indicate when you last performed an apt update and apt upgrade. If you've not done that recently, it would be a good idea to do that now - perhaps your issue has already been resolved?

The errors you cited in your question certainly look like permissions issues, but I would caution you against making permission changes willy-nilly as unintended consequences are always lurking in the shadows.

If the update & upgrade suggestion above didn't resolve your issue, two alternatives that are more likely than permission-fiddling to lead to a stable solution are:

1. Use the support resources provided by the motion project

motion seems to be a well-resourced, active project supporting a number of platforms. They maintain a mailing list, and it's quite likely that you're not the only RPi user who's encountered the issue you've described. motion also maintains a repo on GitHub with useful resources.

2. Remove and re-install motion

If you aren't inclined to mailing lists, or just impatient to move ahead, it's easy enough to remove the motion package, and re-install it. If you elect this approach, be sure to run update & upgrade before you begin:

sudo apt update
sudo apt upgrade

Having done that, you can remove your current version of motion as follows:

sudo apt-get purge motion

The purge option will remove motion as well as any configuration files it set up (ref man apt). It might also be a good idea to set aside your samba-based target_dir and use a local target_dir (e.g. /home/pi/motion_target) to eliminate the variable of samba issues.

It won't hurt to run update & upgrade after the purge.

Finally, re-install motion & edit its config file as required:

sudo apt-get install motion
Seamus
  • 23,558
  • 5
  • 42
  • 83