From 4263f9b0f400b4410c06774ae2f1afdc2b32ba21 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 19 Mar 2018 21:34:07 +0100 Subject: [PATCH] suite --- config/deploy.rb | 210 ++++++++++++++++++++++++---------------------- config/env_init | 6 ++ config/nginx.conf | 12 +-- config/unicorn.rb | 10 +-- 4 files changed, 126 insertions(+), 112 deletions(-) create mode 100644 config/env_init diff --git a/config/deploy.rb b/config/deploy.rb index 12fb19b..281da4f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,143 +1,151 @@ +set :rvm_ruby_string, 'ruby-2.3.0' set :application, 'jipe_app' - set :domain, 'jipe.quartz.xyz' +set :domain, 'quartz-www02.sysnove.net' - set :user, 'web' - set :scm_user, "git" - set :scm_host, "gitlab.quartz.xyz" +set :user, 'web' +set :scm_user, "git" +set :scm_host, "quartz.snlab.fr" + +set :rvm_autolibs_flag, "read-only" - - set :rvm_ruby_string, 'ruby-2.3.0' - set :rvm_autolibs_flag, "read-only" - - set :bundle_cmd, "/home/#{user}/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle" - set :bundle_dir, "/home/#{user}/.rvm/gems/#{rvm_ruby_string}" - set :use_sudo, false +set :bundle_cmd, "/srv/www/#{user}/.rvm/gems/#{rvm_ruby_string}@global/bin/bundle" +set :bundle_dir, "/srv/www/#{user}/.rvm/gems/#{rvm_ruby_string}" +set :use_sudo, false - set :deploy_to, "/home/#{user}/#{application}/" - set :deploy_via, :remote_cache +set :deploy_to, "/srv/www/#{user}/#{application}/" +set :deploy_via, :remote_cache - set :normalize_asset_timestamps, false +set :normalize_asset_timestamps, false - set :rails_env, "production" +set :rails_env, "production" - role :app, domain - role :web, domain - role :db, domain, :primary => true +role :app, domain +role :web, domain +role :db, domain, :primary => true - set :scm, :git +set :scm, :git - set :repository, "#{scm_user}@#{scm_host}:nbally/#{application}.git" +set :repository, "#{scm_user}@#{scm_host}:nicolas/#{application}.git" - set :branch, "master" +set :branch, "master" - default_run_options[:pty] = true +default_run_options[:pty] = true - require "rvm/capistrano" - require 'bundler/capistrano' +require "rvm/capistrano" +require 'bundler/capistrano' - load 'deploy/assets' +load 'deploy/assets' - namespace :deploy do +namespace :deploy do + +# namespace :assets do +# task :precompile, :roles => :web, :except => { :no_release => true } do +# from = source.next_revision(current_revision) +# if releases.length <= 1 || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0 +# run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} +# else +# logger.info "Skipping asset pre-compilation because there were no asset changes" +# end +# end +# end + + + + desc "Symlink shared config files" + task :symlink_config_files do + + + run "ln -s #{deploy_to}shared/storage/private #{current_path}/private_medias" + + run "ln -s #{deploy_to}shared/storage/public #{current_path}/public/public_medias" + + + run "ln -s #{deploy_to}shared/production.sqlite3 #{current_path}/db/production.sqlite3" + + sudo "cp #{current_path}/config/env_init #{deploy_to}env_init" - # namespace :assets do - # task :precompile, :roles => :web, :except => { :no_release => true } do - # from = source.next_revision(current_revision) - # if releases.length <= 1 || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0 - # run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} - # else - # logger.info "Skipping asset pre-compilation because there were no asset changes" - # end - # end - # end + sudo "sudo systemctl enable quartz_app@#{application}" - - desc "Symlink shared config files" - task :symlink_config_files do - - - run "ln -s #{deploy_to}shared/storage/private #{current_path}/private_medias" - - run "ln -s #{deploy_to}shared/storage/public #{current_path}/public/public_medias" - run "ln -s #{deploy_to}shared/pdf #{current_path}/pdf" - - run "ln -s #{deploy_to}shared/csv #{current_path}/csv" - - run "ln -s #{deploy_to}shared/production.sqlite3 #{current_path}/db/production.sqlite3" - - sudo "cp #{current_path}/config/unicorn_init_d /etc/init.d/#{application}" - - sudo "chmod +x /etc/init.d/#{application}" - sudo "update-rc.d #{application} defaults " - end - - - - task :start do - sudo "service #{application} start" - end - task :stop do - run "service #{application} stop" - end - task :restart do - sudo "service #{application} restart" - end - - task :reload_nginx do - - sudo "rm -rf /etc/nginx/sites-enabled/#{application}" - sudo "ln -s #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application} " - - sudo "service nginx reload" - end - - - - task :seeds do - run "cd #{deploy_to}current && rake db:seed RAILS_ENV=#{rails_env}" - - end - - - task :create_files_folders do - - run "mkdir #{deploy_to}shared/storage" - run "mkdir #{deploy_to}shared/storage/private" - run "mkdir #{deploy_to}shared/storage/public" - end - - - end - #before 'deploy:setup', 'rvm:install_rvm' # install RVM - #before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, OR: - #before 'deploy:setup', 'rvm:create_gemset' # only create gemset - + + task :start do + sudo "systemctl start quartz_app@#{application}" + end + task :stop do + sudo "systemctl stop quartz_app@#{application}" + end + task :restart do + sudo "systemctl stop quartz_app@#{application}" + sudo "systemctl start quartz_app@#{application}" + end + + task :reload_nginx do + + sudo "rm -rf /etc/nginx/sites-enabled/#{application}" + sudo "ln -s #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application} " + + sudo "service nginx reload" + end + + + + task :seeds do + run "cd #{deploy_to}current && rake db:seed RAILS_ENV=#{rails_env}" + + end + + + task :create_files_folders do + + run "mkdir #{deploy_to}shared/storage" + run "mkdir #{deploy_to}shared/storage/private" + run "mkdir #{deploy_to}shared/storage/public" + end + + + +end + + +#before 'deploy:setup', 'rvm:install_rvm' # install RVM +#before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, OR: +#before 'deploy:setup', 'rvm:create_gemset' # only create gemset + + + +after "deploy:setup", "deploy:create_files_folders" + +#after "deploy:restart", "deploy:cleanup" + + +before "deploy:restart", "deploy:symlink_config_files" + +after "deploy", "deploy:cleanup" + + + - after "deploy:setup", "deploy:create_files_folders" - #after "deploy:restart", "deploy:cleanup" - before "deploy:restart", "deploy:symlink_config_files" - after "deploy", "deploy:cleanup" diff --git a/config/env_init b/config/env_init new file mode 100644 index 0000000..7042d60 --- /dev/null +++ b/config/env_init @@ -0,0 +1,6 @@ +APP_RUBY=2.3.0 +ENV=production +APP_ROOT=/srv/www/web/jipe_app/current/ +GEM_HOME=/srv/www/web/.rvm/gems/ruby-$APP_RUBY +UNICORN_OPTS="-D -E ${ENV} -c ${APP_ROOT}/config/unicorn.rb" + diff --git a/config/nginx.conf b/config/nginx.conf index bf4adb8..21c5937 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -1,5 +1,5 @@ upstream jipe_app_unicorn { - server unix:/home/web/jipe_app/shared/unicorn.sock fail_timeout=0; + server unix:/srv/www/web/jipe_app/shared/unicorn.sock fail_timeout=0; } @@ -7,9 +7,9 @@ upstream jipe_app_unicorn { server { - listen 80; - server_name jipe.fr jipe.quartz.xyz ; - root /home/web/jipe_app/current/public; + listen [::]:80; + server_name jipe.fr ; + root /srv/www/web/jipe_app/current/public; try_files $uri/index.html $uri @unicorn; location @unicorn { @@ -27,8 +27,8 @@ server { server { - listen 80; - server_name www.jipe.fr *.jipe.fr; + listen [::]:80; + server_name www.jipe.fr *.jipe.fr jipe.quartz.xyz; rewrite ^(.*) http://jipe.fr$1 permanent; } diff --git a/config/unicorn.rb b/config/unicorn.rb index e8ecbe8..b0840db 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,10 +1,10 @@ @rails_app = "jipe_app" -working_directory "/home/web/#{@rails_app}/current" -pid "/home/web/#{@rails_app}/shared/unicorn.pid" -stderr_path "/home/web/#{@rails_app}/shared/log/unicorn.log" -stdout_path "/home/web/#{@rails_app}/shared/log/unicorn.log" +working_directory "/srv/www/web/#{@rails_app}/current" +pid "/srv/www/web/#{@rails_app}/shared/unicorn.pid" +stderr_path "/srv/www/web/#{@rails_app}/shared/log/unicorn.log" +stdout_path "/srv/www/web/#{@rails_app}/shared/log/unicorn.log" -listen "/home/web/#{@rails_app}/shared/unicorn.sock" +listen "/srv/www/web/#{@rails_app}/shared/unicorn.sock" worker_processes 2 timeout 9999 \ No newline at end of file