nebhead / garage-zero-v2

Garage Zero v2 - Raspberry Pi Garage Door Control & Status
https://nebhead.github.io/garage-zero-v2
MIT License
4 stars 2 forks source link

Internal Server Error #4

Closed jamiezorin closed 1 month ago

jamiezorin commented 2 months ago

After three weeks I get this message, it's the second time I rebuild, I'm able to get to the console but no web access.

"Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."

Error.log: 2024/07/28 12:53:15 [error] 608#608: *58 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.213, server: , request: "GET /status HTTP/1.1", upstream: "http://127.0.0.1:8000/status", host: "192.168.1.13", referrer: "http://192.168.1.13/"

Access.log: 192.168.1.10 - - [02/Aug/2024:10:20:18 -0400] "GET / HTTP/1.1" 500 265 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0" 192.168.1.10 - - [02/Aug/2024:10:20:18 -0400] "GET /favicon.ico HTTP/1.1" 499 0 "http://192.168.1.13/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0"

nebhead commented 2 months ago

Can you ssh into your pi and share the log for the webapp?

cd /usr/local/bin/garage-zero-v2/logs
cat webapp.err.log 
jamiezorin commented 2 months ago

Here is the log file webapp.err.log

nebhead commented 2 months ago

Thanks for providing the log!

Just to clarify, this was working and then suddenly stopped working after a while? Or was it never really working?

What I'm seeing from the log file is that the web interface is trying to read the events.log file but is getting a permission error. That might mean that something is happening to the SDCard, like corruption. But just a theory.

jamiezorin commented 2 months ago

It was working perfectly for awhile and I got the error message. Well what I'll do is change the SD card and see if I get the same issue. It may take two weeks to show up but hopefully your right and its a bad SD card.

nebhead commented 2 months ago

It was working perfectly for awhile and I got the error message. Well what I'll do is change the SD card and see if I get the same issue. It may take two weeks to show up but hopefully your right and its a bad SD card.

One other thing you might want to check on is your power supply. I've had a flaky power supply haunt me in the past - causing the system to corrupt silently.

jamiezorin commented 2 months ago

I've replaced the power supply and reinstalled garage-zero-v2. all settings were retained. Let you know if there is any further issues.

nebhead commented 2 months ago

Thanks. Hopefully that does it.

jamiezorin commented 1 month ago

After 3 weeks it's working and no issues after replacing the power supply. Thanks again for the great support for such a wonderful project.

nebhead commented 1 month ago

After 3 weeks it's working and no issues after replacing the power supply. Thanks again for the great support for such a wonderful project.

Great news! And you are totally welcome, my pleasure.

jamiezorin commented 1 month ago

Looks like the dragon came back today, I have replaced the SD card and the power supply. I'll provide the log file. webapp.err.log

nebhead commented 1 month ago

Dang it! Thanks for the log file. I'll take a look and see if there is anything that might lead us somewhere.

nebhead commented 1 month ago

Oh man... I think I know what the issue is.

From your log file it seems like a permissions issue with accessing the events.log file. This means that permissions have changed for this file somewhere along the line. As it turns out, I have a cronjob (scheduled job) that will backup the logs to the /logs folder and then create a new events.log file. Unfortunately, I created that cronjob as a root process. I think I need to change this to a user process instead, or allow reading/writing to this file by other users. I think I need to investigate further. Also not sure why it appears to be working on my installation. Give me a bit to see if I can fix it up and get back to you.

jamiezorin commented 1 month ago

OK, sounds good.

nebhead commented 1 month ago

The issue is that the beginning of each month, the events.log file will be copied into the /logs folder as a backup log. Then the script will create a new log file. The problem is that the script is running as root, thus it will set permissions for root only.

OK, let's try this. You'll need to SSH into your Pi with the same user as you used to install the software.

First, let's remove your root crontab.

sudo crontab -e

Choose 'nano' as your editor (or whatever editor you like the most).

Remove the line:

0 0 1 * * cd /usr/local/bin/garage-zero-v2/logs && sh backup.sh

Then save and exit (Ctrl-O, Ctrl-X in nano).

Next we will create the exact same crontab entry for your unprivileged. Run the following:

crontab -l > my-crontab
echo "0 0 1 * * cd /usr/local/bin/garage-zero-v2/logs && sh backup.sh" >> my-crontab
crontab my-crontab
rm my-crontab

Lastly, we need to change permissions for the events.log file.

cd /usr/local/bin/garage-zero-v2
sudo chmod 777 events.log

Now try going back to the web interface again and see if you are getting any errors.

Let me know how this goes. If it seems to resolve the issue, I'll update the install scripts so that it doesn't break others.

jamiezorin commented 1 month ago

OK, all done, and I have web access. Thanks once again for the quick response.

nebhead commented 1 month ago

So the next time the script runs (will be October 1st), we'll see if anything bad happens. For the time being, I'll keep this open.

jamiezorin commented 1 month ago

Just as a test I changed the cron to run at 30 21 * cd /usr/local/bin/garage-zero-v2/logs && sh backup.sh It worked flawlessly. The dragon is back in his cage, thanks again.

nebhead commented 1 month ago

Awesome, thank you! I've changed the install script and I'd say this issue is resolved.