defmodule BookStore do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# Define workers and child supervisors to be supervised
# worker(BookStore.Worker, [arg1, arg2, arg3])
worker(BookStore.Repo, [])
]
BookStore.Router.start
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: BookStore.Supervisor]
Supervisor.start_link(children, opts)
end
end
require 'capistrano/ext/multistage'
set :stages, ["staging", "production"]
set :default_stage, "production"
set :keep_releases, 5
set :application, "My Awesome App"
set :repository, "git@github.com:learnelixir/my-awesome-app.git"
set :scm, :git
set :branch, :master
set :use_sudo, false
set :normalize_asset_timestamps, false
set :deploy_via, :remote_cache
after "deploy:update", "deploy:cleanup"
after "deploy:update", "deploy:build", "deploy:cleanup"
namespace :assets do
task :precompile, roles: :web do
# do nothing
end
end
def is_application_running?(current_path)
pid = capture(%Q{ps ax -o pid= -o command=|
grep "/home/app/www/book_store/current/rel/book_store/.*/[b]eam"|awk '{print $1}'})
return pid != ""
end
namespace :deploy do
task :is_running, roles: :web do
is_running = is_application_running?(current_path)
if is_running
puts "Application is running"
else
puts "Application is NOT running"
end
end
task :build, roles: :web do
run "cd #{current_path} && mix deps.get && MIX_ENV=#{mix_env} mix release"
end
task :restart, roles: :web do
if is_application_running?(current_path)
run "cd #{current_path}/rel/book_store/bin && ./book_store stop"
end
run "cd #{current_path}/rel/book_store/bin && ./book_store start"
end
task :start, roles: :web do
run "cd #{current_path}/rel/book_store/bin && ./book_store start"
end
task :stop, roles: :web do
run "cd #{current_path}/rel/book_store/bin && ./book_store stop"
end
end
步骤7: 创建production.rb
1
vim config/deploy/production.rb
内容如下
1
server "xx.xx.xx.xx", :app, :web, :db, :primary => true
set :user, '<user>'
set :branch, :master
set :mix_env, :prod
set :deploy_to, "/home/<user>/www/book_store"
set :default_environment, {
'PATH' => "$PATH:/home/app/src/elixir/bin" # --> replace by path to your elixir bin folder
}