這邊有兩種情境
一種就是一般的 ssh 登入的方式,例如 digital ocean , linode 之類的
這種就照原本knife-solo的做法就可以
knife solo bootstrap server-user-name@xx.xx.xx.xx
一種就是 AWS 那種要登入到 ec2 instance 的時候,我們的 local 的環境要有一把 xxxx.pem 檔案的私鑰
這一種就要打這個指令才有辦法讓 knife-solo 去免帳號密碼 遠端驅動 server site 執行 chef-solo
solo bootstrap xx.xx.xx.xx(server_ip) --ssh-user ubuntu -i ~/.ssh/your-pem-file-name.pem --node-name xx.xxx.xx.xx
接著請手動調整下列三個 config file
nginx config file, put it in the site-enable/default file
123456789101112131415161718192021222324
upstreamapp{# Path to Puma SOCK file, as defined previouslyserverunix:/home/ubuntu/site/app/app-name/current/shared/sockets/puma.sockfail_timeout=0;}server{listen80;server_namelocalhost;root/home/ubuntu/site/app/app-name/current/public;try_files$uri/index.html$uri@app;location@app{proxy_passhttp://app;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerHost$http_host;proxy_redirectoff;}error_page500502503504/500.html;client_max_body_size4G;keepalive_timeout10;}
puma config file in config/puma_production.rb
123456789101112131415
environment'production'threads2,64workers2#depends on how many cores of server CPUapplication_path=File.expand_path('..',__dir__)directoryapplication_pathpidfile"#{application_path}/shared/pids/puma.pid"state_path"#{application_path}/shared/sockets/puma.state"stdout_redirect"#{application_path}/shared/log/puma.stdout.log","#{application_path}/shared/log/puma.stderr.log"bind"unix://#{application_path}/shared/sockets/puma.sock"activate_control_app"unix://#{application_path}/shared/sockets/pumactl.sock"daemonizetruepreload_app!
Mina Setup 步驟執行之後注意事項
有三件事情要做:
1- 因為有兩個 config 檔案我們是做 symbolic link 到 shared folder “ shared/config ” 目錄裡面
所以記得要server 上手動增加 database.yml , secret.yml 檔案
2- 另外還有環境變數也記得手動到server去增加,以利後續 Rails production server 要讀取&啟動
3- 在 postgresql 手動 create production 的 database.
require'mina/bundler'require'mina/rails'require'mina/git'require'mina/rbenv'require'mina/puma'# Basic settings:# domain - The hostname to SSH to.# deploy_to - Path to deploy into.# repository - Git repo to clone from. (needed by mina/git)# branch - Branch name to deploy. (needed by mina/git)set:application_name,'production_app'set:domain,'192.168.99.99'set:user,'ubuntu'# Username in the server to SSH to.set:deploy_to,"/home/#{fetch(:user)}/site/app/#{fetch(:application_name)}"set:repository,'git@github.com:abcdefg/xyz.git'set:branch,'master'set:rbenv_path,"$HOME/.rbenv"set:database,'name_of_production'# shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step.set:shared_files,fetch(:shared_files,[]).push('config/database.yml','config/secrets.yml')set:shared_dirs,fetch(:shared_dirs,[]).push('shared/log','tmp/cache','shared/pids','shared/sockets','public','vendor')# This task is the environment that is loaded for all remote run commands, such as# `mina deploy` or `mina rake`.task:environmentdoinvoke:'rbenv:load'endtask:setupdoenddesc"Deploys the current version to the server."task:deploydodeploydo# Put things that will set up an empty directory into a fully set-up# instance of your project.invoke:'git:clone'invoke:'deploy:link_shared_paths'invoke:'bundle:install'invoke:'rails:db_migrate'invoke:'rails:assets_precompile'invoke:'deploy:cleanup'on:launchdoin_path(fetch(:current_path))docommand%{mkdir -p tmp/}command%{touch tmp/restart.txt}invoke:'puma_restart'endendend# you can use `run :local` to run tasks on local machine before of after the deploy scripts# run(:local){ say 'done' }endtaskpuma_restart::environmentdopuma_pid="#{fetch(:current_path)}/shared/pids/puma.pid"command%[ if [ -e '#{puma_pid}' ]; then bundle exec pumactl -F config/puma_production.rb stop bundle exec pumactl -F config/puma_production.rb start else bundle exec pumactl -F config/puma_production.rb start fi ]end# For help in making your deploy script, see the Mina documentation:# - https://github.com/mina-deploy/mina/tree/master/docs