vmc-ng/lib/vmc/cli/app.rb in vmc-0.4.0.beta.10 vs vmc-ng/lib/vmc/cli/app.rb in vmc-0.4.0.beta.11
- old
+ new
@@ -72,11 +72,11 @@
ask "Bind other services to application?", :default => false
}
def push(name = nil)
path = File.expand_path(input(:path) || ".")
- name ||= input(:name)
+ name = input(:name) if input(:name)
detector = Detector.new(client, path)
frameworks = detector.all_frameworks
detected, default = detector.frameworks
@@ -173,10 +173,12 @@
end
end
app.services = bindings
+ app = filter(:push_app, app)
+
with_progress("Creating #{c(name, :name)}") do
app.create!
end
begin
@@ -203,10 +205,12 @@
names.each do |name|
app = client.app(name)
fail "Unknown application." unless app.exists?
+ app = filter(:start_app, app)
+
switch_mode(app, input(:debug_mode))
with_progress("Starting #{c(name, :name)}") do |s|
if app.started?
s.skip do
@@ -303,10 +307,11 @@
fail "No applications." if apps.empty?
names = [input(:name, apps.collect(&:name).sort)]
end
+ # TODO: handle invalid app name
to_delete = names.collect { |n| apps.find { |a| a.name == n } }
orphaned = find_orphaned_services(to_delete)
to_delete.each do |app|
really = input(:really, app.name, :name)
@@ -359,10 +364,11 @@
flag(:memory) { |default|
ask("Memory Limit",
:default => human_size(default * 1024 * 1024, 0),
:choices => MEM_CHOICES)
}
+ flag :restart, :default => true
def scale(name = nil)
name ||= input(:name)
app = client.app(name)
@@ -372,15 +378,28 @@
unless instances || memory
instances = input(:instances, app.total_instances)
memory = input(:memory, app.memory)
end
+ megs = megabytes(memory)
+
+ memory_changed = megs != app.memory
+ instances_changed = instances != app.total_instances
+
+ return unless memory_changed || instances_changed
+
with_progress("Scaling #{c(name, :name)}") do
app.total_instances = instances.to_i if instances
- app.memory = megabytes(memory) if memory
+ app.memory = megs if memory
app.update!
end
+
+ if memory_changed && app.started? && input(:restart)
+ with_progress("Restarting #{c(name, :name)}") do
+ app.restart!
+ end
+ end
end
desc "logs APP", "Print out an app's logs"
group :apps, :info, :hidden => true
flag :name
@@ -562,10 +581,11 @@
class Env < Command
VALID_NAME = /^[a-zA-Za-z_][[:alnum:]_]*$/
desc "set APP [NAME] [VALUE]", "Set an environment variable"
group :apps, :info, :hidden => true
+ flag :restart, :default => true
def set(appname, name, value)
unless name =~ VALID_NAME
fail "Invalid variable name; must match #{VALID_NAME.inspect}"
end
@@ -576,22 +596,35 @@
app.update!("env" =>
app.env.reject { |v|
v.start_with?("#{name}=")
}.push("#{name}=#{value}"))
end
+
+ if app.started? && input(:restart)
+ with_progress("Restarting #{c(app.name, :name)}") do
+ app.restart!
+ end
+ end
end
desc "unset APP [NAME]", "Remove an environment variable"
group :apps, :info, :hidden => true
+ flag :restart, :default => true
def unset(appname, name)
app = client.app(appname)
fail "Unknown application." unless app.exists?
with_progress("Updating #{c(app.name, :name)}") do
app.update!("env" =>
app.env.reject { |v|
v.start_with?("#{name}=")
})
+ end
+
+ if app.started? && input(:restart)
+ with_progress("Restarting #{c(app.ame, :name)}") do
+ app.restart!
+ end
end
end
desc "list APP", "Show all environment variables set for an app"
group :apps, :info, :hidden => true