forked from st8998/commitwall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCapfile
More file actions
83 lines (62 loc) · 2.32 KB
/
Capfile
File metadata and controls
83 lines (62 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
load 'deploy'
set :node_env, 'production'
set :branch, 'master'
set :application_port, '3001'
set :application, 'commitwall'
set :node_file, 'app.js'
set :host, '174.129.235.5'
set :repository, 'git@github.com:st8998/commitwall.git'
ssh_options[:keys] = [File.join(ENV['HOME'], '.ssh', 'loki.pem')]
ssh_options[:forward_agent] = true
set :user, 'ubuntu'
set :admin_runner, 'ubuntu'
set :scm, :git
set :deploy_via, :remote_cache
role :app, host
set :deploy_to, "/opt/apps/#{application}"
set :use_sudo, true
set :normalize_asset_timestamps, false
namespace :deploy do
task :start, :roles => :app, :except => {:no_release => true} do
run "sudo start #{application}"
end
task :stop, :roles => :app, :except => {:no_release => true} do
run "sudo stop #{application}"
end
task :restart, :roles => :app, :except => {:no_release => true} do
run "sudo restart #{application} || sudo start #{application}"
end
desc "Symlink lib files"
task :symlink_libs, :roles => :app do
run "mkdir -p #{shared_path}/node_modules"
run "ln -s #{shared_path}/node_modules #{release_path}/node_modules"
end
desc "Install dependency libs"
task :check_packages, :roles => :app do
run "cd #{release_path} && npm install -d"
end
task :create_deploy_to_with_sudo, :roles => :app do
run "sudo mkdir -p #{deploy_to}"
run "sudo chown #{admin_runner}:#{admin_runner} #{deploy_to}"
end
task :write_upstart_script, :roles => :app do
upstart_script = <<-UPSTART
description "#{application}"
start on startup
stop on shutdown
script
# We found $HOME is needed. Without it, we ran into problems
export HOME="/home/#{admin_runner}"
export NODE_ENV="#{node_env}"
cd #{current_path}
exec sudo -u #{admin_runner} sh -c "NODE_ENV=#{node_env} PORT=#{application_port} /usr/local/bin/node #{current_path}/#{node_file} >> #{shared_path}/log/#{node_env}.log 2>&1"
end script
respawn
UPSTART
put upstart_script, "/tmp/#{application}_upstart.conf"
run "sudo mv /tmp/#{application}_upstart.conf /etc/init/#{application}.conf"
end
end
before 'deploy:setup', 'deploy:create_deploy_to_with_sudo'
after 'deploy:setup', 'deploy:write_upstart_script'
after 'deploy:finalize_update', 'deploy:symlink_libs', 'deploy:check_packages', 'deploy:cleanup'