0

I'm currently new to Chef and Capistrano. I'm using version 3.x of Capistrano to deploy Rails 4 application.

I have successfully bootstrapped a server using chef solo. One cookbook that I'm using is Nginx.

Back to my simple Rails 4 app, I'm trying to run this command to check the status of my deployment:

cap production deploy:check

However, it throws some error:

DEBUG [05e580a4] Command: /usr/bin/env mkdir -pv /var/www/shared /var/www/releases
DEBUG [05e580a4]    mkdir: cannot create directory `/var/www': Permission denied
DEBUG [05e580a4]    mkdir: cannot create directory `/var/www': Permission denied

I'm using deploy user for Capistrano, and on my Chef node config, I speficied the deploy user. I can also logged in on my instance using deploy user.

Is there a proper way for me to address the permissions on Chef or in Capistrano?

2 Answers 2

1

The directory you intend to deploy to should already exist and have the correct ownership and permissions before you try to run Capistrano to deploy to it. So you need to handle that beforehand, probably in the same chef recipe where you created the user.

1

The directory above the base directory Capistrano is deploying to must be writable by the Capistrano user, because Capistrano normally creates that directory.

A style/convention note here. /var/www is not a great place to use as your app's base directory. On a number of OSes and distros, /var/www itself is created and managed by OS packages, and besides it being a little sloppy to put the typical Capistrano releases/current/shared directories there, its own permissions may get reverted if the webserver-related packages are upgraded or reinstalled. I suggest you add another layer to your directory structure, e.g.

/var/www/ruby_apps

And then in your chef recipe:

group 'deploy'

user 'deploy' do
  group 'deploy'
end

directory '/var/www/ruby_apps' do
  user 'deploy'
  group 'deploy'
end

Now let's say your app is called squishy.

In your Rails app's config/deploy.rb edit the :deploy_to line as follows:

set :deploy_to, '/var/www/ruby_apps/squishy'

..and now Capistrano will be able to create and maintain the squishy directory and everything under it, as well as any other apps you want to deploy beside it under ruby_apps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .