Permission denied after deploy app with capistrano - ruby

I have a deploy.rblike this
set :application, "api"
set :repository, "git#github.com/org/api.git"
default_run_options[:pty] = true
set :scm_passphrase, "passwd"
set :scm, :git
set :user, "deploy"
set :use_sudo, false
set :deploy_to, "/var/www"
set :deploy_via, :remote_cache
role :web, "192.168.0.95" # Your HTTP server, Apache/etc
role :app, "192.168.0.95" # This may be the same as your `Web` server
role :db, "192.168.0.95", :primary => true # This is where Rails migrations will run
role :db, "192.168.0.95"
as you can see, I'm doing a deploy to our intranet...
After this, I executed bundle exec foreman start on our server and when I access the app, i see this:
Permission denied - /var/www/releases/20120719190900/tmp/cache
I tried to chmod and chown our www folder, but nothing changed...
What am I missing here?
Thanks

Can you try set :use_sudo, true instead of false?

I've just created the folder cache inside tmp folder and it worked! Strange thing...

Related

Error creating a database with Chef using database cookbook

I'm provisioning a Vagrant bento/centos6.7 box using chef_solo provisioner. I'm using berkshelf-plugin for the cookbook dependencies.
My project folder looks like this:
|── Vagrantfile
|── cookbooks
└── my_cookbook
|── Berksfile
|── metadata.rb
...
Inside my Vagrantfile (which is the default for bento/centos6.7 plus the following config)
config.berkshelf.enabled = true
config.berkshelf.berksfile_path = "cookbooks/my_cookbook/Berksfile"
config.vm.provision "chef_solo" do |chef|
chef.add_recipe "my_cookbook"
end
In my metadata.rb
depends 'mysql2_chef_gem', '~> 1.1'
depends 'database', '~> 5.1'
When I provision my vagrant machine, I get the following error:
Error executing action `create` on resource 'mysql_database[my_database]'
Mysql2::Error
-------------
Lost connection to MySQL server at 'reading initial communication packet', system error: 110
PS: it works perfectly on bento/centos7.2
EDIT: Here is the database creation part:
# Install the MySQL client
mysql_client 'default' do
action :create
end
# Configure the MySQL service
mysql_service 'default' do
initial_root_password node['webserver']['database']['root_password']
action [:create, :start]
end
# Install the mysql2 Ruby gem
mysql2_chef_gem 'default' do
action :install
end
mysql_database node['webserver']['database']['db_name'] do
connection(
:host => node['webserver']['database']['host'],
:username => node['webserver']['database']['root_username'],
:password => node['webserver']['database']['root_password']
)
action :create
end
EDIT 2: It doesn't really work on bento/centos7.2. It doesn't crash, but MySQL seems to be dead and running sudo systemctl start mysqld hangs.
I was over suggestion by the fact that I was using many new things (I'm also new to Chef) so I thought the problem came from a different source (vagrant, bad bersfile integration, something else).
Turns out I just didn't read the docs which clearly states:
Logging into the machine and typing mysql with no extra arguments will fail. You need to explicitly connect over the socket with mysql -S /var/run/mysql-foo/mysqld.sock, or over the network with mysql -h 127.0.0.1

capistrano3 permission denied (using proxy)

I'm trying to migrate my capistrano v2 script to the new v3.4 version.
All went well with development stage: I have one EC2 instance, and the deploy completed without errors.
I'm having some troubles with my production script, because I've got a proxy (EC2 instance) before my production servers (EC2 instances too); in my capistrano v2 script all was working, now I'm using cap-ec2 + capistrano v3.4 to deploy my application only to tagged servers, but when I try it I get "Permission Denied", my production servers refuse my key.
Maybe I've set something wrong with proxy parameters in my script, can you please help me?
Thanks a lot!!
Here you can find proxy parameters:
CAPISTRANO V2 (working)
set :gateway, "deploy#xxx.xxx.xxx.xxx"
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
ssh_options[:port] = "22"
ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa_deploy_myapp")]
CAPISTRANO V3 (not working)
require 'net/ssh/proxy/command'
set :ssh_options, {
user: "deploy",
keys: %w("~/.ssh/id_rsa_deploy_myapp"),
auth_methods: %w(publickey),
forward_agent: true,
port: 22,
proxy: Net::SSH::Proxy::Command.new('ssh xxx.xxx.xxx.xxx -W %h:%p')
}

Laravel 4 Permissions on a Vagrant box with Puppet

I have been using http://www.puphpet.com successfully to generate vagrant+puppet environments for a number of projects. Then this week I got tasked with writing a prototype for a project using Laravel 4. Since I'm not going to be the one working on the project full time, I figured it would be best to make a VM environment for it that the next person can just clone for the repo. Not having much experience with Laravel 4 I got everything to run in the dev environment just fine. Then I tried to run the first migration and here the problems start with the app/storage file permissions.
1. app/storage must be writable by the web user
Fine, took out id: vagrant from the synced folder provisioning and set the owner & group to www-data like so:
config.vm.synced_folder "./www", "/var/www", owner: "www-data", group: "www-data"
2. Artisan can only be run from inside the vagrant box to have access to the DB
Fine, vagrant ssh and run artisan from the www folder.
3. app/storage & app/database have to be writable by the vagrant user in order to use migrations
Grrr, ok, added the following awful piece of code to the vagrant file (note, tried to do this in Puppet first and it didn't take):
config.vm.provision :shell, :inline =>
"usermod -a -G www-data vagrant"
4. app/storage & app/database are not writeable by the group
Argh!!! Ok, let's try this Puppet directive:
file { "/var/www/app/storage":
source => "/var/www/app/storage/",
mode => 0775,
ensure => 'directory',
owner => 'www-data',
group => 'www-data',
recurse => true
}
Nope, doesn't work. Tried to do the same with the Puppet exec {} directive to no effect. It seems that permissions for the vagrant synced folder are set by the host machine, not the guest.
Finally ended up manually changing the permissions for the folder in the host machine. Is there any simpler way to do this? I would really just like to be able to give the next dev a worry free environment they can clone from the repo, not have them re-setup everything after cloning.
UPDATE
We've figured out that if we change the Apache run user, vagrant doesn't override it on reload. So we've done that manually and it's working better than changing the synced folder's permissions & owner. Now we're just trying to figure out how to make that change manually in Puppet.
After some discussion on Twitter, figured out the following:
There's a constraint from VirtualBox on vagrant that does not allow you to set permissions for the synced folder from inside the guest OS. See this issue on github.
You can use the following code to set the synced folder permissions from the vagrant file:
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
Or you can change the Apache runtime user to vagrant from the puppet manifest like so:
exec { "change_httpd_user":
command => "sed -i 's/www-data/vagrant/g' /etc/apache2/envvars",
onlyif => "/bin/grep -q 'www-data' '/etc/apache2/envvars'",
notify => Service['apache2'],
require => Package['apache2'],
}
file { "/var/lock/apache2":
ensure => "directory",
owner => "vagrant",
group => "vagrant",
require => Exec['change_httpd_user'],
}
Or any combination of the above
I'm not using pupphet in my setup and I came up with 2 solutions:
(1) In my bootstrap.sh file:
sudo sed -i 's/APACHE_RUN_USER=.*/APACHE_RUN_USER=vagrant/g' /etc/apache2/envvars
sudo sed -i 's/APACHE_RUN_GROUP=.*/APACHE_RUN_GROUP=www-data/g' /etc/apache2/envvars
(2) Im my VagrantFile:
config.vm.synced_folder "./", "/vagrant", id: "vagrant-root" , :owner => "vagrant", :group => "www-data"
config.vm.synced_folder "./app/storage", "/vagrant/app/storage", id: "vagrant-storage",
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]
config.vm.synced_folder "./public", "/vagrant/public", id: "vagrant-public",
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]
Have a look at this section of the Vagrant documentation http://docs.vagrantup.com/v2/synced-folders/basic_usage.html

Capistrano login Net::SSH failure

Suddenly, Capistrano began to return a SSH issue:
** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: staging.myserver.com
(Net::SSH::AuthenticationFailed: root) connection failed for:
staging.myserver.com (Net::SSH::AuthenticationFailed: root)
My deploy.rb contains:
require 'capistrano/ext/multistage'
ssh_options[:forward_agent] = true
ssh_options[:keys] = ["myserver_rsa"]
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :scm, "git"
set :application, "myapp"
set :repository, "git#bitbucket.org:project/myapp.git"
set :use_sudo, false
set :deploy_via, :remote_cache
and at my config/deploy/staging.rb
server 'staging.myserver.com', :app, :web, :db, primary: true
set :branch, 'staging'
set :rails_env, "staging"
set :deploy_to, "/var/rails/#{application}"
set :user, "root"
set :password, "my_triple_check_password_login"
set :domain, "staging.myserver.com"
Tests made by me before posting here:
Try to login via ssh (ssh -v staging.myserver.com)
=> Logged successfully without prompt my password. (using myserver_rsa key)
Agent Forward
=> Enabled in server and in local
Try to login via ssh without keys:
=> prompted for password. Copy and paste it from staging.rb and logged perfectly.
Change server root password. => Try to login with new password via ssh root#... worked nice. but via capistrano, fails.
Run in IRB a Net SSH script to login.
=> Logged in and return a hostname result from bash.
This issue starts yesterday suddenly. I really don't have more ideas :/
First of all, nothing was change at server either Cap deploy configs.
Thanks!
I found!
In my /etc/ssh_config root section I had:
Host *
SendEnv LANG LC_*
XAuthLocation /opt/X11/bin/xauth
ForwardAgent yes
PasswordAuthentication yes
I was need to create a section to my staging environment:
Host staging.myserver.com
IdentityFile /Users/hlegius/.ssh/myserver_rsa
ForwardAgent yes
RSAAuthentication no
PasswordAuthentication no
and edit my config/deploy.rb to add: default_run_options[:pty] = true
Aaaaaaaaand it's works!
This error is due to the authentication failure. Capistrano can't connect to the deploying server with given username and password. I already done the deployment for a server and I am now deploying to a New server. Then I got this error.
It prompted me to give the password for new server. I entered the new server password. But its showing this error.
I changed the domain here
set :domain, "my-new-ip-or-domain" => my new server domain
But forgot to change the username here in my deploy.rb
set :user, "my-new-username"
After giving the correct username and password it works perfectly!

Problems deploying Sinatra app to staging environment

I have a small Sinatra app with both a staging and production environment on a single server with running Nginx. To deploy I am using Capistrano and capistrano-ext to easily deploy to different locations.
The problem that the staging environment always runs with the production configuration specified within the app.rb file.
configure :staging do
# staging settings
set :foo, "bar" # will never be set to this
end
configure :production do
# prod settings
set :foo, "rab"
end
I have come to the conclusion that the capistrano :environment variable within the deploy.rb file doesn't config Sinatra in any way. I have also tried setting the ENV["RACK_ENV"] to "staging" to no avail.
config/deploy/staging.rb
server "10.10.100.16", :app, :web, :db, :primary => true
set :deploy_to, "/var/www/staging.my_app"
set :environment, "staging"
set :env, "staging"
ENV["RACK_ENV"] = "staging"
Any ideas?
** Update: I should add that I am also using Passenger.
setting the rack_env variable within the nginx seems to do the trick.
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#RackEnv

Resources