Symfony2 Capifony deployment - Conflicts on a same server - deployment

I want to deploy different branchs of a Git repository on a same server.
I've updated app/config/deploy.rb
set :stage_dir, "app/config/deploy"
require "capistrano/ext/multistage"
set :stages, %w(prod stag stag2 stag3)
set :application, "MyApp"
I've created new files in app/config/deploy/
In app/config/deploy/stag.rb :
set :symfony_env_prod, "stag"
set :domain, "stag.example.com"
set :deploy_to, "/var/www/#{domain}"
# Other config
role :web, domain
role :app, domain
role :db, domain, :primary => true
In app/config/deploy/stag2.rb
set :symfony_env_prod, "stag"
set :domain, "stag2.example.com"
set :deploy_to, "/var/www/#{domain}"
# Other config
role :web, domain
role :app, domain
role :db, domain, :primary => true
I also launched cap stag2 deploy:setup.
When I deploy using cap stag deploy, stag.example.com is fine
Then, when I deploy cap stag2 deploy,stag2.example.com is file but stag.example.com get some changes from stag2. The source files of stag.example.com are correct. I suppose that there is a cache conflict.
Is Capifony able to deploy the same app in a same server properly ?
Edit : sounds similar Capistrano Multistage deploying to wrong directory
I also tried with set :deploy_to, "/var/www/stag2/#{domain}"

You have to use the server parameters instead of :domain.
stag.rb:
server "stag.example.com", :app, :web, :primary => true
stag2.rb:
server "stag2.example.com", :app, :web, :primary => true
Don't use :domain for this stuff.
See the docs.

I tried your solution #Elnur , replacing server by domain, deployment works fine but the problem still occurs...
After more investigation and tests I came up with a solution that seems to work.
I noticed that in app/autoload.php we use APC
$loader = new ApcUniversalClassLoader('xx.');
xx. is the A prefix to create a namespace in APC
http://symfony.com/doc/2.0/components/class_loader.html
I replaced by
$loader = new ApcUniversalClassLoader('xx.stagX');
Then restart Apache and rm -Rf app/cache/*
That seems to solve the problem. I would be surprised if the same APC name space could be used by 2 different websites on the same server.
This is the exception stack-trace that we got before, look how we go
from /var/www/stag5.XXXX.com/
to /var/www/stag6.XXXX.com/
#10 /var/www/stag6.XXXX.com/shared/vendor/cg-library/src/CG/Proxy/MethodInvocation.php(58): JMS\SecurityExtraBundle\Security\Authorization\Interception\MethodSecurityInterceptor->intercept(Object(CG\Proxy\MethodInvocation))
#11 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/jms_aop/proxies/St-XxBundle-Manager-XxxManager.php(85): CG\Proxy\MethodInvocation->proceed()
#12 /var/www/stag6.XXXX.com/releases/20121210060841/src/Xx/XxxBundle/Controller/XxxController.php(85): EnhancedProxy_16c750f17d8113ffbee7fc3acdc4b1625ca7410b\__CG__\St\CoreBundle\Manager\TagsManager->findXxxxx(Object(Xx\XxBundle\Entity\Project))
#13 [internal function]: Xx\XxxxxBundle\Controller\XxxxController->getXxxAction(Object(Symfony\Component\HttpFoundation\Request))
#14 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/classes.php(4591): call_user_func_array(Array, Array)
#15 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/classes.php(4555): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#16 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/classes.php(5537): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/stag5.XXXX.com/releases/20121210053804/app/bootstrap.php.cache(564): Symfony\Bundle\FrameworkBundle\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/stag5.XXXX.com/releases/20121210053804/web/app_stag.php(13): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#19 {main}

Related

In Capistrano, both stages load when I specify a non-default stage

I have a short multistage capistrano script that specifies a default stage (set :default_stage, :staging), but I find that when I specify another stage on the command line (e.g. cap production deploy), both the staging and production tasks are run:
$ cap production deploy
triggering load callbacks
* 2013-06-19 06:38:34 executing `staging'
* 2013-06-19 06:38:34 executing `production'
As a consequence, the deployment process looks for the scm in the location specified by staging.rb, which is a local repository -- so it doesn't exist for the production server, and my deployment fails.
Can I provide a default stage in my deploy script but not have it loaded when I specify another stage on the command line?
You can see my deploy files here:
deploy.rb
set :stages, [:staging, :production]
set :default_stage, :staging
require 'capistrano/ext/multistage'
set :repository, "myrepo"
set :scm, :git
set :scm_user, "deploy"
set :user, "deploy"
set (:deploy_to) {"/var/www/clu2/#{application}/"}
set :use_sudo, false
default_run_options[:pty] = true
production.rb
set :application, "production"
set :rails_env, 'production'
set :deploy_to, "/var/www/myapp/"
set :branch, 'develop'
role :app, 'trustedquote.com'
role :web, 'trustedquote.com'
role :db, 'trustedquote.com', :primary => true
staging.rb
set :application, "staging"
set :rails_env, 'production'
set :repository, "file:///git/myrepo.git"
set :local_repository, "file://."
set :branch, 'develop'
role :app, 'mylocation'
role :web, 'mylocation'
role :db, 'mylocation', :primary => true
Thanks to #CDub for his input.
I changed the stage names in deploy.rb from symbols to strings, and that made the difference:
set :stages, %w[staging production]
set :default_stage, 'staging'

capistrano and ec2 and github - unable to deploy

I am trying to deploy my first webapp to EC2 using capistrano and the repo is on github. But I am facing issues with "cap deploy:cold". The deploy.rb is pasted below. Following are the steps I followed.
1) Logged into ec2 instance using ssh from my local machine. Generated keys using ssh-keygen without any passphrase.
2) Took the contents of id_rsa.pub and copied to the github repo settings deploy keys.
3) Then from my local machine, ran "cap deploy:cold". I get the following error
user1#laptop:~/MyExample$ cap deploy:cold
* 2013-03-01 19:08:06 executing deploy:cold'
* 2013-03-01 19:08:06 executingdeploy:update'
** transaction: start
* 2013-03-01 19:08:06 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#github.com:user1/MyExample.git HEAD"
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
* [deploy:update_code] rolling back
* executing "rm -rf /var/www/MyExample.com/releases/20130301133835; true"
servers: ["181.73.124.219"]
[181.73.124.219] executing command
command finished in 1186ms
set :application, "MyExample.com"
set :scm, "git"
set :repository, "git#github.com:thisuser/example.git"
default_run_options[:pty] = true
set :user, 'ubuntu'
set :use_sudo, true
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :remote_cache
role :web, "181.73.124.219"
role :app, "181.73.124.219"
role :db, "181.73.124.219", :primary => true
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"
namespace :deploy do
task :bundle_gems do
run "cd #{deploy_to}/current && bundle install vandor/gems"
end
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
What am I missing here? Also any pointers to a URL/blog that can provide detailed steps would help.
Thanks.
I managed to get it working. As seen in the log,
executing locally: "git ls-remote git#github.com:user1/MyExample.git HEAD"
the capistrano is trying to run the above command local machine and not on the server. Running the above command on the terminal also returned the same error - Permission denied (Public Key).
So I had to copy the generated id_rsa and id_rsa.pub from the deploy server to the local machine. And after copying, add it to the ssk keys being used by running "ssh-add /path/to/keys".
After adding those keys, I was able to move ahead.

Chef Deployment with irrelevant default symlinks

I am trying to deploy my application code with Chef, which is working for one node and failing on another. I cannot determine why it works for one node and not another when they have the exact same config, but I can at least try to debug the problem on the node that fails.
deploy_revision app_config['deploy_dir'] do
scm_provider Chef::Provider::Git
repo app_config['deploy_repo']
revision app_config['deploy_branch']
if secrets["deploy_key"]
git_ssh_wrapper "#{app_config['deploy_dir']}/git-ssh-wrapper" # For private Git repos
end
enable_submodules true
shallow_clone false
symlink_before_migrate({}) # Symlinks to add before running db migrations
purge_before_symlink [] # Directories to delete before adding symlinks
create_dirs_before_symlink [] # Directories to create before adding symlinks
# symlinks()
action :deploy
restart_command do
service "apache2" do action :restart; end
end
end
This is my recipe for deploying the code. Notice that I have tried disabling symlinking entirely, as Chef always jams its own defaults in. Even with this I get the error:
================================================================================
Error executing action `deploy` on resource 'deploy_revision[/var/www]'
================================================================================
Chef::Exceptions::FileNotFound
------------------------------
Cannot symlink /var/www/shared/config/database.yml to /var/www/releases/7404041cf8859a35de90ae72091bea1628391075/config/database.yml before migrate: No such file or directory - /var/www/shared/config/database.yml or /var/www/releases/7404041cf8859a35de90ae72091bea1628391075/config/database.yml
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/kapture/recipes/api.rb
68:
69: deploy_revision app_config['deploy_dir'] do
70: scm_provider Chef::Provider::Git
71: repo app_config['deploy_repo']
72: revision app_config['deploy_branch']
73: if secrets["deploy_key"]
74: git_ssh_wrapper "#{app_config['deploy_dir']}/git-ssh-wrapper" # For private Git repos
75: end
76: enable_submodules true
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/kapture/recipes/api.rb:69:in `from_file'
deploy_revision("/var/www") do
destination "/var/www/shared/cached-copy"
symlink_before_migrate {"config/database.yml"=>"config/database.yml"}
updated_by_last_action true
restart_command #<Proc:0x00007f40f366e5a0#/var/chef/cache/cookbooks/kapture/recipes/api.rb:82>
repository_cache "cached-copy"
retries 0
keep_releases 5
create_dirs_before_symlink ["tmp", "public", "config"]
updated true
provider Chef::Provider::Deploy::Revision
enable_submodules true
deploy_to "/var/www"
current_path "/var/www/current"
recipe_name "api"
revision "HEAD"
scm_provider Chef::Provider::Git
purge_before_symlink ["log", "tmp/pids", "public/system"]
git_ssh_wrapper "/var/www/git-ssh-wrapper"
remote "origin"
shared_path "/var/www/shared"
cookbook_name "kapture"
symlinks {"log"=>"log", "system"=>"public/system", "pids"=>"tmp/pids"}
action [:deploy]
repo "git#github.com:kapture/api.git"
retry_delay 2
end
[2012-09-24T15:42:07+00:00] ERROR: Running exception handlers
[2012-09-24T15:42:07+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2012-09-24T15:42:07+00:00] ERROR: Exception handlers complete
[2012-09-24T15:42:07+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2012-09-24T15:42:07+00:00] FATAL: Chef::Exceptions::FileNotFound: deploy_revision[/var/www] (kapture::api line 69) had an error: Chef::Exceptions::FileNotFound: Cannot symlink /var/www/shared/config/database.yml to /var/www/releases/7404041cf8859a35de90ae72091bea1628391075/config/database.yml before migrate: No such file or directory - /var/www/shared/config/database.yml or /var/www/releases/7404041cf8859a35de90ae72091bea1628391075/config/database.yml
Here you can see it mention database.yml, tmp/, system/ and pids folders, all of which are defaults that Chef likes to set (see related bug)
Question 1
What are these symlinks for and how do I know if I even need any. What sort of things am I symlinking? I will be using migrations, so if they are useful for the migration then I'll need them working.
I have read the documentation many times and it just doesn't explain this is plain English - at least not that I have found.
Question 2
If I do not require them, how can I disable symlinking entirely? Following the examples in that bug report have not helped.
Clear out all the symlink attributes.
deploy_revision("/var/www") do
# ...
symlink_before_migrate.clear
create_dirs_before_symlink.clear
purge_before_symlink.clear
symlinks.clear
end
Make sure the deployment directory in shared has the proper directory structure (/var/www/shared/[log,pids,system,config]) and that all config files necessary for your application are in the config directory.
Your recipe for your application's cookbook should have an array of directory names to create (recursively) so that you won't run into this error again.
The symlinks are there so that while your application code will continue to evolve, you can share the log, pids, and system folder by symlinking shared/log to current/log and so on and so forth..
Chef happens to cache the directory structure - somehow, I haven't dug into that - with this troll application cookbook. It's something in the deploy resource I believe - I never use that - but you can fix it by deleting the directory structure it creates in /var/derp or whatever. Also ensure your tmp directory is setup.
A couple reasons this may be an issue:
File permissions are incorrect
The currently running chef user cannot access the file
You are using the application cookbook in a configuration for rails deploys and your application does not have the same directory structure.
It's definitely caused by Chef caching the state of the deploy somewhere, then reading that state out of it's cache - wherever that is - and then reusing that. I would look at either the application cookbook to see for any persistance, and if you fail at finding it there, look in the deploy resource from chef itself.

Zend Framework Invalid controller specified excepection

Hi I have a problem trying to configure Zend Frame work in test server, I have the project working fine in my local mac computer, I upload all the file to my root html docs in my test server, exactly like I have it in my local, but for some reason I can't found my controllers, the error I have is this
An error occurred
Page not found
Exception information:
Message: Invalid controller specified (MessageBroker)
Stack trace:
#0 /var/www/html/magentoreviewsZF/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /var/www/html/magentoreviewsZF/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 /var/www/html/magentoreviewsZF/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 /var/www/html/magentoreviewsZF/public/index.php(26): Zend_Application->run()
#4 {main}
Request Parameters:
array (
'controller' => 'MessageBroker',
'action' => 'index',
'module' => 'default',
)
I have see in other post that changing the RewriteBase in the htaccess do the trick, but don't work for me, also I have the default structure, also the index controller and the error controller works, if I go directly to their path.
so is working is just my MessageBroker controller is not been found, why!, please anybody can point me to the right direction, I really don't know what else to do, thanks!!!
Iam not sure, but let me guess: Test Server = Windows ? Production = Linux ?
Take care about the filename / classname of your Controller on linux its case sensetive so name you Controller:
class MessagebrokerController extends Zend_Controller_Action
{}
And your filename: MessagebrokerController.php

Zend frame work Database connection and configuration

I am very new to zend frame work , I want to do some updation work in one project that already done by other programmers, now iam trying to setting up this project in my local server (I am using xamp), i have created the database in phpmyadmin, but while running this project i got the following error....
"Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[28000] [1045] Access denied for user 'numberfo_admin'#'localhost' (using password: NO)' in C:\xampp\php\PEAR\Zend\Db\Adapter\Pdo\Abstract.php:144 Stack trace: #0 C:\xampp\php\PEAR\Zend\Db\Adapter\Pdo\Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 C:\xampp\php\PEAR\Zend\Db\Adapter\Abstract.php(832): Zend_Db_Adapter_Pdo_Mysql->_connect() #2 C:\xampp\php\PEAR\Zend\Db\Adapter\Abstract.php(902): Zend_Db_Adapter_Abstract->quote(1257218565, NULL) #3 C:\xampp\htdocs\NFL_021\library\Utils\session_handling.php(16): Zend_Db_Adapter_Abstract->quoteInto('last_login_date...', 1257218565) #4 C:\xampp\htdocs\NFL_021\application\controllers\IndexController.php(16): require_once('C:\xampp\htdocs...') #5 C:\xampp\php\PEAR\Zend\Controller\Action.php(513): IndexController->indexAction() #6 C:\xampp\php\PEAR\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('indexAction') #7 C:\xampp\php\PEAR\Zend\Controller\Front.php(946 in C:\xampp\php\PEAR\Zend\Db\Adapter\Pdo\Abstract.php on line 144"
Plsss any one help me to fix this error........
It looks like you either have incorrect permissions set up with MySql or you're trying to access the database using wrong credentials from Zend Framework. Verify that you can log in to the database with the credentials you're trying to use (via phpMyAdmin). Also verify that in Zend Framework you're using the credentials that indeed have access to the database in question.
Set password for Mysql user (it my be «root» or some other).
Then edit Zend configuration file such as application.ini