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?

4 Answers 4

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

2
  • Thanx! I was looking for hours for a workaround!
    – ampofila
    Jul 23, 2017 at 10:13
  • 1
    I was to eager to be happy... Even though it starts there is no way to stay on. I get this error: Jul 23 16:19:30 raspberrypi motion: [1] [ERR] [ALL] myfopen: Error opening file /home/pi/motion/01-201707231619.jpg with mode w: Jul 23 16:19:30 raspberrypi motion: [1] [ERR] [ALL] put_picture: Can't write picture to file /home/pi/motion/01-201707231619.jpg - check access rights to target directory#012Thread is going to finish due to this fatal error: and the application extis...
    – ampofila
    Jul 23, 2017 at 16:21
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

-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

3
  • 1
    Please take note that using /etc/rc.local has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using it. You should load the module with a *.conf in /etc/modprobe.d/.
    – Ingo
    Feb 27, 2019 at 12:37
  • 1
    @Ingo Why not add the module to /etc/modules instead of creating a new one?
    – Dirk
    Feb 27, 2019 at 13:15
  • @Dirk Yes, you are right, that's better/simpler (so much possibilities ;)
    – Ingo
    Feb 27, 2019 at 14:10
-2

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

1
  • Welcome to the site. This answer is short enough to have been flagged by the Community user as 'low quality'. Can you expand on it to provide some explanation as to what your suggested commands do, and how they address the problem?
    – goobering
    Feb 21, 2017 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.