MDeLuise / plant-it

🪴 Self-hosted, open source gardening companion app
https://plant-it.org
GNU General Public License v3.0
455 stars 17 forks source link

Cannot connect to the backend #134

Closed econcepcion closed 3 months ago

econcepcion commented 4 months ago

Avoid duplicated bug reports

Description

I have used the configuration options in both of these examples.

https://docs.plant-it.org/installation/configurations/ as well as https://pimylifeup.com/raspberry-pi-plant-it/

The only change made to the configurations is on the IP. I use 192.168.1.120.

But I still get this error in both attempts.

I see a closed ticket that addressed this issue, but I still need help getting this to work.

Thanks

Expected behaviour

n/a

Steps to reproduce

n/a

Local environment

n/a

Additional info

n/a

MDeLuise commented 4 months ago

Hi @econcepcion, thanks for opening the issue. I didn’t know about the existence of the pimylifeup guide, so thanks for sharing it. I'm really glad to see someone wrote that.

Regarding your issue, could you please share:

econcepcion commented 4 months ago

ok last post was a mess.

I am attaching the files.

plantit-logs.csv frontend.csv backend.csv docker-compose.csv

MDeLuise commented 4 months ago

I tried your configuration on my machine and it seems to works as expected. In your log I'm seeing that the backend has some problem connecting to the db, maybe this could be the source of the issue.

| java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
...
Caused by: com.mysql.cj.exceptions.CJException: Access denied for user 'root'@'192.168.112.4' (using password: YES)

Could you please:

econcepcion commented 4 months ago

Here is ls -l

total 24 -rw-r--r-- 1 root root 437 Mar 2 18:23 backend.env drwxr-xr-x 2 root root 4096 Mar 1 04:11 certs drwxr-xr-x 9 systemd-coredump root 4096 Mar 2 18:31 db -rw-r--r-- 1 root root 766 Mar 2 18:31 docker-compose.yml -rw-r--r-- 1 root root 143 Mar 2 18:09 frontend.env drwxr-xr-x 2 root root 4096 Mar 1 04:11 upload-dir

deleted db folder and tried again. still same error.

econcepcion commented 4 months ago

Lol. Had to change password for db. I am in.

econcepcion commented 4 months ago

is there avideo that shows how to use? in particular the trefle integration?

MDeLuise commented 4 months ago

Glad to know that the problem is now fixed! 😁

Unfortunately there's no video tutorial yet, but if you have any question please ask without any problem.

For the Trefle integration:

econcepcion commented 4 months ago

I have done as you outlined above, but my search never yields results. I even went to Google to ensure I am typing plant names accurately..

small video. https://monosnap.com/file/Ayq4rm655Sxwbcw7QGbmUqGKJKw2wh

MDeLuise commented 4 months ago

Mh this is is strange, could you please:

itsnotrisky commented 4 months ago

Sort of similar as shown in the video - when I opened the search menu it's briefly showing 2 grey placeholder card then "timeout of 10000ms exceeded" popped up and only showing the Custom card. This is a new installation with TREFLE_KEY provided

Here's the backend container log

2024-03-03T10:28:28.805Z DEBUG 10 --- [io-8080-exec-10] c.g.m.p.systeminfo.SystemVersionService  : retrieve the system version info from GitHub.
2024-03-03T10:28:28.885Z DEBUG 10 --- [nio-8080-exec-7] c.g.mdeluise.plantit.plant.PlantService  : Search for DB saved plants
2024-03-03T10:28:35.372Z DEBUG 10 --- [io-8080-exec-10] c.g.m.p.p.PlantInfoExtractorFacade       : Search all botanical info
2024-03-03T10:28:35.372Z DEBUG 10 --- [io-8080-exec-10] c.g.m.p.b.BotanicalInfoService           : Search for DB saved botanical info (max size 5)
2024-03-03T10:28:35.376Z DEBUG 10 --- [io-8080-exec-10] c.g.m.p.p.trafle.TrefleRequestMaker      : Fetching all info from Trefle

And this is the log when I did a search and ended up timing out too

2024-03-03T10:31:14.043Z DEBUG 10 --- [io-8080-exec-10] c.g.m.p.p.PlantInfoExtractorFacade       : Extract botanical info matching montera (size 5)
2024-03-03T10:31:14.043Z DEBUG 10 --- [io-8080-exec-10] c.g.m.p.b.BotanicalInfoService           : Search for DB saved botanical info matching 'montera' scientific name (max size 5)
2024-03-03T10:31:14.046Z DEBUG 10 --- [io-8080-exec-10] c.g.m.p.p.trafle.TrefleRequestMaker      : Fetching info for "montera" from Trefle

Something I found with the backend connection, the request to /api/botanical-info returned fail but /api/info/ping was 200

MDeLuise commented 4 months ago

Do you guys still have the problem? If so, could you please provide the entire docker compose log?

econcepcion commented 4 months ago

I still have the issue, just havent been able to get back to testing. I will try tomorrow.

econcepcion commented 4 months ago

Ok, giving it another try tonite. Thanks

logs.csv

MDeLuise commented 4 months ago

Mh the log seems to be ok

econcepcion commented 4 months ago

When I curl, i get this back.

{"data":[{"id":136844,"common_name":"Christmastree","slug":"abies-alba","scientific_name":"Abies alba","year":1756,"bibliography":"Gard. Dict. ed. 7.: n.° 1 (1756)","author":"Mill.","status":"accepted","rank":"species","family_common_name":"Pine family","genus_id":7230,"image_url":"https://bs.plantnet.org/image/o/8e171a19f992a34d5d44693472320f6044a5d561","synonyms":["Abies taxifolia","Pinus heterophylla","Abies abies","Abies picea","Abies excelsa","Picea excelsa","Abies vulgaris","Abies pectinata var. columnaris","Abies excelsa var. chlorocarpa","Pinus baldensis","Peuce abies","Picea metensis","Abies pectinata var. pendula","Pinus picea f. columnaris","Abies alba f. columnaris","Abies duplex","Abies pectinata var. podolica","Picea rinzi","Abies candicans","Abies argentea","Abies alba var. aurea","Abies alba f. compacta","Pinus picea f. pendula","Abies alba f. pyramidalis","Picea kukunaria","Abies alba compacta","Pinus lucida","Abies pectinata f. pendula","Abies pardei subsp. pancicii","Abies pardei","Picea pectinata","Pinus pectinata","Picea tenuifolia","Abies alba var. brevifolia","Abies alba f. pendula","Abies alba var. pardei","Abies alba subsp. pardei","Abies alba var. columnaris","Picea pyramidalis","Abies alba var. compacta","Abies excelsa var. baldensis","Picea pectinata var. pendula","Pinus abies var. pectinata","Abies pectinata var. pyramidalis","Abies pectinata var. pendula-gracilis","Pinus picea f. pyramidalis","Abies alba subsp. apennina","Abies metensis","Abies alba var. glauca","Abies miniata","Abies tenuirifolia"],"genus":"Abies","family":"Pinaceae","links":{"self":"/api/v1/species/abies-alba","plant":"/api/v1/plants/abies-alba","genus":"/api/v1/genus/abies"}}],"links":{"self":"/api/v1/species/search?limit=1\u0026q=Abies+alba","first":"/api/v1/species/search?limit=1\u0026page=1\u0026q=Abies+alba","next":"/api/v1/species/search?limit=1\u0026page=2\u0026q=Abies+alba","last":"/api/v1/species/search?limit=1\u0026page=10\u0026q=Abies+alba"},"meta":{"total":10}}

econcepcion commented 4 months ago

I did not have LOG_LEVEL=DEBUG in backend. just added and restarted app and attached log file

logs-030724.csv

econcepcion commented 4 months ago

as I search, this is what comes up.

plantit-be | 2024-03-07T17:35:08.404Z DEBUG 13 --- [nio-8080-exec-3] c.g.m.p.p.PlantInfoExtractorFacade : Extract botanical info matching cactus (size 5) plantit-be | 2024-03-07T17:35:08.405Z DEBUG 13 --- [nio-8080-exec-3] c.g.m.p.b.BotanicalInfoService : Search for DB saved botanical info matching 'cactus' scientific name (max size 5) plantit-be | 2024-03-07T17:35:43.231Z DEBUG 13 --- [nio-8080-exec-6] c.g.m.p.p.PlantInfoExtractorFacade : Extract botanical info matching pine (size 5) plantit-be | 2024-03-07T17:35:43.231Z DEBUG 13 --- [nio-8080-exec-6] c.g.m.p.b.BotanicalInfoService : Search for DB saved botanical info matching 'pine' scientific name (max size 5)

MDeLuise commented 4 months ago

Everything seems to be corrected setup, this is really strange. I just check the deployment with the default README example with the addition of the TREFLE_KEY=my_value and everything works as expected.

In fact, in my log I have the following lines

...
2024-03-08 17:21:09 2024-03-08T16:21:09.455Z  WARN 10 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-03-08 17:21:10 2024-03-08T16:21:10.555Z  INFO 10 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/api'
2024-03-08 17:21:10 2024-03-08T16:21:10.562Z  INFO 10 --- [           main] c.github.mdeluise.plantit.Application    : Started Application in 5.645 seconds (process running for 5.935)
2024-03-08 17:21:10 2024-03-08T16:21:10.563Z  INFO 10 --- [           main] c.g.mdeluise.plantit.ApplicationConfig   : UPDATE_EXISTING flag set to false. Skipping update of existing species.
2024-03-08 17:21:15 2024-03-08T16:21:15.945Z DEBUG 10 --- [nio-8080-exec-3] c.g.m.p.systeminfo.SystemVersionService  : retrieve the system version info from GitHub.
2024-03-08 17:21:16 2024-03-08T16:21:16.010Z DEBUG 10 --- [nio-8080-exec-6] c.g.mdeluise.plantit.plant.PlantService  : Search for DB saved plants
2024-03-08 17:21:16 2024-03-08T16:21:16.574Z DEBUG 10 --- [nio-8080-exec-5] c.g.m.p.p.PlantInfoExtractorFacade       : Search all botanical info
2024-03-08 17:21:16 2024-03-08T16:21:16.574Z DEBUG 10 --- [nio-8080-exec-5] c.g.m.p.b.BotanicalInfoService           : Search for DB saved botanical info (max size 5)
2024-03-08 17:21:16 2024-03-08T16:21:16.580Z DEBUG 10 --- [nio-8080-exec-5] c.g.m.p.p.trafle.TrefleRequestMaker      : Fetching all info from Trefle
2024-03-08 17:22:28 2024-03-08T16:22:28.764Z DEBUG 10 --- [nio-8080-exec-3] c.g.m.p.p.PlantInfoExtractorFacade       : Extract botanical info matching a (size 5)
2024-03-08 17:22:28 2024-03-08T16:22:28.764Z DEBUG 10 --- [nio-8080-exec-3] c.g.m.p.b.BotanicalInfoService           : Search for DB saved botanical info matching 'a' scientific name (max size 5)
2024-03-08 17:22:28 2024-03-08T16:22:28.778Z DEBUG 10 --- [nio-8080-exec-3] c.g.m.p.p.trafle.TrefleRequestMaker      : Fetching info for "a" from Trefle

Specifically TrefleRequestMaker is printing logs so it's used.


I copy here the setup files, please double check that everything matches with your setup

#

JWT

# JWT_SECRET=putTheSecretHere JWT_EXP=1

#

Server config

# USERS_LIMIT=-1 UPLOAD_DIR=/upload-dir API_PORT=8080 TREFLE_KEY=my_key ALLOWED_ORIGINS=* LOG_LEVEL=DEBUG UPDATE_EXISTING=false

#

Cache

# CACHE_TTL=86400 CACHE_HOST=cache CACHE_PORT=6379

#

SSL

# SSL_ENABLED=false CERTIFICATE_PATH=/certificates/


* `frontend.env`

PORT=3000 API_URL=http://localhost:8080/api WAIT_TIMEOUT=10000 CACHE_TTL_DAYS=7 BROWSER=none SSL_ENABLED=false CERTIFICATE_PATH=/certificates/



<hr/> 

If so, please open the network tab of the browser and check if the request is correctly send when you try to search some plants.
<img src="https://github.com/MDeLuise/plant-it/assets/66636702/9b47194f-7ff9-4bf9-a45f-90b2dfb7d9fd" width="100%" />
econcepcion commented 4 months ago

Here are my files. Just made minor changes... added container_name and change restart to unless-stopped.

version: "3"
services:
  backend:
    image: msdeluise/plant-it-backend:latest
    container_name: plantit-be
    env_file: backend.env
    depends_on:
      - db
      - cache
    restart: unless-stopped
    volumes:
      - "./upload-dir:/upload-dir"
      - "./certs:/certificates"
    ports:
      - "8089:8080"
  db:
    image: mysql:8.0
    restart: unless-stopped
    container_name: plantit-db
    env_file: backend.env
    volumes:
      - "./db:/var/lib/mysql"
  cache:
    image: redis:7.2.1
    restart: unless-stopped
    container_name: plantit-cache
  frontend:
    image: msdeluise/plant-it-frontend:latest
    env_file: frontend.env
    container_name: planit
    links:
      - backend
    ports:
      - "3009:3000"
    volumes:
      - "./certs:/certificates"
volumes:
  certs:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ./certificates

#
# DB
#
MYSQL_HOST=db
MYSQL_PORT=3306
MYSQL_USERNAME=root
MYSQL_PSW=[mypassword]
MYSQL_ROOT_PASSWORD=[mypassword]
MYSQL_DATABASE=bootdb

#
# JWT
#
JWT_SECRET=[my secret]
JWT_EXP=1

#
# Server config
#
USERS_LIMIT=10
UPLOAD_DIR=/upload-dir
API_PORT=8080
TRAFLE_KEY=[my key]
ALLOWED_ORIGINS=*
LOG_LEVEL=DEBUG

#
# Cache
#
CACHE_TTL=86400
CACHE_HOST=cache
CACHE_PORT=6379

#
# SSL
#
SSL_ENABLED=false
CERTIFICATE_PATH=/certificates/

Frontend

PORT=3000
API_URL=http://192.168.1.120:8089/api
WAIT_TIMEOUT=5000
PAGE_SIZE=25
BROWSER=none
SSL_ENABLED=false
CERTIFICATE_PATH=/certificates/

SCR-20240308-kpyk

MDeLuise commented 4 months ago

Did you use TRAFLE_KEY= or TREFLE_KEY= in the backend.env file? Because from your file I'm seeing the parameter with a A instead of an E

econcepcion commented 4 months ago

OMG!!!!! Idiot moment. Working Now. Thanks for helping me figure this out.

MDeLuise commented 4 months ago

Really happy to know that now works fine! Initially I made the same error 😂

So thanks for opening the issue and happy planting 🪴

econcepcion commented 4 months ago

I'll be sharing this with my family. My son will love this. Thank you again for taking time to walk me thru this and for such great project.

MDeLuise commented 4 months ago

Thank you for using and sharing the project! Your support means really a lot As mentioned here, I'm currently focused on developing a standalone app, this will simplify the deployment and enhance a lot the user experience

econcepcion commented 4 months ago

Different Question. Dont know if you have looked at this. Have you had any experience using Cloudflare tunnels to allow access outside of your home network?

MDeLuise commented 4 months ago

I haven't personally used Cloudflare tunnels, but they should work without any problem. There was a discussion about them opened by a user some time ago, which might have some helpful insights for you.

nykroy commented 3 months ago

After update to the last stable versión of backend 0.4.3 the backend IS rebooting constantly _plant-it-backend-1_logs (4).txt

I only update the stack

MDeLuise commented 3 months ago

After update to the last stable versión of backend 0.4.3 the backend IS rebooting constantly _plant-it-backend-1_logs (4).txt I only update the stack

Hi, Thanks for bringing this to my attention. After investigating the issue, it seems that the problem may be related to recent updates to the backend and changes in the database schema files. I apologize for any inconvenience this has caused. To resolve the issue, please follow these steps:

  1. Backup Database Files: Before proceeding, it's important to save a copy of the db folder to ensure that you can rollback the process if needed.

  2. Execute SQL Command: From the shell, run the following command to remove all entries from the databaseChangeLog table:

    docker exec <db_container_name> mysql -u<db_user> -p<db_password> -e "USE bootdb; DELETE FROM databaseChangeLog;"

    For example, if you're using the default backend.env file, the command would be:

    docker exec plant-it-db-1 mysql -uroot -proot -e "USE bootdb; DELETE FROM databaseChangeLog;"
  3. Redeploy Docker Compose: Once the SQL command has been executed, redeploy the Docker Compose stack if necessary.

Please let me know if this resolves the issue. Appreciate your patience.

nykroy commented 3 months ago

Not working: docker exec plant-it-db-1 mysql -uroot -proot -e "USE bootdb; DELETE FROM databaseChangeLog;" mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1146 (42S02) at line 1: Table 'bootdb.databaseChangeLog' doesn't exist

MDeLuise commented 3 months ago

This is strange, are you using the mysql:8.0 image as in the docker-compose.yml quickstart section? What's the output of docker exec plant-it-db-1 mysql -uroot -proot -e "USE bootdb; show tables;"?

Also please try to run docker exec plant-it-db-1 mysql -uroot -proot -e "USE bootdb; DELETE FROM DATABASECHANGELOG;", in some unix environment table names are case sensitive.

nykroy commented 3 months ago

Thisis strange, are you using the mysql:8.0 image as in the docker-compose.yml [quickstart](https://github.com/MDeLuise/plant-it?tab=readme-ov-file#quickstart) section? Yes What's the output of docker exec plant-it-db-1 mysql -uroot -proot -e "USE bootdb; show tables;"? Screenshot_20240315-200817 Also please try to run docker exec plant-it-db-1 mysql -uroot -proot -e "USE bootdb; DELETE FROM DATABASECHANGELOG;", in some unix environment table names are case sensitive. Screenshot_20240315-201249

Then i Redeploy Docker Compose but the problem persist _plant-it-backend-1_logs (5).txt

MDeLuise commented 3 months ago

Small progress, now it seems to have another problem and not the one we had previously. Please try to run this

docker exec plant-it-db-1 mysql -uroot -proot -e "DELETE FROM bootdb.DATABASECHANGELOG; INSERT INTO bootdb.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, EXECTYPE, MD5SUM, DESCRIPTION, COMMENTS, TAG, LIQUIBASE, CONTEXTS, LABELS, DEPLOYMENT_ID) VALUES ('addExternalIdUniqueConstraintIfNotExists', 'MDeLuise', 'dblogs/changelog/changes/v1-0-0.xml', '2024-03-16 07:18:12', 16, 'MARK_RAN', '9:edd5ef47cce94adb632f57b7a6ed3729', 'addUniqueConstraint constraintName=botanical_info_external_id_unique, tableName=botanical_infos', NULL, '4.26.0', NULL, NULL, NULL, '0573491549');"

This should

I have to investigate why is failing on your deployment but that check should not be strictly needed.

nykroy commented 3 months ago

Now It is working!!! Thank you!!! I add another log for debug the problem If you needed it _plant-it-backend-1_logs (6).txt

MDeLuise commented 3 months ago

Thank you for bringing up the issue and provide the new log!