in my deploy script deploy.rb
lock "3.11.0"
set :application, "myapp"
set :repo_url, "ssh://app#git.whitebear.com/home/app/myGit/myapp.git"
set :branch, 'master'
set :deploy_to, "/var/www/html/myapp"
#set :linked_files, %w{app/config/parameters.yml}
set :linked_dirs, %w{log vendor var node_modules public/build public/dlstore config/spool}
#somehow app/cache doesn't work...
set :format, :pretty
set :log_level, :debug
set :keep_releases, 3
after 'deploy:starting', 'composer:install_executable'
set :yarn_flags, "--prefer-offline --production --no-progress"
set :yarn_roles, :app
in production.rb
set :stage, :prod
set :symfony_env, "prod"
set :webserver_user, "app"
#set :controllers_to_clear, ["app_*.php"]
set :composer_install_flags, '--prefer-dist --no-interaction --optimize-autoloader'
server 'myapp.com', user: 'app', port: 22, roles: %w{app db web} # edit IP / Port and SSH user of your production server
SSHKit.config.command_map[:composer] = "php #{shared_path.join("composer.phar")}"
I set keep_releases 3, however when I deployed I have permission problems.
I don't know why permission is changed by Aapache though,
Is it possible forcely exec rm when deploying??
DEBUG [cd2bf6b1] cannot remove `/var/www/html/myApp/releases/20190212120003/var/cache/prod/pools/VQruNbwKF0/X/3/tCcgRMw5TEmYO-kHpJ0t'
DEBUG [cd2bf6b1] : Permission denied
This is a common problem caused by poor server configuration or deployment ran via wrong user. You u try to execute a script with user x and permissions for that file belongs to www-data and your user x is unable to remove it you will get this error. Your user has to have rights to remove that file. The user which executes the script is not the same as user that executes web request.
Related
I just completed my capistrano installation for the first time. Most of everything is left to default settings, I configured my server, its authentification, and the remote folder, as well as the access to my git repository.
I use capistrano to deploy php code to my server.
cap staging deploy and cap production deploy function, but they run every command twice. It sometimes causes problems when those tasks are executed too quickly on the server, returning error codes, which stops the deploying process.
an example of my output when running cap staging deploy
DEBUG[47ecea59] Running /usr/bin/env if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi on ftp.cluster013.ovh.net
DEBUG[47ecea59] Command: if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi
DEBUG[c450e730] Running /usr/bin/env if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi on ftp.cluster013.ovh.net
DEBUG[c450e730] Command: if test ! -d ~/www/test_server/repo; then echo "Directory does not exist '~/www/test_server/repo'" 1>&2; false; fi
It does the same with every single task, except the one I defined myself (in my deploy.rb, I defined a :set_distant_server task that moves around files with server info)
I am pretty sure I missed something during the initial configuration.
Here is my capfile, still to default settings :
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
#require 'capistrano/bundler'
#require 'capistrano/rails/assets'
#require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Followed by my deploy.rb file:
# config valid only for Capistrano 3.1
lock '3.2.1'
set :scm, :git
set :application, 'Application name'
# I use token authentification
set :repo_url, 'https://XXXXXXXXXXX:#XXXXXXX.git'
set :role, 'web'
# Default value for :log_level is :debug
set :log_level, :debug
set :tmp_dir, 'www/test_server/tmp'
set :keep_releases, 8
role :deploy_server, "XXXuser_name#XXXX_server"
task :set_distant do
on roles(:deploy_server) do
execute 'echo ------------******* STAGING *******------------'
execute 'cp ~/www/test_server/current/access_distant.php ~/www/test_server/current/access.php'
execute 'cp ~/www/test_server/current/session_distant.php ~/www/test_server/current/session.php'
end
end
after "deploy:finished", :set_distant
Here is my staging.rb, much shorter:
server 'XXX_server', user: 'XXXuser_name', roles: %w{web}, port: 22, password: 'XXXpassword'
set :deploy_to, '~/www/test_server'
set :branch, 'staging'
And my production.rb, very similar:
server 'XXX_server', user: 'XXXuser_name', roles: %w{web}, port: 22, password: 'XXXpassword'
set :deploy_to, '~/www/beta/'
I'm pretty sure I missed a step in all the prerequisites to make it run nicely. I am new to ruby, to gems, and didn't use shell for a very long time.
Does anyone see why those commands are run twice, and how I could fix it?
In advance, many many thanks.
Additional info:
Ruby version: ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
Capistrano version: cap -V
Capistrano Version: 3.2.1 (Rake Version: 10.1.0)
I did not create a Gemfile or set it up, I understood it was not needed in Capistrano 3. Anyway, I would not know how to do it.
I was having this same issue and realized I didn't need both
role :web
and
server '<server>'
I got rid of role :web and that got rid of the 2nd execution.
I have a user didongo (user & group didongo), and the nginx server (user & group www-data). I've setup Capifony to login as didongo user: the first time I deploy setfacl command works ok (while the logs folder is empty). But after the web application, served by nginx, has generated some logs (prod.log) the very next deploy fails, with an setfacl error.
I'm sure I'm doing a noob error with the permissions between the user and the web server, but I don't see what error. I see that didongo should not be able to change permissions of a file he hasn't permissions to. But then, how I'm supposed to configure the server or Capifony?
Thanks!
Relevant (hope so) Capifony deploy.rb config:
set :user, "didongo"
set :webserver_user, "www-data"
set :permission_method, :acl
set :use_set_permissions, true
set :shared_children, [app_path + "/logs", web_path + "/uploads", "vendor"]
set :writable_dirs, ["app/cache", "app/logs"]
This is the Capifony error:
$ setfacl -R -m u:didongo:rwx -m u:www-data:rwx /home/didongo/staging/shared/app/logs
setfacl: /home/didongo/staging/shared/app/logs/prod.log: Operation not permitted
Some data on the ACL:
$ getfacl app/logs
# file: logs
# owner: didongo
# group: didongo
user::rwx
user:www-data:rwx
user:didongo:rwx
group::rwx
mask::rwx
other::r-x
default:user::rwx
default:user:www-data:rwx
default:user:didongo:rwx
default:group::rwx
default:mask::rwx
default:other::r-x
# file: logs/prod.log
# owner: www-data
# group: www-data
user::rw-
user:www-data:rwx #effective:rw-
user:didongo:rwx #effective:rw-
group::rwx #effective:rw-
mask::rw-
other::r--
Try this once with sudo and after you will no need to use sudo
sudo sh -c 'setfacl -R -m u:didongo:rwX -m u:www-data:rwX /home/didongo/staging/shared/app/logs'
Because you need to set x+ permissions, read this What is trailing Plus indicates
The problem here, is that prod.log file was created automatically so its owner is www-data. Capifony runs deployment as didongo user. One user can't do setfacl to the other owner's file.
So just add didongo to the group www-data: sudo adduser didongo www-data
Finally I managed this creating different PHP-FPM pools with the same permissions as the user. This way I can have different users separated from each other. And as a bonus deploy.rb is simplified.
I've been experiencing an issue where capistrano will deploy an old revision from our git repo, unless we specify the exact revision we want to deploy to.
#this will deploy a revision from a couple weeks ago
cap staging deploy:migrations
#this will deploy correctly a new revision
cap staging deploy:migrations -S revision=74d27c00363cdcd456942d6951230564893ccb28
Does anyone have an idea why this could be happening?
here is the cap deploy file:
set :rvm_ruby_string, 'ruby-1.9.3-p194#ac_helenefrance_01' # Or:
#set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
# set :verbose ,1
require 'capistrano/ext/multistage'
set :stages, %w(staging production)
set :default_stage, "staging"
set :user, "webm"
# set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git#aliencom.beanstalkapp.com:/ac_helenefrance_01.git"
# :branch is being set in stage files
default_run_options[:pty] = true
# ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "#{sudo} service unicorn_#{server_configuration} #{command}"
end
end
desc "build missing paperclip styles"
task :build_missing_paperclip_styles, :roles=> :app do
run "cd #{release_path}; RAILS_ENV=production bundle exec rake paperclip:refresh:missing_styles"
end
after "deploy:update", "deploy:build_missing_paperclip_styles"
task :setup_config, roles: :app do
puts "#making symlink to nginx sites-enabled"
run "#{sudo} ln -fs #{current_path}/config/server/#{server_configuration}/nginx.conf /etc/nginx/sites-enabled/#{server_configuration}"
puts "#making symlink to unicorn service script"
run "#{sudo} ln -fs #{current_path}/config/server/#{server_configuration}/unicorn_init.sh /etc/init.d/unicorn_#{server_configuration}"
puts "#making a the new config directory"
run "mkdir -p #{shared_path}/config"
run "sunique 1"
put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
run "sunique 0"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
puts "#for reference:"
puts "#rvm wrapper 1.9.3#ac_helenefrance_01 ruby-1.9.3-p194##{server_configuration} unicorn cap"
puts "#now be sure to run: sudo update-rc.d unicorn_#{server_configuration} defaults"
end
after "deploy:finalize_update", "deploy:symlink_config"
end
and the environment/stage.rb for the default multistage env.
server "xxx.xxx.xxx.xxx", :web, :app, :db, primary: true
set :branch, "sitemap"
set :isRemote, true
set :server_configuration, "st_ac_helenefrance_01"
set :application, "#{server_configuration}"
set :deploy_to, "/home/#{user}/#{server_configuration}"
It was setup to an old branch >:(
My colleague accidentally committed a test he was doing.
I have problem to deploy via very fresh capifony up on Capistrano v2.8.0 - it's my first capistrano/capifony deploy.
I have successfully done cap deploy:setup and now i need to execute cap deploy:cold.
SSH communication works well but it cannot execute git clone command because of ssh permissions:
* executing "git clone -q git#github.com:palmic/www.myproject.com.git /home/palmic/web/hostik.cz/palmic/releases/20110823122821 && cd /home/palmic/web/hostik.cz/palmic/releases/20110823122821 && git checkout -q -b deploy 7407672c0a59ad631ea2f1f1d71fb15c2f68ac30 && (echo 7407672c0a59ad631ea2f1f1d71fb15c2f68ac30 > /home/palmic/web/hostik.cz/palmic/releases/20110823122821/REVISION)"
servers: ["hostik.cz"]
[hostik.cz] executing command
** [hostik.cz :: err] Permission denied (publickey).
** fatal: The remote end hung up unexpectedly
command finished in 3123ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/palmic/web/hostik.cz/palmic/releases/20110823122821; true"
servers: ["hostik.cz"]
[hostik.cz] executing command
command finished in 164ms
When i login into ssh session and call this manualy it request ssh passphrase.
When i fill up the same passphrase which i have like :scm_passphrase in deploy.rb, then clone is successfully done.
So it looks like capistrano cannot fill up passphrase on my setup.
BTW. ssh_options[:forward_agent] = true/false does totaly nothing does anybody knows why?? (i have agent forwarding allowed in my ~/.ssh/config):
Host *hostik.cz
ForwardAgent yes
Host *
ForwardAgent no
my deploy.rb:
set :application, "app"
set :domain, "hostname"
set :deploy_to, "remotepath"
set :use_sudo, false
set :repository, "git#github.com:palmic/myproject.git"
set :scm, :git
set :user, "my remote username"
set :scm_passphrase, "my ssh passphrase on remote host"
set :branch, "git project deploy branchname"
set :scm_verbose, true
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
set :keep_releases, 3
ssh_options[:forward_agent] = true
I know it's not any original bug and iam missing something, does anybody know?
You could add this in your deploy.rb:
default_run_options[:pty] = true
I'm trying to deploy a simple Ruby on Rails app to dreamhost but I'm getting an error related to the bundle command. Here is the error:
servers: ["bullseye.dreamhost.com"]
[bullseye.dreamhost.com] executing command
command finished
* executing "find /home/USER-NAME/MY-DOMAIN/releases/20110123014150/public/images /home/USER-NAME/MY-DOMAIN/releases/20110123014150/public/stylesheets /home/USER-NAME/MY-DOMAIN/releases/20110123014150/public/javascripts -exec touch -t 201101230141.52 {} ';'; true"
servers: ["bullseye.dreamhost.com"]
[bullseye.dreamhost.com] executing command
command finished
triggering after callbacks for `deploy:update_code'
* executing `bundle:install'
* executing "ls -xt /home/USER-NAME/MY-DOMAIN/releases"
servers: ["bullseye.dreamhost.com"]
[bullseye.dreamhost.com] executing command
command finished
* executing "bundle install --gemfile /home/USER-NAME/MY-DOMAIN/releases/20110123014150/Gemfile --path /home/USER-NAME/MY-DOMAIN/shared/bundle --deployment --quiet --without development test"
servers: ["bullseye.dreamhost.com"]
[bullseye.dreamhost.com] executing command
*** [err :: bullseye.dreamhost.com] sh: bundle: command not found
command finished
*** [deploy:update_code] rolling back
* executing "rm -rf /home/USER-NAME/MY-DOMAIN/releases/20110123014150; true"
servers: ["bullseye.dreamhost.com"]
[bullseye.dreamhost.com] executing command
command finished
failed: "sh -c 'bundle install --gemfile /home/USER-NAME/MY-DOMAIN/releases/20110123014150/Gemfile --path /home/USER-NAME/MY-DOMAIN/shared/bundle --deployment --quiet --without development test'" on bullseye.dreamhost.com
Here is my deploy.rb file.
require 'bundler/capistrano'
set :user, "MY-USERNAME"
set :password, "MY-PASSWORD"
set :domain, 'bullseye.dreamhost.com' # Dreamhost servername where your account is located
set :project, 'blog' # Your application as its called in the repository
set :application, 'MY-DOMAIN' # Your app's location (domain or sub-domain name as setup in panel)
set :applicationdir, "/home/#{user}/#{application}" # The standard Dreamhost setup
# version control config
set :scm_username, 'MY-SVN-USERNAME'
set :scm_password, 'MY-SVN-PWD'
set :repository, "http://MY-SVN-URL/01/blog/"
# roles (servers)
role :web, domain
role :app, domain
role :db, domain, :primary => true
# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export
# additional settings
default_run_options[:pty] = false # Forgo errors when deploying from windows
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
I found a similar question at Bundle install failing when deploying a Rails 3 app to Dreamhost with Capistrano but the solution didn't work. Anybody have any ideas as to what might be happening in my case?
I got this figured out eventually. What I did was
ssh into the dreamhost server and execute which bundle command
from ssh session execute echo $PATH command
edit config/deploy.rb and combine both strings with a : between and place inside default_environment PATH value, see below
set :default_environment, {
'PATH' => "'/usr/lib/ruby/gems/1.8/bin//bundle:/home/sayed3/.gems/bin:/usr/lib/ruby/gems/1.8/bin/:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games'"
}
Once I did this it was able to execute the bundle command successfully, but then I started running into some other issues. I eventually decided to use a VPS that I have hosted elsewhere, but I'm sure if I spent a bit more time I could have figured it out.
Besides adding the path to bundle, as specified above, I also had to add the following line to my config/deploy.rb in order to force capistrano to use bash, instead of the default shell, which, on dreamhost, is dash:
set :shell, '/bin/bash'