aboutsummaryrefslogtreecommitdiffstats
path: root/config/deploy.rb
diff options
context:
space:
mode:
authorLuc Donnet2013-12-11 14:03:50 +0100
committerLuc Donnet2013-12-11 14:03:50 +0100
commit62dac463665bbe9c5255162c0bbb3b6217a067cb (patch)
treefd67f6465f97fc4bb2991331984e4f0adffb38b5 /config/deploy.rb
parentadb8844abec23b4ab0382d59397cd2e6a0caaa58 (diff)
downloadchouette-core-62dac463665bbe9c5255162c0bbb3b6217a067cb.tar.bz2
Add capistrano to chouette2
Diffstat (limited to 'config/deploy.rb')
-rw-r--r--config/deploy.rb92
1 files changed, 92 insertions, 0 deletions
diff --git a/config/deploy.rb b/config/deploy.rb
new file mode 100644
index 000000000..f0ddfded5
--- /dev/null
+++ b/config/deploy.rb
@@ -0,0 +1,92 @@
+require 'capistrano/ext/multistage'
+require './config/boot'
+
+set :stages, %w(sandbox unstable staging production)
+set :application, "chouette2"
+set :user, "ldonnet"
+set :scm, :git
+set :repository, "git@github.com:afimb/chouette2.git"
+set :deploy_to, "/var/www/chouette2"
+set :use_sudo, false
+default_run_options[:pty] = true
+set :group_writable, true
+set :rake, "bundle exec rake"
+set :keep_releases, 4
+set :rails_env, "production" #added for delayed job
+
+after "deploy:update", "deploy:cleanup", "deploy:group_writable"
+after "deploy:update_code", "deploy:symlink_shared", "deploy:chouette_command", "deploy:gems"
+# ugly workaround for bug https://github.com/capistrano/capistrano/issues/81
+before "deploy:assets:precompile", "deploy:symlink_shared"
+after "deploy:restart", "delayed_job:restart"
+after "deploy:migrate", "deploy:migrate_tenants"
+
+# If you want to use command line options, for example to start multiple workers,
+# define a Capistrano variable delayed_job_args:
+#
+# set :delayed_job_args, "-n 2"
+
+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
+
+ # Prevent errors when chmod isn't allowed by server
+ task :setup, :except => { :no_release => true } do
+ dirs = [deploy_to, releases_path, shared_path]
+ dirs += shared_children.map { |d| File.join(shared_path, d) }
+ run "mkdir -p #{dirs.join(' ')} && (chmod g+w #{dirs.join(' ')} || true)"
+ end
+
+ desc "Runs rake task which migrates database tables for all tenants"
+ task :migrate_tenants do
+ run "cd #{release_path} && rake apartment:migrate"
+ end
+
+ desc "Install gems"
+ task :gems, :roles => :app do
+ run "cd #{release_path} && umask 02 && bundle install --path=#{shared_path}/bundle --without=development:test:cucumber"
+ end
+
+ desc "Symlinks shared configs and folders on each release"
+ task :symlink_shared, :except => { :no_release => true } do
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/"
+ run "ln -nfs #{shared_path}/config/production.rb #{release_path}/config/environments/"
+ end
+
+ desc "Install chouette command"
+ task :chouette_command, :except => { :no_release => true } do
+ run "mkdir -p /var/lib/chouette/imports"
+ run "mkdir -p /var/lib/chouette/imports"
+ run "mkdir -p /var/lib/chouette/validations"
+ run "mkdir -p /usr/local/opt/chouette-command/"
+ end
+
+ desc "Make group writable all deployed files"
+ task :group_writable do
+ run "sudo /usr/local/sbin/cap-fix-permissions /var/www/chouette2"
+ end
+
+ # desc "Generate jekyll static sites"
+ # task :jekyll, :except => { :no_release => true } do
+ # run "cd #{release_path} && jekyll --auto doc/functional public/help"
+ # end
+
+ desc "tail log files"
+ task :tail, :roles => :app do
+ #run "tail -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
+ run "tail -f /var/log/syslog" do |channel, stream, data|
+ puts "#{channel[:host]}: #{data}"
+ break if stream == :err
+ end
+ end
+
+end
+
+namespace :delayed_job do
+ task :restart do
+ run "sudo /etc/init.d/chouette2 restart"
+ end
+end