magicmonkey 1.0.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +7 -8
- data/bin/magicmonkey +1 -1
- data/lib/magicmonkey/app_servers/passenger.rb +2 -8
- data/lib/magicmonkey/app_servers/thin.rb +2 -8
- data/lib/magicmonkey/app_servers/unicorn_rails.rb +11 -0
- data/lib/magicmonkey/configuration.rb +5 -6
- data/lib/magicmonkey/magicmonkey.rb +258 -224
- data/lib/magicmonkey/version.rb +1 -1
- metadata +7 -6
data/README.rdoc
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
= Magicmonkey
|
2
2
|
|
3
|
-
Magicmonkey is a useful script that can manage your Ruby on Rails applications.
|
4
|
-
Magicmonkey allows
|
5
|
-
|
3
|
+
Magicmonkey is a useful script that can help you to manage your Ruby on Rails applications.
|
4
|
+
Magicmonkey allows to build in easy way the follow web server architecture:
|
6
5
|
|
7
6
|
+---------------------------------------------------------------------------------------------------+
|
8
7
|
| Apache web server |
|
@@ -29,7 +28,7 @@ Every your web applications have a virtual host like this:
|
|
29
28
|
ProxyPassReverse / http://127.0.0.1:3000/
|
30
29
|
</VirtualHost>
|
31
30
|
|
32
|
-
A proxy that speak with an application server standalone mode (like Phusion Passenger v3) that run with a specific Ruby version.
|
31
|
+
A proxy that speak with an application server in standalone mode (like Phusion Passenger v3) that run with a specific Ruby version.
|
33
32
|
To do this you need to have install RVM to manage multiply Ruby versions.
|
34
33
|
|
35
34
|
== Install
|
@@ -38,15 +37,15 @@ To do this you need to have install RVM to manage multiply Ruby versions.
|
|
38
37
|
|
39
38
|
== Usage
|
40
39
|
|
41
|
-
First of all you need to
|
40
|
+
First of all you need to configure an application. To to this use the magicmonkey command 'configure':
|
42
41
|
|
43
|
-
magicmonkey
|
42
|
+
magicmonkey configure APP_NAME [options]
|
44
43
|
|
45
|
-
When
|
44
|
+
When configured, you can start, stop, restart the application
|
46
45
|
|
47
46
|
magicmonkey {start|stop|restart} APP_NAME1, APP_NAME2, ...
|
48
47
|
|
49
|
-
If no application is given start, stop, restart all
|
48
|
+
If no application is given start, stop, restart all applications.
|
50
49
|
|
51
50
|
You can show the configuration of all your applications with
|
52
51
|
|
data/bin/magicmonkey
CHANGED
@@ -1,17 +1,11 @@
|
|
1
1
|
module Passenger
|
2
2
|
|
3
3
|
def self.start(args = {})
|
4
|
-
|
5
|
-
return "#{bundle_exec}passenger start -e production -p #{args[:port]} #{args[:app_server_options]} -d"
|
4
|
+
["passenger start -e production -p #{args[:port]} #{args[:app_server_options]} -d"]
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.stop(args = {})
|
9
|
-
|
10
|
-
return "#{bundle_exec}passenger stop -p #{args[:port]}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.restart(args = {})
|
14
|
-
[self.stop(args), 'sleep 3', self.start(args)]
|
8
|
+
["passenger stop -p #{args[:port]}"]
|
15
9
|
end
|
16
10
|
|
17
11
|
end
|
@@ -1,17 +1,11 @@
|
|
1
1
|
module Thin
|
2
2
|
|
3
3
|
def self.start(args = {})
|
4
|
-
|
5
|
-
return "#{bundle_exec}thin start -e production -p #{args[:port]} #{args[:app_server_options]} -d"
|
4
|
+
["thin start -e production -p #{args[:port]} #{args[:app_server_options]} -d"]
|
6
5
|
end
|
7
6
|
|
8
7
|
def self.stop(args = {})
|
9
|
-
|
10
|
-
return "#{bundle_exec}thin stop -p #{args[:port]}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.restart(args = {})
|
14
|
-
[self.stop(args), 'sleep 3', self.start(args)]
|
8
|
+
["thin stop -p #{args[:port]}"]
|
15
9
|
end
|
16
10
|
|
17
11
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module UnicornRails
|
2
|
+
|
3
|
+
def self.start(args = {})
|
4
|
+
["unicorn_rails -E production -p #{args[:port]} -c #{args[:app_path]}/config/unicorn.rb #{args[:app_server_options]} -D"]
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.stop(args = {})
|
8
|
+
["kill `ps ax | grep -v grep | grep -e 'unicorn_rails .*-p #{args[:port]}' | awk 'NR==1{print $1}'`"]
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -16,17 +16,16 @@ EOT
|
|
16
16
|
DEFAULT = {
|
17
17
|
:app_server => nil,
|
18
18
|
:app_server_options => nil,
|
19
|
-
:port => nil,
|
20
19
|
:ruby => 'default',
|
21
|
-
:app_path => '/var/sites/$
|
22
|
-
:
|
20
|
+
:app_path => '/var/sites/$APP/current',
|
21
|
+
:bundle_exec => true,
|
23
22
|
:vhost_template => VHT,
|
24
23
|
:vhost_path => '/etc/apache2/sites-available',
|
25
|
-
:
|
26
|
-
:create_vhost => true,
|
24
|
+
:overwrite_file => false,
|
27
25
|
:enable_site => false,
|
28
26
|
:reload_apache => false,
|
29
|
-
:
|
27
|
+
:editor => 'nano',
|
28
|
+
:verbose => false
|
30
29
|
}
|
31
30
|
|
32
31
|
def initialize
|
@@ -1,26 +1,29 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
require 'pp'
|
3
|
+
require 'tempfile'
|
3
4
|
require 'cocaine'
|
4
5
|
require 'term/ansicolor'
|
5
6
|
require "#{$APP_PATH}/lib/magicmonkey/version"
|
6
7
|
require "#{$APP_PATH}/lib/magicmonkey/configuration"
|
7
8
|
include Term::ANSIColor
|
8
9
|
|
9
|
-
module
|
10
|
+
module Magicmonkey
|
10
11
|
|
11
|
-
|
12
|
+
@o = {}
|
13
|
+
|
14
|
+
COMMANDS = %w(configure deconfigure show vhost start stop restart)
|
12
15
|
|
13
16
|
def self.main
|
14
17
|
#Process::UID.change_privilege(Conf[:uid] || Process.uid)
|
15
18
|
raise 'You cannot do this as root' if Process.uid == 0
|
16
19
|
|
17
|
-
|
20
|
+
@o = Marshal.load(Marshal.dump(Conf[:default]))
|
18
21
|
parser = OptionParser.new do |opts|
|
19
22
|
opts.banner = 'Usage: magicmonkey <command> [<args>]'
|
20
23
|
opts.separator ''
|
21
24
|
opts.separator "Commands: #{COMMANDS.join(' ')}"
|
22
25
|
opts.separator 'For more information about a specific command, please type'
|
23
|
-
opts.separator "'magicmonkey <command> --help', e.g. 'magicmonkey
|
26
|
+
opts.separator "'magicmonkey <command> --help', e.g. 'magicmonkey configure --help'."
|
24
27
|
opts.separator ''
|
25
28
|
opts.separator 'Options:'
|
26
29
|
opts.on_tail('-v', '--version', 'Print version') { puts Magicmonkey::VERSION; exit }
|
@@ -28,252 +31,247 @@ module MagicMonkey
|
|
28
31
|
end
|
29
32
|
begin
|
30
33
|
parser.order!
|
31
|
-
command = ARGV
|
32
|
-
|
33
|
-
|
34
|
+
command = (ARGV & COMMANDS).first
|
35
|
+
raise 'Invalid command.' unless command
|
36
|
+
ARGV.delete(command)
|
34
37
|
rescue => e
|
35
|
-
rputs e
|
36
38
|
puts parser.help; exit
|
37
39
|
end
|
40
|
+
app = ARGV.first
|
41
|
+
self.send(command, ARGV)
|
42
|
+
end
|
43
|
+
|
44
|
+
#####################
|
45
|
+
# CONFIGURE COMMAND #
|
46
|
+
#####################
|
47
|
+
def self.configure(args)
|
48
|
+
app = self.help('configure', 'DESC', args) do |opts|
|
49
|
+
opts.on('-c', '--configuration CONFIG_FILE', 'Use this file as configuration') do |c|
|
50
|
+
@o[:configuration] = c
|
51
|
+
end
|
52
|
+
end
|
38
53
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
when 'stop'
|
45
|
-
start_stop_restart(:stop, ARGV)
|
46
|
-
when 'restart'
|
47
|
-
start_stop_restart(:restart, ARGV)
|
48
|
-
when 'remove'
|
49
|
-
remove(ARGV)
|
50
|
-
when 'show'
|
51
|
-
show(ARGV)
|
54
|
+
app_conf = Conf[app.to_sym]
|
55
|
+
unless app_conf
|
56
|
+
app_conf = @o.select{|k,v| [:app_server, :app_server_options, :ruby, :app_path, :bundle_exec].include?(k)}
|
57
|
+
app_conf[:app_path].gsub!('$APP', app)
|
58
|
+
app_conf[:port] = Conf.next_port
|
52
59
|
end
|
60
|
+
tmpfile = Tempfile.new("#{app}.yml")
|
61
|
+
tmpfile.write(app_conf.to_yaml)
|
62
|
+
tmpfile.close
|
63
|
+
system("#{@o[:editor]} '#{tmpfile.path}'")
|
64
|
+
conf = YAML.load_file(tmpfile.path)
|
65
|
+
tmpfile.unlink
|
66
|
+
|
67
|
+
self.check_port!(conf[:port]) if app_conf[:port] != conf[:port]
|
68
|
+
self.check_ruby_version!(conf[:ruby])
|
69
|
+
self.check_app_server!(conf[:app_server])
|
70
|
+
|
71
|
+
Conf[app.to_sym] = conf
|
72
|
+
Conf.save
|
53
73
|
end
|
54
74
|
|
75
|
+
#######################
|
76
|
+
# DECONFIGURE COMMAND #
|
77
|
+
#######################
|
78
|
+
def self.deconfigure(args)
|
79
|
+
app = help('deconfigure', 'The application will no longer be handled by magicmonkey.', args)
|
80
|
+
app_conf = Conf[app.to_sym]
|
81
|
+
unless app_conf
|
82
|
+
rputs "Application '#{app}' does not configured."
|
83
|
+
puts "Use 'magicmonkey configure #{app}' to configure it."
|
84
|
+
exit
|
85
|
+
else
|
86
|
+
Conf.delete(app)
|
87
|
+
Conf.save
|
88
|
+
end
|
89
|
+
end
|
55
90
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
91
|
+
################
|
92
|
+
# SHOW COMMAND #
|
93
|
+
################
|
94
|
+
def self.show(args)
|
95
|
+
applications = help2('show', 'Shows the configurations of selected applications', args)
|
96
|
+
applications.each do |app|
|
97
|
+
puts app.upcase
|
98
|
+
pp Conf[app]
|
99
|
+
puts '-' * 80
|
100
|
+
end
|
101
|
+
end
|
60
102
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
opts.on('-p', '--port NUMBER', Integer, "Use the given port number (default: #{Conf.next_port}).") do |p|
|
69
|
-
o[:port] = p
|
70
|
-
end
|
71
|
-
opts.on('-r', '--ruby RUBY_VERSION', "Use the given Ruby version (default: #{o[:ruby]}).") do |r|
|
72
|
-
o[:ruby] = r
|
73
|
-
end
|
74
|
-
opts.on('--app-path APP_PATH', "Use the given application path (default #{o[:app_path]}).") do |path|
|
75
|
-
o[:app_path] = path
|
76
|
-
end
|
77
|
-
opts.on('--server-name SERVER_NAME', "Use the given server name (default: #{o[:server_name]}).") do |name|
|
78
|
-
o[:server_name] = name
|
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
|
79
110
|
end
|
80
|
-
opts.on('--
|
81
|
-
o[:
|
111
|
+
opts.on('--path VHOST_PATH', "Use the given virtual host path (default: '#{@o[:vhost_path]}')") do |path|
|
112
|
+
@o[:vhost_path] = path
|
82
113
|
end
|
83
|
-
opts.on('
|
84
|
-
o[:
|
114
|
+
opts.on('-f', '--[no-]overwrite-file', "Replace exist file (default: #{@o[:overwrite_file]})") do |f|
|
115
|
+
@o[:overwrite_file] = f
|
85
116
|
end
|
86
|
-
opts.on('
|
87
|
-
o[:
|
117
|
+
opts.on('--[no-]enable-site', "Enable Apache virtual host (default: #{@o[:enable_site]})") do |e|
|
118
|
+
@o[:enable_site] = e
|
88
119
|
end
|
89
|
-
opts.on('--[no-]
|
90
|
-
o[:
|
120
|
+
opts.on('--[no-]reload-apache', "Reload apache to load virtual host (default: #{@o[:reload_apache]})") do |r|
|
121
|
+
@o[:reload_apache] = r
|
91
122
|
end
|
92
|
-
opts.on('--[no-]enable-site', "Enable Apache virtual host (default: #{o[:enable_site]}).") do |e|
|
93
|
-
o[:enable_site] = e
|
94
|
-
end
|
95
|
-
opts.on('--[no-]reload-apache', "Reload apache to load virtual host (default: #{o[:reload_apache]}).") do |r|
|
96
|
-
o[:reload_apache] = r
|
97
|
-
end
|
98
|
-
opts.on('--[no-]bundle-exec', "Use bundle exec to run application server (default: #{o[:bundle_exec]}).") do |b|
|
99
|
-
o[:bundle_exec] = b
|
100
|
-
end
|
101
|
-
opts.on_tail('-v', '--version', 'Print version') { puts Magicmonkey::VERSION; exit }
|
102
|
-
opts.on_tail('-h', '--help', 'Show this help message') { puts opts; exit }
|
103
|
-
end
|
104
|
-
begin
|
105
|
-
args = parser.parse!(args)
|
106
|
-
raise 'Missing application name.' if args.size != 1
|
107
|
-
rescue => e
|
108
|
-
rputs e
|
109
|
-
puts parser.help; exit
|
110
123
|
end
|
111
124
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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."
|
116
129
|
exit
|
117
130
|
end
|
118
|
-
o[:app_path].gsub!('$APP_NAME', app_name) if o[:app_path] == Conf[:default][:app_path]
|
119
|
-
o[:server_name].gsub!('$APP_NAME', app_name) if o[:server_name] == Conf[:default][:server_name]
|
120
|
-
o[:port] ||= Conf.next_port
|
121
|
-
if Conf.ports.include?(o[:port])
|
122
|
-
rputs 'Invalid port number. This port is used by another application or is invalid.'
|
123
|
-
exit
|
124
|
-
end
|
125
|
-
self.check_ruby_version!(o[:ruby])
|
126
|
-
self.check_app_server!(o[:app_server])
|
127
|
-
o[:vhost_template].gsub!('$APP_NAME', app_name)
|
128
|
-
o[:vhost_template].gsub!('$SERVER_NAME', o[:server_name])
|
129
|
-
o[:vhost_template].gsub!('$PORT', o[:port].to_s)
|
130
131
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
if
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
Cocaine::CommandLine.new("sudo bash -c \"echo '#{o[:vhost_template]}' > #{vh_file}\"").run
|
141
|
-
rescue Cocaine::ExitStatusError => e
|
142
|
-
rputs 'Failed to write virtual host file.'
|
143
|
-
end
|
144
|
-
else
|
145
|
-
puts "Virtual host file '#{vh_file}' already exist. Use option '-f' to replace it. Skip creation."
|
146
|
-
end
|
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.'
|
147
141
|
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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.'
|
154
151
|
end
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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.'
|
161
158
|
end
|
162
|
-
Conf[app_name] = o.select{|k,v| [:ruby, :port, :app_server, :app_server_options, :app_path, :vhost_path, :bundle_exec].include?(k)}
|
163
|
-
Conf.save
|
164
|
-
|
165
|
-
puts "#{green}Application '#{app_name}' added.#{reset}"
|
166
|
-
puts "use 'magicmonkey start #{app_name}' to start the application."
|
167
159
|
end
|
168
160
|
end
|
169
161
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
162
|
+
#################
|
163
|
+
# START COMMAND #
|
164
|
+
#################
|
165
|
+
def self.start(args)
|
166
|
+
applications = help2('start', 'Starts the selected applications.', args)
|
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
|
178
173
|
end
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
app_name = args.first
|
190
|
-
if Conf[app_name]
|
191
|
-
self.start_stop_restart(:stop, [app_name])
|
192
|
-
begin
|
193
|
-
Cocaine::CommandLine.new("sudo a2dissite '#{app_name}'").run
|
194
|
-
rescue Cocaine::ExitStatusError => e
|
195
|
-
rputs 'Failed to disable site.'
|
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]} ")
|
196
183
|
end
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
Cocaine::CommandLine.new(
|
201
|
-
rescue Cocaine::ExitStatusError => e
|
202
|
-
rputs 'Failed to remove virtual host file.'
|
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
|
203
188
|
end
|
189
|
+
puts " #{green}#{bold}done#{reset}."
|
190
|
+
rescue Cocaine::ExitStatusError => e
|
191
|
+
rputs "Failed to start application '#{app}'"
|
204
192
|
end
|
205
|
-
Conf.delete(app_name)
|
206
|
-
Conf.save
|
207
|
-
puts "Application '#{app_name}' removed."
|
208
|
-
else
|
209
|
-
rputs "Application '#{app_name}' does not exist."
|
210
193
|
end
|
211
194
|
end
|
212
195
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
if
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
puts " #{green}#{bold}done#{reset}."
|
240
|
-
rescue Cocaine::ExitStatusError => e
|
241
|
-
puts ''
|
242
|
-
rputs "Failed to #{ssr} application '#{app_name}'"
|
196
|
+
################
|
197
|
+
# STOP COMMAND #
|
198
|
+
################
|
199
|
+
def self.stop(args)
|
200
|
+
applications = help2('stop', 'Stops the selected applications.', args)
|
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
|
243
222
|
end
|
244
|
-
|
245
|
-
|
246
|
-
rputs "
|
223
|
+
puts " #{green}#{bold}done#{reset}."
|
224
|
+
rescue Cocaine::ExitStatusError => e
|
225
|
+
rputs "Failed to stop application '#{app}'"
|
247
226
|
end
|
248
227
|
end
|
249
228
|
end
|
250
229
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
230
|
+
###################
|
231
|
+
# RESTART COMMAND #
|
232
|
+
###################
|
233
|
+
def self.restart(args)
|
234
|
+
applications = help2('restart', 'Restart the selected applications.', args)
|
235
|
+
applications.each do |app|
|
236
|
+
app_conf = Conf[app.to_sym]
|
237
|
+
unless app_conf
|
238
|
+
rputs "Application '#{app}' does not configured."
|
239
|
+
puts "Use 'magicmonkey configure #{app}' to configure it."
|
240
|
+
exit
|
241
|
+
end
|
242
|
+
check_ruby_version!(app_conf[:ruby])
|
243
|
+
server = check_app_server!(app_conf[:app_server])
|
244
|
+
lines = []
|
245
|
+
lines << "source '#{Dir.home}/.rvm/scripts/rvm'"
|
246
|
+
lines << "rvm use #{app_conf[:ruby]}"
|
247
|
+
lines += server.stop(app_conf)
|
248
|
+
lines << 'sleep 3'
|
249
|
+
lines += server.start(app_conf)
|
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]} ")
|
253
|
+
end
|
254
|
+
begin
|
255
|
+
print "Calling #{bold}restart#{reset} for '#{app}' application..."
|
256
|
+
Dir.chdir(app_conf[:app_path]) do
|
257
|
+
Cocaine::CommandLine.new(command).run
|
258
|
+
end
|
259
|
+
puts " #{green}#{bold}done#{reset}."
|
260
|
+
rescue Cocaine::ExitStatusError => e
|
261
|
+
rputs "Failed to restart application '#{app}'"
|
262
|
+
end
|
272
263
|
end
|
273
264
|
end
|
274
265
|
|
275
266
|
private
|
276
267
|
|
268
|
+
def self.check_port!(port)
|
269
|
+
if Conf.ports.include?(port)
|
270
|
+
rputs 'Invalid port number. This port is used by another application or is invalid.'
|
271
|
+
exit
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
277
275
|
def self.check_ruby_version!(ruby)
|
278
276
|
rubies = ['default', 'system']
|
279
277
|
begin
|
@@ -296,11 +294,10 @@ module MagicMonkey
|
|
296
294
|
def self.check_app_server!(app_server)
|
297
295
|
unless app_server
|
298
296
|
rputs 'You must specify the application server.'
|
299
|
-
rputs 'Please use --app-server option. e.g. magicmonkey add APP_NAME --app-server=passenger'
|
300
297
|
exit
|
301
298
|
end
|
302
299
|
begin
|
303
|
-
Cocaine::CommandLine.new(app_server).run
|
300
|
+
Cocaine::CommandLine.new("#{app_server} -v").run
|
304
301
|
rescue Cocaine::CommandNotFoundError
|
305
302
|
rputs "The application server '#{app_server}' is not installed in your system."
|
306
303
|
rputs 'Please use a valid and installed application server.'
|
@@ -309,27 +306,64 @@ module MagicMonkey
|
|
309
306
|
end
|
310
307
|
begin
|
311
308
|
require "#{$APP_PATH}/lib/magicmonkey/app_servers/#{app_server}"
|
312
|
-
|
309
|
+
m = ''
|
310
|
+
i = 0
|
311
|
+
app_server.each_char do |c|
|
312
|
+
app_server[i-1] == '_' ? m << c.upcase : m << c if c != '_'
|
313
|
+
i+=1
|
314
|
+
end
|
315
|
+
m[0] = m[0].upcase
|
316
|
+
const_get(m)
|
313
317
|
rescue LoadError, NameError
|
314
|
-
rputs "No module '#{
|
318
|
+
rputs "No module '#{m}' found in #{$APP_PATH}/lib/magicmonkey/app_servers/#{app_server}.rb"
|
315
319
|
rputs "You must create a module called '#{app_server.capitalize}' to tell how to start, stop and restart the server."
|
316
320
|
exit
|
317
321
|
end
|
318
322
|
end
|
319
323
|
|
320
|
-
def self.
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
324
|
+
def self.help(command, desc, args)
|
325
|
+
parser = OptionParser.new do |opts|
|
326
|
+
opts.banner = "Usage: magicmonkey #{command} APP_NAME"
|
327
|
+
opts.separator ''
|
328
|
+
if desc
|
329
|
+
opts.separator desc
|
330
|
+
opts.separator ''
|
331
|
+
end
|
332
|
+
opts.separator 'Options:'
|
333
|
+
yield(opts) if block_given?
|
334
|
+
opts.on_tail('-h', '--help', 'Show this help message') { puts opts; exit }
|
335
|
+
end
|
336
|
+
begin
|
337
|
+
args = parser.parse!(args)
|
338
|
+
raise 'Missing application name.' if args.size != 1
|
339
|
+
rescue => e
|
340
|
+
puts parser.help; exit
|
341
|
+
end
|
342
|
+
return args.first
|
343
|
+
end
|
344
|
+
|
345
|
+
def self.help2(command, desc, args)
|
346
|
+
parser = OptionParser.new do |opts|
|
347
|
+
opts.banner = "Usage: magicmonkey #{command} [APP_NAME1 APP_NAME2 ...]"
|
348
|
+
opts.separator ''
|
349
|
+
if desc
|
350
|
+
opts.separator desc
|
351
|
+
opts.separator "If no application name passed, #{command} all applications."
|
352
|
+
opts.separator ''
|
353
|
+
end
|
354
|
+
opts.separator ''
|
355
|
+
opts.separator 'Options:'
|
356
|
+
yield(opts) if block_given?
|
357
|
+
opts.on_tail('-h', '--help', 'Show this help message') { puts opts; exit }
|
358
|
+
end
|
359
|
+
begin
|
360
|
+
args = parser.parse!(args)
|
361
|
+
rescue => e
|
362
|
+
puts parser.help; exit
|
330
363
|
end
|
331
|
-
|
332
|
-
|
364
|
+
applications = Conf.applications
|
365
|
+
applications &= args.map(&:to_sym) unless args.empty?
|
366
|
+
return applications
|
333
367
|
end
|
334
368
|
|
335
369
|
def self.rputs(message)
|
data/lib/magicmonkey/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magicmonkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cocaine
|
16
|
-
requirement: &
|
16
|
+
requirement: &70117049364340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70117049364340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: term-ansicolor
|
27
|
-
requirement: &
|
27
|
+
requirement: &70117049363460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70117049363460
|
36
36
|
description: ! 'Manage your Rails applications: different Ruby versions and different
|
37
37
|
application servers.'
|
38
38
|
email:
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- bin/magicmonkey
|
51
51
|
- lib/magicmonkey/app_servers/passenger.rb
|
52
52
|
- lib/magicmonkey/app_servers/thin.rb
|
53
|
+
- lib/magicmonkey/app_servers/unicorn_rails.rb
|
53
54
|
- lib/magicmonkey/configuration.rb
|
54
55
|
- lib/magicmonkey/magicmonkey.rb
|
55
56
|
- lib/magicmonkey/version.rb
|