basecamp / kamal

Deploy web apps anywhere.
https://kamal-deploy.org
MIT License
9.41k stars 362 forks source link

Display the error why a rails server is not starting during `kamal setup` #743

Closed serv closed 2 months ago

serv commented 3 months ago

Hi Kamal team,

When I ran kamal setup, I got the message saying the healthcheck has failed.

 ERROR {
  "Status": "unhealthy",
  "FailingStreak": 27,
  "Log": [
    {
      "Start": "2024-03-25T06:10:57.057607108Z",
      "End": "2024-03-25T06:10:57.150344418Z",
      "ExitCode": 1,
      "Output": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (7) Failed to connect to localhost port 3000 after 3 ms: Couldn't connect to server\n"
    },

This is too generic and unactionable. A more helpful error should not only show that health check has failed, but why the health check failed by displaying the error message that would've printed, if you ran ./bin/rails s locally.

I was able to dubug what the real issue is by running the command to manually start the docker app image like:

docker run --detach --name healthcheck-kamal-rails-pg-tutorial-ccc7f8046c5feaa21e3cd52b9c69fed49dbd413c_uncommitted_ba1a020121f126ac --publish 3999:3000 --label service=healthcheck-kamal-rails-pg-tutorial -e KAMAL_CONTAINER_NAME="healthcheck-kamal-rails-pg-tutorial" --env-file .kamal/env/roles/kamal-rails-pg-tutorial-web.env azuretutorials.azurecr.io/serv/kamal-rails-pg-tutorial:ccc7f8046c5feaa21e3cd52b9c69fed49dbd413c_uncommitted_ba1a020121f126ac

djmb commented 2 months ago

@serv - before the failed healthcheck message you've posted, you should have the output from the container logs. See https://github.com/basecamp/kamal/blob/67a86e1068d312b80726890805328d0958609534/lib/kamal/cli/healthcheck.rb#L12.

Did you see anything there?