Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I gracefully restart thin + nginx?

I have my Thin servers configured with nginx and my ROR app is running on them.

Running thin restart when I release an update to my code introduces some downtime to my application. I was trying to figure how to gracefully restart the running Thin instances but I could not find a good solution.

Has anyone been able to achieve this?

like image 988
Lester Celestial Avatar asked Jul 25 '12 20:07

Lester Celestial


People also ask

When should I restart Nginx?

Restart Nginx only when making significant configuration updates, such as changing ports or interfaces. This command will force shut down all worker processes.


1 Answers

# Restart just the thin server described by that config
sudo thin -C /etc/thin/mysite.yml restart 

Nginx will continue running and proxying requests. If you have your Nginx set to use multiple upstream servers, e.g.

server {
  listen        80;
  server_name  myapp.mysite.com;
  # ...
  location / {
    try_files $uri $uri/index.html /cache$uri.html $uri.html @proxy;
  }
  location @proxy {
    proxy_pass http://myapp.rails;
  }
}

upstream myapp.rails {
   server 127.0.0.1:9001 max_fails=1 fail_timeout=10s;
   server 127.0.0.1:9002 max_fails=1 fail_timeout=10s;
   server 127.0.0.1:9003 max_fails=1 fail_timeout=10s;
}

…then each instance will be restarted in turn and Nginx will automatically route requests around one of the proxies if it's down.

like image 55
Phrogz Avatar answered Oct 08 '22 20:10

Phrogz