5

I'm trying to run Motion as a deamon, however whenever I try to write a file, it crashes and I find this in my syslog:

Dec 19 10:52:40 raspberrypi motion: [1] Resizing pre_capture buffer to 1 items
Dec 19 10:53:27 raspberrypi motion: [1] Error opening file /home/pi/Monitor/01-20131219105327-00.jpg with mode w: Permission denied
Dec 19 10:53:27 raspberrypi motion: [1] Can't write picture to file /home/pi/Monitor/01-20131219105327-00.jpg - check access rights to target$
Dec 19 10:53:27 raspberrypi motion: [1] Thread is going to finish due to this fatal error: Permission denied

It was able to write files there when I started it manually. Only since running it as a deamon did it start giving these errors/crash. I've read/google'd countles Motion tutorials and haven't found one that explicitly talks about permissions required to write files to a given directory.

Note, my motion.conf points at:

target_dir /home/pi/Monitor

daemon on

And in /etc/default/motion I've changed

start_motion_daemon=yes

Am I doing something obviously dumb, or what permissions and where do I need to assign?

KHibma
  • 280
  • 2
  • 6
  • 17

4 Answers4

10

Motion usually creates it's own user called motion and when you run motion as daemon, this user is used.

I suggest you change the group of the folder and make the folder group-writeable so that both you (user: pi) and motion (group:motion) will be able to read and write to that directory without making it world-readable.

As root:

1) Change the group of the directory to motion

chgrp motion /home/pi/Monitor

2) Give full access to the directory to the motion group

chmod g+rwx /home/pi/Monitor

3) Optional: Give write access to everything inside the directory, in case motion wants to overwrite something (e.g. the timelapse video). Alternatively, you can just empty the directory and let motion create everything on it's own.

chmod -R g+w /home/pi/Monitor/

Start the daemon. It should be ok now.


NOTE:

To make sure which user is running the motion daemon use this command while the daemon is running.

ps aux | grep -v grep | grep motion

The output looks like this if the daemon is running.

motion    2500  2.1  1.9  53620  9908 ?        Sl   Nov22 865:08 /usr/bin/motion

The first column is the user. In my case it is indeed motion

foibs
  • 803
  • 1
  • 8
  • 9
1

In Debian I wasn't able to get this to work with another directory other than the home directory of the motion process, specified in /etc/passwd , indifferent of permissions

I had to mount --bind /home/storage/videos /var/lib/motion in order to mount another drive in the home dir of the motion process

jsaddwater
  • 131
  • 5
-1

I kept banging my head against the wall because I had a similar ffmpeg error that did not disappear by modifying the folder permissions. google kept bringing me to this answer so since I have it working now I'll add it to help others

i had to add

modprobe bcm2835-v4l2

to

/etc/rc.local

see for more details. RasPi Camera Board and Motion

-2

Try starting using "sudo motion" instead of using "sudo service" or "sudo /etc/init.d/".

Alan
  • 1