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

Influx takes a while to start after an install or upgrade, which is why I created the loop to try for up to 5 minutes. However it seems your version of bash or influx isn't behaving properly with the for loop. To properly test the script, you'll have to get the PID from influx (ps aux | grep influx) and kill it (sudo kill -9 xxxx where xxxx is the PID), before running the test script.

I believe vi is the default editor, but I use vim (sudo apt-get install vim). Use the Insert key to start editing. Then Escape to exit insert mode. Then use the colon (:), then wq to write and quit the editor (:wq! to force write and quit).

Model76 commented 7 years ago

Sorry, my internet went out...

The script returned "success", and that was without killing influx. I will try it now with influx down.

Model76 commented 7 years ago

I tried killing influx, but wasn't able to. Not for long, anyway. Every time I killed it, it just came back up with a different PID, so something must be making sure it runs.

Anyway, I decided to try running the original install script again, and low and behold, it finished without any errors this time. Super strange, since that is the first and only time it has finished without errors, during these 3 separate install attempts, from scratch. It would be nice if we could at least have consistent errors, huh? ;-)

I still have the original failing log, is you are interested, and now I can also pull the log from the successful run. Let me know if you want them.

Do you have any idea what is causing this odd behavior? Are we sure influx is the culprit?

/Edit : I forgot to add that after the successful install script run, I was immediately able to access the web interface on the pi, without even rebooting.

kizniche commented 7 years ago

I tried killing influx, but wasn't able to. Not for long, anyway. Every time I killed it, it just came back up with a different PID, so something must be making sure it runs.

Yeah, I forgot to mention you should run the script immediately after killing influx. I also shortened the sleep to 5 seconds for my testing.

Anyway, I decided to try running the original install script again, and low and behold, it finished without any errors this time.

This is what I expected to happen when I asked you to rerun the setup.sh script. Once influxdb has started, the influx commands should work fine.

I still have the original failing log, is you are interested, and now I can also pull the log from the successful run. Let me know if you want them.

I don't think they'll be that useful, since I think we've narrowed the issue down to the loop.

Do you have any idea what is causing this odd behavior? Are we sure influx is the culprit?

I'm pretty sure the issue was influx returning the "connection refused". I'm still not sure why the loop isn't properly working for you but it is for me. I'm 99% sure the issue is the influx loop.

Here's my output from the test (after killing influx and with sleep at 5 seconds):

kiz@tnccave:~ $ ./test.sh 
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.
test 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.
test 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.
test 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.
test 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.
ghost commented 7 years ago

Thanks kizniche for you help. I have a similar problem and I have managed to solve it with several installs and repairs.

Looking forward for the fix.

kizniche commented 7 years ago

I don't really know what the issue for @Model76 and @rngkay installs are, as my bash for loop works as expected. I'll put some time this upcoming weekend (or sooner) to attempt to develop a more robust method to detect when influx has started to be able to properly connect and create the user/database.

If anyone has a suggestion, please let me know, but as of now I'm thinking I should put a loop that continually tries to connect to the influx port until it opens, rather than merely attempting to create the user/database to test the connection.

kizniche commented 7 years ago

I just tested installing Mycodo on a fresh Raspbian Lite image (6/21/2017) and was able to finally replicate the issue with the influxdb database/user creation error. I used curl to test the connection and it appears to work for me.

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
    # Check if influxdb has successfully started and be connected to
    curl -sL -I localhost:8086/ping > /dev/null &&
    influx -execute "CREATE DATABASE mycodo_db" &&
    influx -database mycodo_db -execute "CREATE USER mycodo WITH PASSWORD 'mmdu77sj3nIoiajjs'" &&
    printf "Influxdb database and user successfully created\n" &&
    break ||
    # Else wait 60 seconds if the influxd port is not accepting connections
    printf "Could not connect to Influxdb. Waiting 60 seconds then trying again...\n" &&
    sleep 60
done

I'm going to get one more thing added before making the release. I should have it out within the hour, and I believe that will close this issue.

kizniche commented 7 years ago

Release v5.0.36 should fix this issue.