-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
223 lines (178 loc) · 4.8 KB
/
Rakefile
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# -*- mode: ruby -*-
# vi: set ft=ruby :
desc "default=up"
task :default do
Rake::Task["core:up"].invoke()
end
namespace :core do
desc "up"
task :up do
puts "up"
begin
sh "ssh-add -K ~/.ssh/id_rsa && vagrant up && vagrant ssh"
rescue
end
end
desc "halt"
task :halt do
begin
sh "vagrant halt"
rescue
end
end
desc "suspend"
task :suspend do
begin
sh "vagrant suspend"
rescue
end
end
desc "reload"
task :reload do
begin
sh "vagrant reload"
rescue
end
end
desc "up_rsync"
task :up_rsync do
begin
sh "ssh-add -K ~/.ssh/id_rsa && vagrant up"
sh "vagrant rsync-auto"
rescue
end
end
desc "ssh"
task :ssh do
begin
sh "vagrant ssh"
rescue
end
end
desc "destroy"
task :destroy do
begin
sh "vagrant destroy -f"
rescue
end
end
end
namespace :share do
desc "web"
task :web do
sh "vagrant login && vagrant share --http 80 --https 443"
end
desc "ssh"
task :ssh do
sh "vagrant login && vagrant share --ssh"
end
desc "all"
task :full do
sh "vagrant login && vagrant share --http 80 --https 443 --ssh"
end
end
namespace :environment do
desc "install vagrant dependencies"
task :install_dependencies_vagrant do
sh "vagrant plugin install vagrant-cachier --plugin-version '1.2.0'"
sh "vagrant plugin install vagrant-hostsupdater --plugin-version '0.0.11'"
sh "vagrant plugin install vagrant-omnibus --plugin-version '1.4.1'"
sh "vagrant plugin install vagrant-persistent-storage --plugin-version '0.0.16'"
sh "vagrant plugin install vagrant-reload --plugin-version '0.0.1'"
sh "vagrant plugin install vagrant-share --plugin-version '1.1.4'"
sh "vagrant plugin install vagrant-triggers --plugin-version '0.5.0'"
sh "vagrant plugin install vagrant-vbguest --plugin-version '0.10.0'"
end
end
namespace :maintenance do
desc "clear_logs"
task :clear_logs do
Rake::Task["core:up"].invoke()
sh "vagrant ssh --command 'sudo rm -rf /var/log/*'"
sh "vagrant ssh --command 'sudo mkdir /var/log/apache2 ; sudo mkdir /var/log/mysql'"
Rake::Task["core:reload"].invoke()
end
desc "restart_apache"
task :restart_apache do
sh "vagrant ssh --command 'sudo service apache restart'"
end
desc "restart_mysql"
task :restart_mysql do
sh "vagrant ssh --command 'sudo service mysql restart'"
end
desc "shrink"
task :shrink do
begin
require 'json'
load 'include/helper.rb'
vconfig = vagrant_get_config()
box_hostname = vconfig['config']['box_hostname'].split('.')[0]
rescue
LoadError
end
Rake::Task["core:up"].invoke()
Rake::Task["maintenance:clear_logs"].invoke()
begin
sh "vagrant ssh --command 'sudo cat /dev/zero > zero.fill'"
rescue
sh "vagrant ssh --command 'sudo sync;sleep 1;sudo sync;'"
sh "vagrant ssh --command 'sudo rm -f zero.fill'"
end
begin
Rake::Task["core:halt"].invoke()
sh "tar -cvzf ~/VirtualBox\\ VMs/"+ box_hostname + ".tar.gz ~/VirtualBox\\ VMs/"+ box_hostname
Rake::Task["core:up"].invoke()
sh "VBoxManage storageattach " + box_hostname + " --storagectl SATAController --port 0 --device 0 --type hdd --medium none"
sh "VBoxManage clonehd --format VDI ~/VirtualBox\\ VMs/"+ box_hostname +"/box-disk1.vmdk /tmp/box-disk1.vdi"
sh "VBoxManage closemedium disk ~/VirtualBox\\ VMs/"+ box_hostname +"/box-disk1.vmdk --delete"
sh "VBoxManage modifyhd /tmp/box-disk1.vdi --compact"
sh "VBoxManage clonehd --format vmdk /tmp/box-disk1.vdi ~/VirtualBox\\ VMs/"+ box_hostname +"/box-disk1.vmdk"
sh "VBoxManage closemedium disk /tmp/box-disk1.vdi --delete"
sh "VBoxManage storageattach " + box_hostname + " --storagectl SATAController --port 0 --device 0 --type hdd --medium ~/VirtualBox\\ VMs/"+ box_hostname +"/box-disk1.vmdk"
sh "rm -rf ~/VirtualBox\\ VMs/"+ box_hostname + ".tar.gz"
rescue
Rake::Task["core:halt"].invoke()
sh "tar -xvzf ~/VirtualBox\\ VMs/"+ box_hostname + ".tar.gz ~/VirtualBox\\ VMs/"+ box_hostname
end
Rake::Task["core:reload"].invoke()
end
end
namespace :emergency_fix do
desc "nfs"
task :nfs do
Rake::Task["core:halt"].invoke()
begin
sh "sudo rm -f /etc/exports"
rescue
end
begin
for i in 0..20
sh "vboxmanage hostonlyif remove vboxnet#{i}"
end
rescue
end
Rake::Task["core:up"].invoke()
begin
sh "vagrant hostsupdater"
rescue
end
end
desc "forcekill"
task :forcekill do
begin
begin
sh "sudo killall -9 vagrant"
rescue
end
begin
sh "sudo killall -9 VBoxHeadless"
rescue
end
begin
sh "sudo killall -9 ruby"
rescue
end
rescue
end
end
end