pageauc / speed-camera

A Unix, Windows, Raspberry Pi Object Speed Camera using python, opencv, video streaming, motion tracking. Includes a Standalone Web Server Interface, Image Search using opencv template match and a whiptail Admin Menu Interface Includes picam and webcam Plugins for motion track security camera configuration including rclone sync script. watch-app allows remotely controller camera configuration from a remote storage service name. Uses sqlite3 and gnuplot for reporting. Recently added openalpr license plate reader support.
Apache License 2.0
983 stars 172 forks source link

trying to setup crontab to start camera at 6am and stop at 2000 but doesn't work. #96

Closed johncblacker closed 3 years ago

johncblacker commented 3 years ago

I'm trying to setup crontab to start camera at 0600, stop at 2000 but it's not working - never continues running. My crontab entry: 0 6 /home/pi/git-projects/speed-camera/speed-cam.sh start >> /home/pi/git-projects/speed-camera/speedcam.log 59 20 /home/pi/git-projects/speed-camera/speed-cam.sh stop >> /home/pi/git-projects/speed-camera/speedcam.log My speedcam.log shows: START - Start speed-cam.py in Background ... STATUS - speed-cam.py is Running ... STATUS - PID is 31430 INFO - To Stop speed-cam.py execute command below INFO - /home/pi/git-projects/speed-camera/speed-cam.sh stop Done /home/pi/git-projects/speed-camera/speed-cam.sh ver 6.00 written by Claude Pageau But if I check for running speed-cam after the start, it isn't there. What might I be doing wrong? I also tried starting it after reboot with: @reboot cd /home/pi/git-projects/speed-camera && ./speed-cam.sh start >/home/pi/git-projects/speed-camera/cronlog.log but it doesn't start, not running when I check. Maybe some guidance in trying to find out what's wrong?

pageauc commented 3 years ago

Edit speed-cam.sh script and change the progpath variable to path where speed-cam.py is located. The shell script is hard coded to /home/pi/speed-camera so change to

progpath="/home/pi/git-projects/speed-camera/"

This is the top of

!/bin/bash

This script will run the speed-cam.py as a background task

You will then be able close the terminal session. To auto start

Add the following command to the /etc/rc.local

/home/pi/speed-camera/speed-cam.sh start

progpath="/home/pi/speed-camera" progname="speed-cam.py"

make sure speed-cam.sh works from command line

Let me know if this resolves your problem.

On Sun, Jul 18, 2021 at 6:30 PM John Blacker @.***> wrote:

I'm trying to setup crontab to start camera at 0600, stop at 2000 but it's not working - never continues running. My crontab entry: 0 6 /home/pi/git-projects/speed-camera/speed-cam.sh start >> /home/pi/git-projects/speed-camera/speedcam.log 59 20 /home/pi/git-projects/speed-camera/speed-cam.sh stop >> /home/pi/git-projects/speed-camera/speedcam.log My speedcam.log shows: START - Start speed-cam.py in Background ... STATUS - speed-cam.py is Running ... STATUS - PID is 31430 INFO - To Stop speed-cam.py execute command below INFO - /home/pi/git-projects/speed-camera/speed-cam.sh stop Done /home/pi/git-projects/speed-camera/speed-cam.sh ver 6.00 written by Claude Pageau But if I check for running speed-cam after the start, it isn't there. What might I be doing wrong? I also tried starting it after reboot with: @reboot https://github.com/reboot cd /home/pi/git-projects/speed-camera && ./speed-cam.sh start >/home/pi/git-projects/speed-camera/cronlog.log but it doesn't start, not running when I check. Maybe some guidance in trying to find out what's wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/96, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZAEELM3FV7CRNRHIVTTYNIWXANCNFSM5ASSAJNQ .

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

johncblacker commented 3 years ago

I had already made the directory that you suggest early on in my testing. I will try changing rc.local as you suggest to take

care of the reboot problem; but that still leaves the issue regarding starting the application and stopping it via cron. I’ve

researched that online and found nothing that suggests I’m doing anything wrong, so it’s still a mystery. I even changed

from using the shell script to simply trying to start the speed-cam.py program itself in the crontab and looking at my output

from that and, there again, I see where it was supposedly started, yet when I check via ./speed-cam.sh status it indicates it

is not running. I also used “ps -ef | grep “ and “ps -ef | grep speed” to check the status of the app and it all cases

it is not running. So, for whatever reason, it might have gotten started, then ended? I’m searching for any ideas as to how

to pursue finding the error. I have used simply dummy test.sh scripts in the crontab and they execute fine.

So, thanks for your suggestion. I will continue to pursue this, but if you have any further ideas regarding the crontab issue

I welcome them and will try anything.

Thanks again.

From: Claude Pageau @.> Sent: Sunday, July 18, 2021 6:59 PM To: pageauc/speed-camera @.> Cc: John Blacker @.>; Author @.> Subject: Re: [pageauc/speed-camera] trying to setup crontab to start camera at 6am and stop at 2000 but doesn't work. (#96)

Edit speed-cam.sh script and change the progpath variable to path where speed-cam.py is located. The shell script is hard coded to /home/pi/speed-camera so change to

progpath="/home/pi/git-projects/speed-camera/"

This is the top of

!/bin/bash

This script will run the speed-cam.py as a background task

You will then be able close the terminal session. To auto start

Add the following command to the /etc/rc.local

/home/pi/speed-camera/speed-cam.sh start

progpath="/home/pi/speed-camera" progname="speed-cam.py"

make sure speed-cam.sh works from command line

Let me know if this resolves your problem.

On Sun, Jul 18, 2021 at 6:30 PM John Blacker @. <mailto:@.> > wrote:

I'm trying to setup crontab to start camera at 0600, stop at 2000 but it's not working - never continues running. My crontab entry: 0 6 /home/pi/git-projects/speed-camera/speed-cam.sh start >> /home/pi/git-projects/speed-camera/speedcam.log 59 20 /home/pi/git-projects/speed-camera/speed-cam.sh stop >> /home/pi/git-projects/speed-camera/speedcam.log My speedcam.log shows: START - Start speed-cam.py in Background ... STATUS - speed-cam.py is Running ... STATUS - PID is 31430 INFO - To Stop speed-cam.py execute command below INFO - /home/pi/git-projects/speed-camera/speed-cam.sh stop Done /home/pi/git-projects/speed-camera/speed-cam.sh ver 6.00 written by Claude Pageau But if I check for running speed-cam after the start, it isn't there. What might I be doing wrong? I also tried starting it after reboot with: @reboot https://github.com/reboot cd /home/pi/git-projects/speed-camera && ./speed-cam.sh start >/home/pi/git-projects/speed-camera/cronlog.log but it doesn't start, not running when I check. Maybe some guidance in trying to find out what's wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/96, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZAEELM3FV7CRNRHIVTTYNIWXANCNFSM5ASSAJNQ .

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/96#issuecomment-882127949 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAAU6ZERAANDIVEWDC2DTYNMDRANCNFSM5ASSAJNQ . https://github.com/notifications/beacon/AB6WAAUCVR63TAYNC63N7TTTYNMDRA5CNFSM5ASSAJN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGSKDITI.gif

johncblacker commented 3 years ago

So, put the startup command in rc.local, rebooted and the output from the startup said it failed to import cv2! So, at whatever level it was at when

it ran, it couldn’t perform the import; however, I don’t have any problems running after startup is complete. Wonder if there’s a way to only execute

the command at a specific “run level” – I’ll have to research that.

From: Claude Pageau @.> Sent: Sunday, July 18, 2021 6:59 PM To: pageauc/speed-camera @.> Cc: John Blacker @.>; Author @.> Subject: Re: [pageauc/speed-camera] trying to setup crontab to start camera at 6am and stop at 2000 but doesn't work. (#96)

Edit speed-cam.sh script and change the progpath variable to path where speed-cam.py is located. The shell script is hard coded to /home/pi/speed-camera so change to

progpath="/home/pi/git-projects/speed-camera/"

This is the top of

!/bin/bash

This script will run the speed-cam.py as a background task

You will then be able close the terminal session. To auto start

Add the following command to the /etc/rc.local

/home/pi/speed-camera/speed-cam.sh start

progpath="/home/pi/speed-camera" progname="speed-cam.py"

make sure speed-cam.sh works from command line

Let me know if this resolves your problem.

On Sun, Jul 18, 2021 at 6:30 PM John Blacker @. <mailto:@.> > wrote:

I'm trying to setup crontab to start camera at 0600, stop at 2000 but it's not working - never continues running. My crontab entry: 0 6 /home/pi/git-projects/speed-camera/speed-cam.sh start >> /home/pi/git-projects/speed-camera/speedcam.log 59 20 /home/pi/git-projects/speed-camera/speed-cam.sh stop >> /home/pi/git-projects/speed-camera/speedcam.log My speedcam.log shows: START - Start speed-cam.py in Background ... STATUS - speed-cam.py is Running ... STATUS - PID is 31430 INFO - To Stop speed-cam.py execute command below INFO - /home/pi/git-projects/speed-camera/speed-cam.sh stop Done /home/pi/git-projects/speed-camera/speed-cam.sh ver 6.00 written by Claude Pageau But if I check for running speed-cam after the start, it isn't there. What might I be doing wrong? I also tried starting it after reboot with: @reboot https://github.com/reboot cd /home/pi/git-projects/speed-camera && ./speed-cam.sh start >/home/pi/git-projects/speed-camera/cronlog.log but it doesn't start, not running when I check. Maybe some guidance in trying to find out what's wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/96, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZAEELM3FV7CRNRHIVTTYNIWXANCNFSM5ASSAJNQ .

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/96#issuecomment-882127949 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6WAAU6ZERAANDIVEWDC2DTYNMDRANCNFSM5ASSAJNQ . https://github.com/notifications/beacon/AB6WAAUCVR63TAYNC63N7TTTYNMDRA5CNFSM5ASSAJN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGSKDITI.gif

johncblacker commented 3 years ago

** update 14:54 est **

Success running as a service. I wasn’t able to make it work by starting via the speed-cam.sh script so I reverted to just

using ‘python speed-cam.py’ after first changing the settings so that the cv windows weren’t being displayed…that doesn’t work

when running as a service; but, who cares? If you want to see you can go to the webserver and display the current image(s) which

is actually better because they have the speed displayed on them.

So, I now have something that’ll work a reboot time, all I have to do is issued ‘sudo systemctl enable speedcam.service’

Here is a link to the page I fashioned my speedcam.service after:

            systemd - Raspberry Pi Documentation <https://www.raspberrypi.org/documentation/linux/usage/systemd.md> 

Here’s my “unit file” speedcam.service contents:

[Unit]

Description=Speed camera

After=network.target

[Service]

ExecStart=/bin/bash -c '\

python /home/pi/git-projects/speed-camera/speed-cam.py > /home/pi/git-projects/speed-camera/script.txt 2>&1'

WorkingDirectory=/home/pi/git-projects/speed-camera

StandardOutput=inherit

StandardError=inherit

Restart=on-failure

RestartSec=30s

User=pi

[Install]

WantedBy=multi-user.target

That file is in /etc/systemd/system named speedcam.service

Now, I’m going to tackle the up/down at a specific time of day…

cheers!

** Update ****

switched over from crontab to starting this as a service. That would then start immediately after reboot; and by having it a service, I can simply put

systemctl restart speedcam.service in crontab – which I’m sure will work.

But (there’s always a but, isn’t there) when I tried to test start the service, I get some messages in the log which indicate a problem:

Started Speed camera.

Jul 19 13:57:36 client1 systemd[1]: speedcam.service: Main process exited, code=exited, status=1/FAILURE

Jul 19 13:57:36 client1 systemd[1]: speedcam.service: Failed with result 'exit-code'.

So, there appears to be a problem.

From: Claude Pageau @.> Sent: Sunday, July 18, 2021 6:59 PM To: pageauc/speed-camera @.> Cc: John Blacker @.>; Author @.> Subject: Re: [pageauc/speed-camera] trying to setup crontab to start camera at 6am and stop at 2000 but doesn't work. (#96)

Edit speed-cam.sh script and change the progpath variable to path where speed-cam.py is located. The shell script is hard coded to /home/pi/speed-camera so change to

progpath="/home/pi/git-projects/speed-camera/"

This is the top of

!/bin/bash

This script will run the speed-cam.py as a background task

You will then be able close the terminal session. To auto start

Add the following command to the /etc/rc.local

/home/pi/speed-camera/speed-cam.sh start

progpath="/home/pi/speed-camera" progname="speed-cam.py"

make sure speed-cam.sh works from command line

Let me know if this resolves your problem.

On Sun, Jul 18, 2021 at 6:30 PM John Blacker @. <mailto:@.> > wrote:

I'm trying to setup crontab to start camera at 0600, stop at 2000 but it's not working - never continues running. My crontab entry: 0 6 /home/pi/git-projects/speed-camera/speed-cam.sh start >> /home/pi/git-projects/speed-camera/speedcam.log 59 20 /home/pi/git-projects/speed-camera/speed-cam.sh stop >> /home/pi/git-projects/speed-camera/speedcam.log My speedcam.log shows: START - Start speed-cam.py in Background ... STATUS - speed-cam.py is Running ... STATUS - PID is 31430 INFO - To Stop speed-cam.py execute command below INFO - /home/pi/git-projects/speed-camera/speed-cam.sh stop Done /home/pi/git-projects/speed-camera/speed-cam.sh ver 6.00 written by Claude Pageau But if I check for running speed-cam after the start, it isn't there. What might I be doing wrong? I also tried starting it after reboot with: @reboot https://github.com/reboot cd /home/pi/git-projects/speed-camera && ./speed-cam.sh start >/home/pi/git-projects/speed-camera/cronlog.log but it doesn't start, not running when I check. Maybe some guidance in trying to find out what's wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/96, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZAEELM3FV7CRNRHIVTTYNIWXANCNFSM5ASSAJNQ .

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

— You are receiving this because you authored the thread. Reply to this email directly, https://github.com/pageauc/speed-camera/issues/96#issuecomment-882127949 view it on GitHub, or https://github.com/notifications/unsubscribe-auth/AB6WAAU6ZERAANDIVEWDC2DTYNMDRANCNFSM5ASSAJNQ unsubscribe. https://github.com/notifications/beacon/AB6WAAUCVR63TAYNC63N7TTTYNMDRA5CNFSM5ASSAJN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGSKDITI.gif

johncblacker commented 3 years ago

After converting to a service, the process of starting at boot is simplified by simply "systemctl enable speedcam.service" and commands in crontab simply become: "systemctl start speedcam.service" and "systemctl stop speedcam.service" and I verified those work. Cron is a fine service, but difficult to debug when something doesn't work; although by having your scripts or command write output to a Githubissues.

  • Githubissues is a development platform for aggregating issues.