504 Gateway Timeout after memory resizing

Posted June 8, 2020 1.8k views
Ruby on RailsNginx

I have a droplet with a rails 5 app working fine. After a deployment I got errors when installing gems and I realized that I had to increase memory.

I had 1Gb and resized to 2Gb.
After resize from 1Gb to 2Gb of memory I got this error (504 Gateway Timeout).

Before resizing I poweroff from terminal, all fine, but I did not:
service nginx stop
service unicorn stop
service postgresql stop
Maybe, is this the problem?

Now all 3 services are working fine, but I still get the 504 Gateway Timeout error.

Also, now when In run cap production deploy it hangs out when installing gems

I’m absolutely lost, and any help will be appreciated.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @Casulleres,

It seems like the services Nginx, Unicorn, PostgresSQL didn’t start properly. To check this SSH to your droplet,

ssh root@YourDropletIp

Once you are in see if everything is running on the needed ports:

netstat -tulpen

Now, if something doesn’t work right, I’ll recommend trying to restart them like so

service nginx restart
service unicron restart
service postgresql restart

Once this has been done the websites should be running as expected.


  • Hi, thank you for your response!

    First of all, let me say that I’ve reverted the gem changes (new gem and gem updates) that made me resize the memory, so now, the code is as it was last week when everything worked fine.

    I’ve keeped a pair of commented lines at the end of /etc/defaul/unicorn:

    export SECRET_KEY_BASE=452342....61f9
    export APP_DATABASE_PASSWORD=.......
    #export RECAPTCHA_SITE_KEY=6L...d3r

    When I run netstat -tulpen I get:

    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name    
    tcp        0      0*               LISTEN      106        22254      -                   
    tcp        0      0    *               LISTEN      0          877289     -                   
    tcp        0      0 *               LISTEN      109        14053      -                   
    tcp        0      0    *               LISTEN      0          21214      -                   
    tcp6       0      0 :::22                   :::*                    LISTEN      0          21414      -                   
    udp        0      0 *                           109        14052      -  

    Is this ok?

    all 3 services are restarted and their status in green:

    rails@forjartistica:~/www/digitalshelving/current$ service nginx status
    ● nginx.service - A high performance web server and a reverse proxy server
       Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
       Active: active (running) since Tue 2020-06-09 12:06:24 EDT; 56s ago
         Docs: man:nginx(8)
      Process: 9683 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/ (code=exited, status=0/SUCCESS)
      Process: 9685 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
      Process: 9684 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
     Main PID: 9686 (nginx)
        Tasks: 2 (limit: 2339)
       CGroup: /system.slice/nginx.service
               ├─9686 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
               └─9687 nginx: worker process
    rails@forjartistica:~/www/digitalshelving/current$ service unicorn status
    ● unicorn.service - LSB: unicorn initscript
       Loaded: loaded (/etc/init.d/unicorn; generated)
       Active: active (running) since Tue 2020-06-09 12:06:14 EDT; 1min 12s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 9506 ExecStop=/etc/init.d/unicorn stop (code=exited, status=0/SUCCESS)
      Process: 2386 ExecReload=/etc/init.d/unicorn reload (code=exited, status=0/SUCCESS)
      Process: 9511 ExecStart=/etc/init.d/unicorn start (code=exited, status=0/SUCCESS)
        Tasks: 10 (limit: 2339)
       CGroup: /system.slice/unicorn.service
               ├─ 9547 unicorn master -D -c /etc/unicorn.conf -E production
               ├─10395 unicorn worker[3] -D -c /etc/unicorn.conf -E production
               ├─10398 unicorn worker[0] -D -c /etc/unicorn.conf -E production
               ├─10400 unicorn worker[1] -D -c /etc/unicorn.conf -E production
               └─10404 unicorn worker[2] -D -c /etc/unicorn.conf -E production
    rails@forjartistica:~/www/digitalshelving/current$ service postgres status
    Unit postgres.service could not be found.
    rails@forjartistica:~/www/digitalshelving/current$ service postgresql status
    ● postgresql.service - PostgreSQL RDBMS
       Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
       Active: active (exited) since Tue 2020-06-09 12:05:50 EDT; 1min 48s ago
      Process: 9491 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
     Main PID: 9491 (code=exited, status=0/SUCCESS)
    • I can see in unicorn.log some errors:

      INFO -- : Refreshing Gem list
      /home/rails/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/runtime.rb:312:in `check_for_activated_spec!': You have already activated rack 2.2.2, but your Gemfile requires rack 2.0.8. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

      let me investigate, thanks and excuse the inconveniences

      • Solved!!
        During the last deploy rack was upgraded and in the revert of the last commit not correctly reverted.

        It is not related with resizing the memory of the droplet

        If the administrators think convenient, I can remove this post

        • I’m glad to hear you managed to solve the issue!

          No need to remove the post, it might prove beneficial to someone!