magicmonkey 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/magicmonkey/app_servers/passenger.rb +1 -1
- data/lib/magicmonkey/app_servers/thin.rb +1 -1
- data/lib/magicmonkey/app_servers/unicorn_rails.rb +1 -1
- data/lib/magicmonkey/configuration.rb +2 -13
- data/lib/magicmonkey/magicmonkey.rb +53 -130
- data/lib/magicmonkey/version.rb +1 -1
- metadata +24 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d62a15ccec8260c8fb74146f164e5c2c11eb6fb0
|
4
|
+
data.tar.gz: 961b1e9cf089ee7b6ac8039a65259a5a4b662c92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1da5ad79b0ae7a1ba7132b689142e1f5d927ffc3286dadd5a2117ccb4a110cd29b62c033af8716b3b6d1f517e078a9bd9b16ebb439dca73e7ef6b0d12e977fbb
|
7
|
+
data.tar.gz: f41c8009ac15c5ed3933b159444aebc92ae5e6a471d06088d3578481567a9769c576a6f218beaeb54b233d0add7f53f823eb6f3c1529e624c8e123fce28420ae
|
@@ -5,7 +5,7 @@ module UnicornRails
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.stop(args = {})
|
8
|
-
["kill `ps ax | grep -v grep | grep -e 'unicorn_rails .*-p #{args[:port]}' | awk 'NR==1{print $1}'`"]
|
8
|
+
["kill `ps ax | grep -v grep | grep -e 'unicorn_rails .*-p #{args[:port]}' | awk 'NR==1{print $1}'` || true"]
|
9
9
|
end
|
10
10
|
|
11
11
|
end
|
@@ -5,26 +5,15 @@ class Conf
|
|
5
5
|
include Singleton
|
6
6
|
attr_reader :config
|
7
7
|
|
8
|
-
VHT = <<EOT
|
9
|
-
<VirtualHost *:80>
|
10
|
-
ServerName $SERVER_NAME
|
11
|
-
ProxyPass / http://127.0.0.1:$PORT/
|
12
|
-
ProxyPassReverse / http://127.0.0.1:$PORT/
|
13
|
-
</VirtualHost>
|
14
|
-
EOT
|
15
|
-
|
16
8
|
DEFAULT = {
|
17
9
|
:app_server => nil,
|
18
10
|
:app_server_options => nil,
|
19
11
|
:ruby => 'default',
|
20
12
|
:app_path => '/var/sites/$APP/current',
|
21
13
|
:bundle_exec => true,
|
22
|
-
:vhost_template => VHT,
|
23
|
-
:vhost_path => '/etc/apache2/sites-available',
|
24
14
|
:overwrite_file => false,
|
25
|
-
:enable_site => false,
|
26
|
-
:reload_apache => false,
|
27
15
|
:editor => 'nano',
|
16
|
+
:enabled => true,
|
28
17
|
:verbose => false
|
29
18
|
}
|
30
19
|
|
@@ -64,7 +53,7 @@ EOT
|
|
64
53
|
end
|
65
54
|
|
66
55
|
def self.applications
|
67
|
-
Conf.instance.config.keys.select{|k| ![:default, :uid].include?(k)}
|
56
|
+
apps = Conf.instance.config.keys.select{|k| ![:default, :uid].include?(k)}
|
68
57
|
end
|
69
58
|
|
70
59
|
def self.ports
|
@@ -11,7 +11,7 @@ module Magicmonkey
|
|
11
11
|
|
12
12
|
@o = {}
|
13
13
|
|
14
|
-
COMMANDS = %w(configure deconfigure show vhost start stop restart)
|
14
|
+
COMMANDS = %w(configure deconfigure enable disable show vhost start stop restart)
|
15
15
|
|
16
16
|
def self.main
|
17
17
|
#Process::UID.change_privilege(Conf[:uid] || Process.uid)
|
@@ -88,6 +88,28 @@ module Magicmonkey
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
##################
|
92
|
+
# ENABLE COMMAND #
|
93
|
+
##################
|
94
|
+
def self.enable(args)
|
95
|
+
applications = help2('enable', 'Enable the selected applications', args)
|
96
|
+
applications.each do |app|
|
97
|
+
Conf[app][:enabled] = true
|
98
|
+
end
|
99
|
+
Conf.save
|
100
|
+
end
|
101
|
+
|
102
|
+
###################
|
103
|
+
# DISABLE COMMAND #
|
104
|
+
###################
|
105
|
+
def self.disable(args)
|
106
|
+
applications = help2('disable', 'Disable the selected applications', args)
|
107
|
+
applications.each do |app|
|
108
|
+
Conf[app][:enabled] = false
|
109
|
+
end
|
110
|
+
Conf.save
|
111
|
+
end
|
112
|
+
|
91
113
|
################
|
92
114
|
# SHOW COMMAND #
|
93
115
|
################
|
@@ -100,139 +122,32 @@ module Magicmonkey
|
|
100
122
|
end
|
101
123
|
end
|
102
124
|
|
103
|
-
#################
|
104
|
-
# VHOST COMMAND #
|
105
|
-
#################
|
106
|
-
def self.vhost(args)
|
107
|
-
app = self.help('vhost', 'Creates the Apache virtual host file for an application.', args) do |opts|
|
108
|
-
opts.on('-s', '--server-name SERVER_NAME', 'The server name') do |s|
|
109
|
-
@o[:server_name] = s
|
110
|
-
end
|
111
|
-
opts.on('--path VHOST_PATH', "Use the given virtual host path (default: '#{@o[:vhost_path]}')") do |path|
|
112
|
-
@o[:vhost_path] = path
|
113
|
-
end
|
114
|
-
opts.on('-f', '--[no-]overwrite-file', "Replace exist file (default: #{@o[:overwrite_file]})") do |f|
|
115
|
-
@o[:overwrite_file] = f
|
116
|
-
end
|
117
|
-
opts.on('--[no-]enable-site', "Enable Apache virtual host (default: #{@o[:enable_site]})") do |e|
|
118
|
-
@o[:enable_site] = e
|
119
|
-
end
|
120
|
-
opts.on('--[no-]reload-apache', "Reload apache to load virtual host (default: #{@o[:reload_apache]})") do |r|
|
121
|
-
@o[:reload_apache] = r
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
app_conf = Conf[app.to_sym]
|
126
|
-
unless app_conf
|
127
|
-
rputs "Application '#{app}' does not configured."
|
128
|
-
puts "Use 'magicmonkey configure #{app}' to configure it."
|
129
|
-
exit
|
130
|
-
end
|
131
|
-
|
132
|
-
@o[:vhost_template].gsub!('$SERVER_NAME', @o[:server_name] || app)
|
133
|
-
@o[:vhost_template].gsub!('$PORT', app_conf[:port].to_s)
|
134
|
-
|
135
|
-
vh_file = File.join(@o[:vhost_path], app)
|
136
|
-
if (!File.exist?(vh_file) || @o[:overwrite_file])
|
137
|
-
begin
|
138
|
-
Cocaine::CommandLine.new("sudo echo '#{@o[:vhost_template]}' > '#{vh_file}'").run
|
139
|
-
rescue Cocaine::ExitStatusError => e
|
140
|
-
rputs 'Failed to write virtual host file.'
|
141
|
-
end
|
142
|
-
else
|
143
|
-
rputs 'Failed to write virtual host file.'
|
144
|
-
puts "Virtual host file '#{vh_file}' already exist. Use option '-f' to replace it."
|
145
|
-
end
|
146
|
-
if @o[:enable_site]
|
147
|
-
begin
|
148
|
-
Cocaine::CommandLine.new("sudo a2ensite '#{app}'").run
|
149
|
-
rescue Cocaine::ExitStatusError => e
|
150
|
-
rputs 'Failed to enable the site.'
|
151
|
-
end
|
152
|
-
end
|
153
|
-
if @o[:enable_site] && @o[:reload_apache]
|
154
|
-
begin
|
155
|
-
Cocaine::CommandLine.new('sudo /etc/init.d/apache2 reload').run
|
156
|
-
rescue Cocaine::ExitStatusError => e
|
157
|
-
rputs 'Failed to reload Apache.'
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
125
|
#################
|
163
126
|
# START COMMAND #
|
164
127
|
#################
|
165
128
|
def self.start(args)
|
166
|
-
|
167
|
-
applications.each do |app|
|
168
|
-
app_conf = Conf[app.to_sym]
|
169
|
-
unless app_conf
|
170
|
-
rputs "Application '#{app}' does not configured."
|
171
|
-
puts "Use 'magicmonkey configure #{app}' to configure it."
|
172
|
-
exit
|
173
|
-
end
|
174
|
-
check_ruby_version!(app_conf[:ruby])
|
175
|
-
server = check_app_server!(app_conf[:app_server])
|
176
|
-
lines = []
|
177
|
-
lines << "source '#{Dir.home}/.rvm/scripts/rvm'"
|
178
|
-
lines << "rvm use #{app_conf[:ruby]}"
|
179
|
-
lines += server.start(app_conf)
|
180
|
-
command = "bash -c \"#{lines.join(' && ')}\""
|
181
|
-
if app_conf[:bundle_exec]
|
182
|
-
command.gsub!(" && #{app_conf[:app_server]} ", " && bundle exec #{app_conf[:app_server]} ")
|
183
|
-
end
|
184
|
-
begin
|
185
|
-
print "Calling #{bold}start#{reset} for '#{app}' application..."
|
186
|
-
Dir.chdir(app_conf[:app_path]) do
|
187
|
-
Cocaine::CommandLine.new(command).run
|
188
|
-
end
|
189
|
-
puts " #{green}#{bold}done#{reset}."
|
190
|
-
rescue Cocaine::ExitStatusError => e
|
191
|
-
rputs "Failed to start application '#{app}'"
|
192
|
-
end
|
193
|
-
end
|
129
|
+
self.run('start', args)
|
194
130
|
end
|
195
131
|
|
196
132
|
################
|
197
133
|
# STOP COMMAND #
|
198
134
|
################
|
199
135
|
def self.stop(args)
|
200
|
-
|
201
|
-
applications.each do |app|
|
202
|
-
app_conf = Conf[app.to_sym]
|
203
|
-
unless app_conf
|
204
|
-
rputs "Application '#{app}' does not configured."
|
205
|
-
puts "Use 'magicmonkey configure #{app}' to configure it."
|
206
|
-
exit
|
207
|
-
end
|
208
|
-
check_ruby_version!(app_conf[:ruby])
|
209
|
-
server = check_app_server!(app_conf[:app_server])
|
210
|
-
lines = []
|
211
|
-
lines << "source '#{Dir.home}/.rvm/scripts/rvm'"
|
212
|
-
lines << "rvm use #{app_conf[:ruby]}"
|
213
|
-
lines += server.stop(app_conf)
|
214
|
-
command = "bash -c \"#{lines.join(' && ')}\""
|
215
|
-
if app_conf[:bundle_exec]
|
216
|
-
command.gsub!(" && #{app_conf[:app_server]} ", " && bundle exec #{app_conf[:app_server]} ")
|
217
|
-
end
|
218
|
-
begin
|
219
|
-
print "Calling #{bold}stop#{reset} for '#{app}' application..."
|
220
|
-
Dir.chdir(app_conf[:app_path]) do
|
221
|
-
Cocaine::CommandLine.new(command).run
|
222
|
-
end
|
223
|
-
puts " #{green}#{bold}done#{reset}."
|
224
|
-
rescue Cocaine::ExitStatusError => e
|
225
|
-
rputs "Failed to stop application '#{app}'"
|
226
|
-
end
|
227
|
-
end
|
136
|
+
self.run('stop', args)
|
228
137
|
end
|
229
138
|
|
230
139
|
###################
|
231
140
|
# RESTART COMMAND #
|
232
141
|
###################
|
233
142
|
def self.restart(args)
|
234
|
-
|
235
|
-
|
143
|
+
self.run('restart', args)
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
def self.run(action, args)
|
149
|
+
applications = help2(action, "#{action.capitalize} the selected applications.", args)
|
150
|
+
applications.select{|k| Conf[k.to_sym][:enabled]}.each do |app|
|
236
151
|
app_conf = Conf[app.to_sym]
|
237
152
|
unless app_conf
|
238
153
|
rputs "Application '#{app}' does not configured."
|
@@ -241,29 +156,37 @@ module Magicmonkey
|
|
241
156
|
end
|
242
157
|
check_ruby_version!(app_conf[:ruby])
|
243
158
|
server = check_app_server!(app_conf[:app_server])
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
command = "bash -c \"#{lines.join(' && ')}\""
|
251
|
-
if app_conf[:bundle_exec]
|
252
|
-
command.gsub!(" && #{app_conf[:app_server]} ", " && bundle exec #{app_conf[:app_server]} ")
|
159
|
+
command = self.build_command(app) do
|
160
|
+
if action == 'restart'
|
161
|
+
[server.stop(app_conf), 'sleep 3', server.start(app_conf)]
|
162
|
+
else
|
163
|
+
server.send(action, app_conf)
|
164
|
+
end
|
253
165
|
end
|
254
166
|
begin
|
255
|
-
print "Calling #{bold}
|
167
|
+
print "Calling #{bold}#{action}#{reset} for '#{app}' application..."
|
256
168
|
Dir.chdir(app_conf[:app_path]) do
|
257
169
|
Cocaine::CommandLine.new(command).run
|
258
170
|
end
|
259
171
|
puts " #{green}#{bold}done#{reset}."
|
260
172
|
rescue Cocaine::ExitStatusError => e
|
261
|
-
rputs "Failed to
|
173
|
+
rputs "Failed to #{action} application '#{app}'"
|
262
174
|
end
|
263
175
|
end
|
264
176
|
end
|
265
177
|
|
266
|
-
|
178
|
+
def self.build_command(app)
|
179
|
+
app_conf = Conf[app.to_sym]
|
180
|
+
lines = []
|
181
|
+
lines << "source '#{Dir.home}/.rvm/scripts/rvm'"
|
182
|
+
lines << "rvm use #{app_conf[:ruby]}"
|
183
|
+
lines += yield if block_given?
|
184
|
+
command = "bash -c \"#{lines.join(' && ')}\""
|
185
|
+
if app_conf[:bundle_exec]
|
186
|
+
command.gsub!(" && #{app_conf[:app_server]} ", " && bundle exec #{app_conf[:app_server]} ")
|
187
|
+
end
|
188
|
+
return command
|
189
|
+
end
|
267
190
|
|
268
191
|
def self.check_port!(port)
|
269
192
|
if Conf.ports.include?(port)
|
data/lib/magicmonkey/version.rb
CHANGED
metadata
CHANGED
@@ -1,39 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magicmonkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Enrico Pilotto
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: cocaine
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: term-ansicolor
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: 'Manage your Rails applications: different Ruby versions and different
|
37
42
|
application servers.'
|
38
43
|
email:
|
39
44
|
- enrico@megiston.it
|
@@ -59,29 +64,28 @@ files:
|
|
59
64
|
- test/test_magic_monkey.rb
|
60
65
|
homepage: https://github.com/pioz/magicmonkey
|
61
66
|
licenses: []
|
67
|
+
metadata: {}
|
62
68
|
post_install_message:
|
63
69
|
rdoc_options: []
|
64
70
|
require_paths:
|
65
71
|
- lib
|
66
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
73
|
requirements:
|
69
|
-
- -
|
74
|
+
- - '>='
|
70
75
|
- !ruby/object:Gem::Version
|
71
76
|
version: '0'
|
72
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
78
|
requirements:
|
75
|
-
- -
|
79
|
+
- - '>='
|
76
80
|
- !ruby/object:Gem::Version
|
77
81
|
version: '0'
|
78
82
|
requirements: []
|
79
83
|
rubyforge_project: magicmonkey
|
80
|
-
rubygems_version:
|
84
|
+
rubygems_version: 2.0.3
|
81
85
|
signing_key:
|
82
|
-
specification_version:
|
83
|
-
summary:
|
84
|
-
|
86
|
+
specification_version: 4
|
87
|
+
summary: 'Manage your Rails applications: different Ruby versions and different application
|
88
|
+
servers'
|
85
89
|
test_files:
|
86
90
|
- test/helper.rb
|
87
91
|
- test/test_magic_monkey.rb
|