Skip to content

fm start Fails to Start Nginx #314

@lukastom

Description

@lukastom

Describe the bug
After short time of using Frappe Manager, I have always this error: when I run fm start (app name):

  • Nginx starts
  • It tries to locate Mailpit (in admin-tools.conf) but silently fails because Mailpit does not run yet so it can not be reached
  • Mailpit starts
  • Nginx stops (after like 1 second) because it did not locate Mailpit successfully
  • the result is that everything looks OK but myapp.localhost does not run, it shows an error. In docker Desktop, we see that fm__mypp_localhost__nginx is not running. We can simply start it (docker start fm__myapp_localhost__nginx) and everything works after that.
  • in Nginx logs, there is nginx: [emerg] host not found in upstream "fm__firstapp_localhost__mailpit" in /etc/nginx/custom/admin-tools.conf:8
  • as a test, if we disable Admin Tools, everything is OK, if we enable it, Nginx keeps stopping
  • fm services restart does not help, fmx status does not see any problem
  • the problem is visible in fm info testapp

To Reproduce
Steps to reproduce the behavior:

  1. Create a new project with FM using fm create testapp --environment dev
  2. Couple of times, start it and stop it, here are my commands:
  3. fm stop testapp.localhost
  4. fm start testapp.localhost
  5. fm stop testapp.localhost
  6. fm start testapp
  7. fm stop testapp
  8. fm start testapp (at this point, testapp.localhost does not work in the browser, there is an error 503 Service Temporarily Unavailable / nginx)
  9. fm info testapp shows Status: Inactive, nginx not running.
  10. (I am mixing testapp and testapp.localhost in my commands, not sure if it has any relevance, maybe it is breaking it?)

Expected behavior
Mailpit must start before Nginx, so nginx can see it or there must be another solution.

System information (please complete the following information):

  • I am running it inside WMS on Windows + using Docker Desktop
  • [0.18.0] fm --version
  • [Ubuntu 24.04.3 LTS ] lsb_release -a
  • [Client v: 28.5.1, Docker Desktop 4.48.0] docker version
  • [ v2.40.0-desktop.1] docker-compose version or docker compose version

Attach log
fm.log

Additional context
The solution seems to be to have this code in frappe\sites\firstapp.localhost\configs\nginx\conf\custom\admin-tools.conf:

# DNS resolver – in Docker normally 127.0.0.11
resolver 127.0.0.11 ipv6=off;

# Upstream hostnames to variables – this makes NGINX resolve DNS during it runs
set $mailpit_upstream  fm__firstapp_localhost__mailpit;
set $adminer_upstream fm__firstapp_localhost__adminer;

# Mailpit
location ^~ /mailpit/ {
    auth_basic "Frappe-Manager Admin Tools";
    auth_basic_user_file /etc/nginx/http_auth/firstapp.localhost-admin-tools.htpasswd;
    
    chunked_transfer_encoding on;
    proxy_set_header X-NginX-Proxy true;

    # hostname in variable
    proxy_pass http://$mailpit_upstream:8025/mailpit/;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_redirect off;
    proxy_buffering off;
}

# Adminer
location ^~ /adminer/ {
    auth_basic "Frappe-Manager Admin Tools";
    auth_basic_user_file /etc/nginx/http_auth/firstapp.localhost-admin-tools.htpasswd;
    
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $host;

    # hostname in variable
    proxy_pass http://$adminer_upstream:8080/;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions