5

I have a Pi Zero W running Raspbian Stretch Lite (June 2018). I'm using it to turn the crank on an automatic cat feeder. I've barely changed the base configuration: apt-get-installed git and samba, used Python's pip to install wiringpi and psutil, and scheduled my Python script to run at 7AM and 7PM using crontab -e.

In the mornings I've been finding the pi shut down and missed the 7AM feeding. Unplug/replug brings it back up. I set up a ping test from my desktop and discovered for the last three days that the system shuts down at exactly 11:23 in the evening (eastern daylight time).

I've confirmed that there is no cron job for the pi user or the super user for that time (or at any time, other than the feedings.) I'm pretty new to Linux. What could be causing this?

Update 2:

I stayed up tonight and observed the issue. Sure enough, the LED switched off at 11:23 and my SSH session went dead. Interesting twist: I powered it up again right away, and it shut down again about 1 minute later! This pattern repeated until around 11:28, after which point it has stayed up no problem.

Here is a gist with the /var/log/messages for the whole affair. What's strange is that the system appears to boot up at 11:17, although I didn't shut it down and my ping test didn't report an outage.

https://gist.github.com/buzzcola/6ea029d7d496d8852b4c7a062945937b

  • 4
    A bit hard to say. If you are powering from the mains I'd say something like central heating is switched on at that time which sends an EMF spike and knocks out the Pi. – joan Aug 29 '18 at 11:21
  • 1
    That's an interesting idea! I was thinking about scheduled tasks in the local software but if it were a power spike it could be anything scheduled in the house. I do have an air conditioner running on a thermostat, but it kicks in based on ambient temperature so the time would be arbitrary. – James Orr Aug 29 '18 at 11:39
  • 1
    I do have a surge suppressor I could plug into. I'll try that tonight. – James Orr Aug 29 '18 at 11:42
  • 3
    Any chance your script get stuck in a loop that runs for 4 hrs and 23 minutes before crashing? Power surge is possible, but it seems strange that you'd get one so regularly. – Brick Aug 29 '18 at 17:04
  • 2
    Does /var/log/syslog show anything around that time? Is the Pi really "shutdown" like from a shutdown command? – HeatfanJohn Aug 29 '18 at 17:57
1

Solved! It turns out there's another cron file I didn't know about, /etc/crontab. I took a look and found this:

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
23 3    * * *   pi      python /share/squeakernet/squeakernet.py feed
#

The last line was me, I guess. 03:23 (11pm my local time) must have been an incorrect adding of four hours instead of subtracting. When the script runs as the "pi" user (not root) it apparently causes a completely un-logged crash.

  • Is there any mechanism that would change /etc/crontab other than directly editing the file? I have no memory of changing this, nor why I would ever have specified 03:23 for the time. – James Orr Aug 30 '18 at 23:38
  • And how would this explain the repeated crashes from ~11:23 to ~11:28? Does cron pick up missed/failed/recent jobs and try to recover/run them? – James Orr Aug 30 '18 at 23:42
  • 2
    If you do sudo crontab -e then you make an entry in root's crontab. If you do crontab -e (without the sudo), then you make an entry in the user's crontab, in your case pi. I'd guess that you accidentally did it the wrong way once and didn't notice. Maybe if you type history you'll see it, assuming that it's still in the history. – Brick Aug 31 '18 at 0:06
  • 1
    Related to some of your secondary questions: askubuntu.com/questions/609850/… – Brick Aug 31 '18 at 0:47
  • 1
    If you hadn't found this, I was going to blame the cat next, so just as well that you discovered the answer yourself. – Brick Aug 31 '18 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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