1

I'm using the motion library on a raspberry pi zero with sketch.

In order to get the motion server to start on boot, 've updated /etc/rc.local to include the following:

sudo motion -c ~/.motion/motion.conf &

I'm having an issue with starting motion on boot. When I boot, I execute

ps aux | grep motion.conf 

and see the following:

root 550  0.0  0.7   7212  2956 pts/0    S+   14:30   0:00  sudo motion -c /home/pi/.motion/motion.conf

root 554 23.1  7.5 137524 28680 pts/0    Sl+  14:30   3:13 motion -c /home/pi/.motion/motion.conf 

pi 595  0.0  0.4   4336  1660 pts/1    S+   14:44   0:00 grep --color=auto motion.conf*

If I kill -9 the first two processes, I'm able to successfully execute

sudo motion -c ~/.motion/motion.conf

Thanks for your help.

7
  • Apparently, motion is started. Why do you need to kill it and start it again?
    – Dirk
    Commented Aug 18, 2018 at 15:06
  • 1
    Don't use sudo in /etc/rc.local. It's at best superfluous. If you need to test it, use sudo /etc/rc.local instead.
    – goldilocks
    Commented Aug 18, 2018 at 16:41
  • Paste in the output from ps -lC motion, and, for each process listed, the output from ps -lp NNN, where NNN is the PPID (not PID).
    – goldilocks
    Commented Aug 18, 2018 at 16:48
  • Thanks @Dirk, When I boot the pi and check "sudo service motion" it shows motion as "active (exited)", and checking the media dir no images are being created. So I kill the processes and run "sudo motion -c ~/.motion/motion.conf" and motion works correctly. Commented Aug 19, 2018 at 11:49
  • Thanks @goldilocks, here's the output of the two commands: pi@raspberrypi:~ $ ps -lC motion F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 554 550 14 80 0 - 34492 - ? 03:05:14 motion pi@raspberrypi:~ $ ps -lp 550 F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 550 1 0 80 0 - 1803 - ? 00:00:00 sudo Commented Aug 19, 2018 at 11:49

2 Answers 2

2

Since version Jessie Raspbian comes with systemd that replaces classic SysV init process. rc.local belongs to SysV. To be compatible systemd tries to emulate classic SysV but with many limitations. Look at systemd - Compatibility with SysV what you have to take attention for when using rc.local. Better you switch over to systemd and start your services with a unit. A simple unit for your program could look like this but I don't know if there are some edge conditions you have to configure. By default it runs as root. Maybe you have to set User=pi on section [Service]?

[Unit]
Wants=multi-user.target
After=multi-user.target

[Service]
ExecStart=/usr/bin/motion -c /home/pi/.motion/motion.conf

[Install]
WantedBy=multi-user.target
0
0

Motion is automatically started at boot if you have installed it as a service (apt-get install method), if you compiled and built - what you are doing is correct. But essentially if just used regular way of installing motion, you are creating two processes of motion at boot by adding it to rc.local.

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.