I have installed the motion package on my pi (stretch). If I start motion in the foreground it's working but when I try to start it as a daemon it fails with the following log message:
motion: permission denied for /var/log/motion/motion.log
I've seen many approaches to fix this problem by tinkering with the permissions of /var/log/... but this does not convince me.
Q What's the correct way to fix this problem?
Update
I've motion installed as a service and I start it for testing with
sudo service motion start
but even then it fails with the error message below
raspberrypi motion[323]: [0:motion] [ERR] [ALL] myfopen: Error opening file /var/log/motion/motion.log with mode a: Permission denied
5 Answers
Gotcha! For testing I started motion with sudo motion -b. Therefore, /var/log/motion/motion.log was written with root:root. After removing /var/log/motion and reboot, the motion-daemon was up and running and had the permission to write to the log.
-
Same thing happened to me. I think this should be the accepted answer. After removing the /var/log/motion directory, restart the service using sudo service motion restart and it works correctly.– jontsaiOct 20, 2018 at 3:05
-
Same thing happened to me. Had to sudo rm -fr /var/log/motion then restart the service and now the right owner/group shows on that folder.– Josh PJan 4, 2020 at 15:22
-
This isn't working for me. The directory doesn't get created after a reboot and I get the same error with after sudo service motion restart– NickGApr 8 at 8:40
-
@NickG You need to remove /var/log/motion (i.e. sudo rm -r /var/log/motion) at first and then reboot. Apr 19 at 15:40
There are three ways to fix the problem. All are really the same, just from different angles. That is to make sure that the user starting motion has the access permission to write into the /var/log/motion/ directory. First could just make that user the owner of the directory. And give the owner write access. The second would be start the daemon using root by using the sudo command. An alternative third method is to allow write access to the log directory for a group 'motion' and to make that a supplementary group of any user needing to be able to start the daemon.
E.g. Assuming you want to create group motion and add user pi
pi@raspberrypi:~$sudo groupadd motion pi@raspberrypi:~$sudo usermod -aG motion pi
Finally change the ownership and permission of the /var/log/motion directory
pi@raspberrypi:~$cd /var/log pi@raspberrypi:/var/log $ chown root:motion motion pi@raspberrypi:/var/log $ chmod 664 motion
It is simpler and more normal to start the daemon as the root user who should already have all the correct permissions by using sudo command as I already mentioned.
>reboot
>sudo service motion restart
'라즈베리파이' 카테고리의 다른 글
How to Build Your Own Amazon Echo with a Raspberry Pi (0) | 2022.05.18 |
---|---|
Screenly와 Raspberry Pi를 사용하여 디지털 전광판 만들기 (0) | 2022.05.18 |
라즈베리파이 웹캠 - motion (0) | 2022.05.18 |
RPI Cloud Cam 따라하기 (0) | 2022.05.18 |
[Raspberry Pi] 웹캠 연결하기(motion) (0) | 2022.05.18 |
댓글