-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsetup_config.cap
More file actions
70 lines (56 loc) · 2.85 KB
/
Copy pathsetup_config.cap
File metadata and controls
70 lines (56 loc) · 2.85 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
require 'capistrano/dsl'
require 'capistrano/cookbook/helpers/setup_config_values'
require 'capistrano/cookbook/helpers/substitute_strings'
require 'capistrano/cookbook/helpers/smart_template'
require 'capistrano/cookbook/nginx'
require 'capistrano/cookbook/monit'
require 'securerandom'
namespace :deploy do
task :setup_config do
conf = ::Capistrano::Cookbook::SetupConfigValues.new
on roles(:app) do
# make the config dir
execute :mkdir, "-p #{shared_path}/config"
execute :mkdir, "-p /home/#{fetch(:deploy_user)}/.config/systemd/user"
# config files to be uploaded to shared/config, see the
# definition of smart_template for details of operation.
conf.config_files.each do |file|
smart_template(file[:source], file[:destination], file[:as_root])
execute(:chmod, "+x #{file[:destination]}") if file[:executable]
end
# which of the above files should be marked as executable
# conf.executable_config_files.each do |file|
# execute :chmod, "+x #{shared_path}/config/#{file}"
# end
# symlink stuff which should be... symlinked
# conf.symlinks.each do |symlink|
# sudo "ln -nfs #{shared_path}/config/#{symlink[:source]} #{sub_strings(symlink[:link])}"
# end
if File.exists?(File.join('config', 'master.key'))
upload! File.join('config', 'master.key'), File.join(shared_path, 'config', 'master.key')
end
end
end
end
# remove the default nginx configuration as it will tend to conflict with our configs
before 'deploy:setup_config', 'nginx:remove_default_vhost'
# make sure that shared directories etc exist before running otherwise the
# initial nginx reload won't work because of the nginx log file directory path
# not existing
before 'deploy:setup_config', 'deploy:check:directories'
before 'deploy:setup_config', 'deploy:check:linked_dirs'
# After setup config has generated and setup initial files, run the Capistrano Puma
# tasks responsible for uploading config files. Note that `setup_config` creates overrides
# for these in `config/deploy/templates` so we're not using the default ones from the gem
after 'deploy:setup_config', 'puma:config'
after 'deploy:setup_config', 'puma:nginx_config'
after 'deploy:setup_config', 'puma:monit:config'
after 'deploy:setup_config', 'puma:systemd:config'
after 'deploy:setup_config', 'puma:systemd:enable'
after 'deploy:setup_config', 'certbot:install'
# Enable the sidekiq systemd service so that it's started automatically on (re)boot
after 'deploy:setup_config', 'sidekiq:systemd:enable' if (defined?(Capistrano::Sidekiq) == 'constant' && Capistrano::Sidekiq.class == Class)
# reload nginx to it will pick up any modified vhosts from setup_config
after 'deploy:setup_config', 'nginx:reload'
# Restart monit so it will pick up any monit configurations we've added
after 'deploy:setup_config', 'monit:reload'