Beau Trepp
Beau Trepp

Reputation: 2780

Capistrano appserver as service without sudo

Does anyone have a good way to manage the appserver with capistrano?. This seems to be a leave it to your own devices situation, and I've yet to see a good example of it.

There is basically two trains of thoughts I see.

1) Daemonize it as the deploy user. Pros, no system service etc, so no permissions issues. However this wreaks as if the machine is rebooted, blam the system goes down.

2) Init scripts. Installing a init script and using that to manage the server. This would survive reboots, and allow for say /etc/init.d/myapp restart/stop/start control if you ssh'd in. This is decent apart from two reasons

I'm experimenting with using nginx+unicorn. Nginx I have set perfectly. I've added a site to sites-available and pointed upstream to /appserver/public. This works great, asset precompilation works fantastic and all is well, I can redeploy and be served new assets. It's simple, works with the OS init process. However I've lucked out as the nginx config is basically static, and nginx only has to serve static files.

The appserver.. unicorn/thin/puma/ whatever is the part thats tripping me. I would like it to reload the application on cap deploy, but I'm struggling to find a good enough example of this.

In summary. What is a simple way of having a rails application survive reboots, and reload when cap deploy is called

Upvotes: 0

Views: 174

Answers (1)

Uri Agassi
Uri Agassi

Reputation: 37409

  1. If you use Passenger with your nginx and unicorn or thin... you can restart after deployment by touching tmp/restart.txt file:

    task :restart do
      on roles(:app), in: :sequence, wait: 5 do
        execute :touch, release_path.join('tmp/restart.txt')
      end
    end
    
  2. To reload a puma server after deploy use capistrano3-puma:

    Gemfile:

    gem 'capistrano3-puma'
    

    Capfile:

    require 'capistrano/puma'
    

Upvotes: 1

Related Questions