kizniche / Mycodo

An environmental monitoring and regulation system
http://kylegabriel.com/projects/
GNU General Public License v3.0
2.95k stars 494 forks source link

An error occurred that prevented Mycodo from being installed #255

Closed Model76 closed 7 years ago

Model76 commented 7 years ago

Mycodo Issue Report:

Problem Description

Please list:

Errors

I have isolated 2 errors in ~/Mycodo/install/setup.log : 1:

#### Creating InfluxDB database and user
Failed to connect to http://localhost:8086: Get http://localhost:8086/ping: dial tcp [::1]:8086: getsockopt: connection refused
Please check your connection settings and ensure 'influxd' is running.

And 2, at the end of the log :

#### Starting the Mycodo daemon and web server
Restarting apache2 (via systemctl): apache2.service.

*******************************
*** ERROR: Install Aborted! ***
*******************************

An error occurred that prevented Mycodo from being installed!

Please contact the developer by submitting a bug report at
https://github.com/kizniche/Mycodo/issues with the pertinent
excerpts from the setup log located at Mycodo/install/setup.log

An error occurred. Exiting... 

Steps to Reproduce the issue:

How can this issue be reproduced?

Follow the installation instructions at https://github.com/kizniche/Mycodo/. The only step I had added was setting the correct keyboard layout in raspi-config.

Additional Notes

I will now try installing again with an older version of raspian (2016-11-25-raspbian-jessie-lite) that I have laying around from when I successfully installed Mycodo last year. I'll report back if that solves it.

kizniche commented 7 years ago

Did influxdb install properly during the setup?

Model76 commented 7 years ago

It did say "Incorrect version of influxDB" when it was checking for the correct version, but then it also said it was installing another version. No error or failing was mentioned at this point in the log, so I can only assume that all went well.

Model76 commented 7 years ago

OK, I just finished trying to install on 2016-11-25-raspbian-jessie-lite and that failed, too. What can I do to help you fix this?

kizniche commented 7 years ago

What version Pi is it? I suspect that influxdb didn't have enough time to start before the connection to create the user/database was attempted. You can just rerun the setup.sh script to see if it can finish, now that influxdb has probably started.

Model76 commented 7 years ago

It's a version 3

Model76 commented 7 years ago

I re-ran setup.sh (with sudo /bin/bash ./setup.sh) and am still getting an error after Restarting apache2....

kizniche commented 7 years ago

Did influxdb start without errors after it was installed?

Do you have any errors restarting it? sudo service influxdb restart

Can you connect to influxdb from the terminal? influx

kizniche commented 7 years ago

Strange issue.

Do you have any peripherals attached to your Pi?

Do you have another Pi to test?

Do you have another SD card to test?

kizniche commented 7 years ago

So the web server is not starting as well? That means when you go to https://your.Pi.IP.address/ it doesn't connect?

Model76 commented 7 years ago

If I try to connect to the pi via browser, I get an Internal Server Error.

sudo service influxdb restart returns immediately without any messages. I suppose that is the expected behavior?

Can you connect to influxdb from the terminal?

How can I test this? I use the terminal as little as possible...

kizniche commented 7 years ago

just type influx into the terminal.

kizniche commented 7 years ago

And just to be sure, this is how you're executing setup.sh, correct?

sudo /bin/bash ./setup.sh

Model76 commented 7 years ago

That is correct.

influx says "Connected to http://localhost:8086 version 1.2.4" so seems fine to me.

kizniche commented 7 years ago

try adding the user and database manually:

influx -execute "CREATE DATABASE mycodo_db"

influx -database mycodo_db -execute "CREATE USER mycodo WITH PASSWORD 'mmdu77sj3nIoiajjs'"

kizniche commented 7 years ago

Then restart your Pi and everything should work

kizniche commented 7 years ago

This is the code for configuring influxdb, from setup.sh:

printf "\n#### Creating InfluxDB database and user\n"
# Attempt to connect to influxdb 5 times, sleeping 60 seconds every fail
for i in {1..5}; do
influx -execute "CREATE DATABASE mycodo_db" &&
influx -database mycodo_db -execute "CREATE USER mycodo WITH PASSWORD 'mmdu77sj3nIoiajjs'" &&
break || sleep 60; done

This should have attempted to execute the commands 5 times, with 60 seconds between attempts. Your log shows only attempting once. Can you paste the output of /bin/bash --version for me?

Model76 commented 7 years ago

I am afraid it doesn't, though.

As for other Pi's to test with, I have a Pi 1 with sd card, and another Pi 3, but no other sd card for that.

kizniche commented 7 years ago

What is indicating to you it isn't working?

Model76 commented 7 years ago

I still get Internal Server Error when I try to connect via browser.

The version of bash is 4.3.30(1)-release

kizniche commented 7 years ago

Do this to start the HTTP server in debug mode to get a detailed error:

sudo /etc/init.d/apache2 stop
sudo ~/Mycodo/env/bin/python ~/Mycodo/mycodo/start_flask_ui.py -d

Then go to the Pi web address and paste the error.

kizniche commented 7 years ago

I have to leave for an appointment, but I'll be back later to help diagnose the issue further.

Model76 commented 7 years ago

OK, thank you. I also have an appointment later, and will return after that.

Now I am getting Unable to connect - so it seems the apache server is not back up... Or is there a particular port other than 80 I should use for debugging?

kizniche commented 7 years ago

Debugging should still be using SSL, so https. Is there any output in the terminal when you run start_flask_ui.py?

Model76 commented 7 years ago

Yes, I get: Running on https://0.0.0.0:443/ Restarting with stat Debugger is active! And then a debugger PIN that you probably don't care about.

kizniche commented 7 years ago

That's indicating the server is running in debug mode, so you should be able to connect with your web browser.

Model76 commented 7 years ago

Yeah, but that was when I got "Unable to connect".

kizniche commented 7 years ago

Do you happen to have a monitor/keyboard connected to your Pi that you can log into its GUI and open the web browser to https://127.0.0.1?

Model76 commented 7 years ago

Yes, except I installed the lite version of Raspbian. Do you happen to know a package I can install to easily get the desktop on there?

kizniche commented 7 years ago

sudo apt-get install xfce4 lightdm should install all the prerequisites to login to xfce.

Model76 commented 7 years ago

Wait... It magically works now! What the hell???

kizniche commented 7 years ago

Good to hear. Did you do anything in the meantime that would have affected anything?

Model76 commented 7 years ago

Maybe I had to power the pi completely down and not just reboot for some reason? I did absolutely nothing besides turn the Pi off for 6 hours. So odd.

kizniche commented 7 years ago

I still have no idea why you had an issue installing. I guess I'll just have to wait and see if anyone else has any issues during install.

Model76 commented 7 years ago

Well, I unplugged the and reinserted the keyboard when it was off, but that REALLY shouldn't matter...

I don't mind starting all over again to see if we can localize the error. Would you like that?

kizniche commented 7 years ago

I'm not really sure how to even begin diagnosing this issue. It appears that the for loop in the bash script wasn't working properly. It should have attempted to create the user/database 5 times with 60 seconds between attempts. It appears it didn't do this, and just exited the for loop at the first error. Let me research bash/for before suggesting you should overwrite a working setup.

kizniche commented 7 years ago

Was this the entire error:

#### Creating InfluxDB database and user
Failed to connect to http://localhost:8086: Get http://localhost:8086/ping: dial tcp [::1]:8086: getsockopt: connection refused
Please check your connection settings and ensure 'influxd' is running.

before showing this?

#### Installing and configuring apache2 web server
Model76 commented 7 years ago

Just give me the word, I'd like to contribute what little I can. I am a developer, too, so I understand how helpful it can be to have someone test for you.

Model76 commented 7 years ago

The log seems to have been overwritten the second time I ran the setup script. My offer still stands. I will gladly run through the procedure one more time.

Model76 commented 7 years ago

To clarify: There seemingly was no failure with influxDB the second time the script was run.

It still said


*******************************
*** ERROR: Install Aborted! ***
*******************************

An error occurred that prevented Mycodo from being installed!

at the end of the script, though.

Model76 commented 7 years ago

I had a look at your for loop, and it did look a little strange to me. Bear in mind that I am not at all a bash person, and actually never looked at it before today, but shouldn't the loop look more like this:

for i in {1..5}; do
 if [influx -execute "CREATE DATABASE mycodo_db" && influx -database mycodo_db -execute "CREATE USER mycodo WITH PASSWORD 'mmdu77sj3nIoiajjs'"]
 then
  break
 fi
 sleep 60
done

Please bear with me if I am completely wrong...

kizniche commented 7 years ago

The log seems to have been overwritten the second time I ran the setup script.

It should append the log, and not overwrite. I'll correct that in the next release.

There seemingly was no failure with influxDB the second time the script was run

Yeah, I'm trying to figure this out as well. That error should stop the install script wherever the error occurs. So, it seems it's happening on one of these three commands:

printf "\n#### Starting the Mycodo daemon and web server\n"
/etc/init.d/apache2 restart
wget --quiet --no-check-certificate -p http://127.0.0.1 -O /dev/null
service mycodo start
kizniche commented 7 years ago

shouldn't the loop look more like this

There are probably a number of ways to do it, but what's there now is what I've tested to work. Perhaps influxdb changed the exit code for an inability to connect.

kizniche commented 7 years ago

I believe this is where I got the bash loop solution.

Model76 commented 7 years ago

Oh, yes, I see how it is supposed to work now. A bit hacky to use the order of operations like that if you ask me, but hey, I come from C++.

So the assumptions in this code are as follows: 1: Each command will evaluate to true on success or false on failure.

2: The second command will always succeed when run in rapid succession of the first command OR the first command can succeed more than once and the second command can succeed when run in rapid succession of the first command.

Are those true?

kizniche commented 7 years ago

Yes, if the first command succeeds, the && will allow the next to be executed. If the first command succeeds, the second command should succeed. If the second command succeeds, the break will be executed, leaving the loop. If any command before the break fails, then sleep 60 will be executed and the loop will run again.

kizniche commented 7 years ago

I'm open to changing the code to something that works better. I just haven't put much effort into testing to notice any situation where it would fail. I'll stop influx and run some tests with this loop isolated.

kizniche commented 7 years ago

My test was successful when influx wasn't running and the command returned "connection refused", in that it waited and tried again. I suspect for some reason your influx didn't start. Why? I haven't a clue.

Model76 commented 7 years ago

Well, I couldn't leave it alone and just reinstalled the system a third time. I am still getting the same errors. On the up-side I now have a complete install log. Here is the influx part you were asking about earlier:

#### Ensuring compatible version of influxdb is installed ####
Incorrect version of InfluxDB installed: v. Installing 1.2.4-1
Selecting previously unselected package influxdb.
(Reading database ... 46730 files and directories currently installed.)
Preparing to unpack influxdb_1.2.4_armhf.deb ...
Unpacking influxdb (1.2.4-1) ...
Setting up influxdb (1.2.4-1) ...
Created symlink from /etc/systemd/system/influxd.service to /lib/systemd/system/influxdb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/influxdb.service to /lib/systemd/system/influxdb.service.
Processing triggers for man-db (2.7.0.2-5) ...

#### Creating InfluxDB database and user
Failed to connect to http://localhost:8086: Get http://localhost:8086/ping: dial tcp [::1]:8086: getsockopt: connection refused
Please check your connection settings and ensure 'influxd' is running.

#### Installing and configuring apache2 web server

Is there anything else you would like to see?

kizniche commented 7 years ago

Strange. Can you create a file with just this in it:

#!/bin/bash
for i in {1..5}; do
influx -execute "CREATE DATABASE mycodo_db" &&
influx -database mycodo_db -execute "CREATE USER mycodo WITH PASSWORD 'mmdu77sj3nIoiajjs'" &&
printf "success" &&
break || sleep 60; done

then make it executable and execute it...

chmod +x test.sh
./test.sh
Model76 commented 7 years ago

Sure. What is the name of the command line text editor on the Pi, do you know?

Also, influx is running, I just checked.

Edit - I found nano