From eb19552544b1ffc906bcc8cc697d9c5f9ef5a13f Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Tue, 23 Jul 2019 17:01:20 +0200 Subject: [PATCH] mise en ligne nouveau serveur --- config/deploy.rb | 80 +++++++++++++--------- config/deploy.rb.old | 138 ++++++++++++++++++++++++++++++++++++++ config/env_init | 6 ++ config/nginx.conf | 83 +++++++++-------------- config/nginx.conf.old | 64 ++++++++++++++++++ config/unicorn.rb | 12 ++-- config/unicorn.rb.old | 10 +++ config/unicorn_init_d | 2 +- config/unicorn_init_d.old | 64 ++++++++++++++++++ 9 files changed, 368 insertions(+), 91 deletions(-) create mode 100644 config/deploy.rb.old create mode 100644 config/env_init create mode 100644 config/nginx.conf.old create mode 100644 config/unicorn.rb.old mode change 100644 => 100755 config/unicorn_init_d create mode 100755 config/unicorn_init_d.old diff --git a/config/deploy.rb b/config/deploy.rb index 0fa4df4..4037408 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,26 +1,25 @@ - - +set :rvm_ruby_string, 'ruby-2.0.0-p195' set :application, 'blog_eft_app' - set :domain, 'blog.technique-eft.com' +set :domain, 'quartz-www02.sysnove.net' + + set :user, 'web' set :scm_user, "git" -set :scm_host, "git.nicolasbally.com" +set :scm_host, "quartz.snlab.fr" - - -set :rvm_ruby_string, 'ruby-2.0.0-p195' + 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 :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_to, "/srv/www/#{user}/#{application}/" set :deploy_via, :remote_cache set :normalize_asset_timestamps, false @@ -33,7 +32,7 @@ role :db, domain, :primary => true set :scm, :git -set :repository, "#{scm_user}@#{scm_host}:root/#{application}.git" +set :repository, "#{scm_user}@#{scm_host}:nicolas/#{application}.git" set :branch, "master" @@ -49,7 +48,7 @@ require 'bundler/capistrano' load 'deploy/assets' namespace :deploy do - + # namespace :assets do # task :precompile, :roles => :web, :except => { :no_release => true } do # from = source.next_revision(current_revision) @@ -60,42 +59,47 @@ namespace :deploy do # 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/unicorn_init_d /etc/init.d/#{application}" - - sudo "chmod +x /etc/init.d/#{application}" - sudo "update-rc.d #{application} defaults " + + sudo "cp #{current_path}/config/env_init #{deploy_to}env_init" + + sudo "sudo systemctl enable quartz_app@#{application}" + + + + end task :start do - sudo "service #{application} start" + sudo "systemctl start quartz_app@#{application}" end task :stop do - run "service #{application} stop" + sudo "systemctl stop quartz_app@#{application}" end task :restart do - sudo "service #{application} restart" + 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 @@ -105,24 +109,24 @@ namespace :deploy 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" @@ -135,4 +139,14 @@ before "deploy:restart", "deploy:symlink_config_files" after "deploy", "deploy:cleanup" - \ No newline at end of file + + + + + + + + + + + \ No newline at end of file diff --git a/config/deploy.rb.old b/config/deploy.rb.old new file mode 100644 index 0000000..0fa4df4 --- /dev/null +++ b/config/deploy.rb.old @@ -0,0 +1,138 @@ + + +set :application, 'blog_eft_app' + set :domain, 'blog.technique-eft.com' + +set :user, 'web' +set :scm_user, "git" +set :scm_host, "git.nicolasbally.com" + + + +set :rvm_ruby_string, 'ruby-2.0.0-p195' +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 :deploy_to, "/home/#{user}/#{application}/" +set :deploy_via, :remote_cache + +set :normalize_asset_timestamps, false + +set :rails_env, "production" + +role :app, domain +role :web, domain +role :db, domain, :primary => true + +set :scm, :git + +set :repository, "#{scm_user}@#{scm_host}:root/#{application}.git" + +set :branch, "master" + +default_run_options[:pty] = true + + +require "rvm/capistrano" +require 'bundler/capistrano' + + + + +load 'deploy/assets' + +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/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 + + + +after "deploy:setup", "deploy:create_files_folders" + +#after "deploy:restart", "deploy:cleanup" + + +before "deploy:restart", "deploy:symlink_config_files" + +after "deploy", "deploy:cleanup" + + + \ No newline at end of file diff --git a/config/env_init b/config/env_init new file mode 100644 index 0000000..fe6fc3f --- /dev/null +++ b/config/env_init @@ -0,0 +1,6 @@ +APP_RUBY=2.0.0-p195 +ENV=production +APP_ROOT=/srv/www/web/blog_eft_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 d922ca7..a6b3de4 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -1,64 +1,45 @@ upstream blog_eft_app_unicorn { - server unix:/home/web/blog_eft_app/shared/unicorn.sock fail_timeout=0; + server unix:/srv/www/web/blog_eft_app/shared/unicorn.sock fail_timeout=0; } -server { - listen 80; - server_name blogeft.bally.me ; - root /home/web/blog_eft_app/current/public; - try_files $uri/index.html $uri @unicorn; - location @unicorn { - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://blog_eft_app_unicorn; - proxy_read_timeout 6000; - } - - error_page 500 502 503 504 /500.html; - client_max_body_size 4G; - keepalive_timeout 10; -} - -server { - listen 80; - server_name blog.technique-eft.com www.blog.technique-eft.com; - rewrite ^(.*) https://blog.technique-eft.com$1 permanent; -} server { + listen [::]:443 ssl; + server_name blog.technique-eft.com; + root /srv/www/web/blog_eft_app/current/public; + try_files $uri/index.html $uri @unicorn; - listen 443 ssl; + location @unicorn { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://blog_eft_app_unicorn; + proxy_read_timeout 6000; + } - server_name blog.technique-eft.com; - root /home/web/blog_eft_app/current/public; - - ssl on; - ssl_certificate /etc/letsencrypt/live/blog.technique-eft.com/fullchain.pem; # managed by Certbot - ssl_certificate_key /etc/letsencrypt/live/blog.technique-eft.com/privkey.pem; # managed by Certbot - - - try_files $uri/index.html $uri @unicorn; - - #access_log /var/log/nginx/YOUR_APP_NAME_access.log combined; - #error_log /var/log/nginx/YOUR_APP_NAME_error.log; - - location @unicorn { - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://blog_eft_app_unicorn; - proxy_set_header X-Forwarded-Proto https; - } - - error_page 500 502 503 504 /500.html; - client_max_body_size 4G; - keepalive_timeout 10; - - include snippets/letsencrypt.conf; + error_page 500 502 503 504 /500.html; + client_max_body_size 4G; + keepalive_timeout 10; + + ssl on; + ssl_certificate /etc/letsencrypt/live/blog.technique-eft.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/blog.technique-eft.com/privkey.pem; + + + include snippets/letsencrypt.conf; +} + + +server { + listen [::]:80; + server_name blog.technique-eft.com *.blog.technique-eft.com; + + return 301 https://blog.technique-eft.com$request_uri; + + include snippets/letsencrypt.conf; } diff --git a/config/nginx.conf.old b/config/nginx.conf.old new file mode 100644 index 0000000..d922ca7 --- /dev/null +++ b/config/nginx.conf.old @@ -0,0 +1,64 @@ +upstream blog_eft_app_unicorn { + server unix:/home/web/blog_eft_app/shared/unicorn.sock fail_timeout=0; +} + +server { + listen 80; + server_name blogeft.bally.me ; + root /home/web/blog_eft_app/current/public; + try_files $uri/index.html $uri @unicorn; + + location @unicorn { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://blog_eft_app_unicorn; + proxy_read_timeout 6000; + } + + error_page 500 502 503 504 /500.html; + client_max_body_size 4G; + keepalive_timeout 10; +} + +server { + listen 80; + server_name blog.technique-eft.com www.blog.technique-eft.com; + rewrite ^(.*) https://blog.technique-eft.com$1 permanent; +} + + + + +server { + + listen 443 ssl; + + server_name blog.technique-eft.com; + root /home/web/blog_eft_app/current/public; + + ssl on; + ssl_certificate /etc/letsencrypt/live/blog.technique-eft.com/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/blog.technique-eft.com/privkey.pem; # managed by Certbot + + + try_files $uri/index.html $uri @unicorn; + + #access_log /var/log/nginx/YOUR_APP_NAME_access.log combined; + #error_log /var/log/nginx/YOUR_APP_NAME_error.log; + + location @unicorn { + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://blog_eft_app_unicorn; + proxy_set_header X-Forwarded-Proto https; + } + + error_page 500 502 503 504 /500.html; + client_max_body_size 4G; + keepalive_timeout 10; + + include snippets/letsencrypt.conf; +} + diff --git a/config/unicorn.rb b/config/unicorn.rb index 5dadccd..2efc11b 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,10 +1,10 @@ @rails_app = "blog_eft_app" -working_directory "/home/web/#{@rails_app}/current" -pid "/home/web/#{@rails_app}/shared/unicorn.pid" -stderr_path "/home/web/#{@rails_app}/shared/unicorn.log" -stdout_path "/home/web/#{@rails_app}/shared/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 600 \ No newline at end of file +timeout 9999 \ No newline at end of file diff --git a/config/unicorn.rb.old b/config/unicorn.rb.old new file mode 100644 index 0000000..5dadccd --- /dev/null +++ b/config/unicorn.rb.old @@ -0,0 +1,10 @@ +@rails_app = "blog_eft_app" + +working_directory "/home/web/#{@rails_app}/current" +pid "/home/web/#{@rails_app}/shared/unicorn.pid" +stderr_path "/home/web/#{@rails_app}/shared/unicorn.log" +stdout_path "/home/web/#{@rails_app}/shared/unicorn.log" + +listen "/home/web/#{@rails_app}/shared/unicorn.sock" +worker_processes 2 +timeout 600 \ No newline at end of file diff --git a/config/unicorn_init_d b/config/unicorn_init_d old mode 100644 new mode 100755 index 1729dba..7e5a16a --- a/config/unicorn_init_d +++ b/config/unicorn_init_d @@ -61,4 +61,4 @@ case ${1-help} in echo >&2 "Usage: $0 " exit 1 ;; -esac \ No newline at end of file +esac \ No newline at end of file diff --git a/config/unicorn_init_d.old b/config/unicorn_init_d.old new file mode 100755 index 0000000..1729dba --- /dev/null +++ b/config/unicorn_init_d.old @@ -0,0 +1,64 @@ +#!/bin/bash + + +set -u +set -e + +# Change these to match your app: +APP_NAME=blog_eft_app +APP_RUBY=2.0.0-p195 +APP_ROOT="/home/web/blog_eft_app/current" +PID="/home/web/blog_eft_app/shared/unicorn.pid" +ENV=production + +GEM_HOME="/home/web/.rvm/gems/ruby-$APP_RUBY" + +UNICORN_OPTS="-D -E $ENV -c $APP_ROOT/config/unicorn.rb" + +SET_PATH="cd $APP_ROOT; rvm $APP_RUBY" +CMD="$SET_PATH; unicorn $UNICORN_OPTS" + +old_pid="$PID.oldbin" + +cd $APP_ROOT || exit 1 + +sig () { + test -s "$PID" && kill -$1 `cat $PID` +} + +oldsig () { + test -s $old_pid && kill -$1 `cat $old_pid` +} + +case ${1-help} in + start) + sig 0 && echo >&2 "Already running" && exit 0 + su - web -c "$CMD" + ;; + stop) + sig QUIT && exit 0 + echo >&2 "Not running" + ;; + force-stop) + sig TERM && exit 0 + echo >&2 "Not running" + ;; + restart|reload) + sig HUP && echo reloaded OK && exit 0 + echo >&2 "Couldn't reload, starting '$CMD' instead" + su - web -c "$CMD" + ;; + upgrade) + sig USR2 && exit 0 + echo >&2 "Couldn't upgrade, starting '$CMD' instead" + su - web -c "$CMD" + ;; + rotate) + sig USR1 && echo rotated logs OK && exit 0 + echo >&2 "Couldn't rotate logs" && exit 1 + ;; + *) + echo >&2 "Usage: $0 " + exit 1 + ;; +esac \ No newline at end of file