lib/gitdocs/cli.rb in gitdocs-0.1.2 vs lib/gitdocs/cli.rb in gitdocs-0.1.3
- old
+ new
@@ -9,29 +9,34 @@
desc "start", "Starts a daemonized gitdocs process"
method_option :debug, :type => :boolean, :aliases => "-D"
def start
if !self.running? && !options[:debug]
self.runner(:daemonize => true, :pid_path => self.pid_path).execute { Gitdocs.run }
- say "Started gitdocs", :green
+ until_true(5) { self.running? }
+ self.running? ? say("Started gitdocs", :green) : say("Failed to start gitdocs", :red)
elsif !self.running? && options[:debug]
say "Running in debug mode", :yellow
Gitdocs.run(nil, true)
else # already running
say "Gitdocs is already running, please use restart", :red
end
end
desc "stop", "Stops the gitdocs process"
def stop
- self.runner(:kill => true, :pid_path => self.pid_path).execute
- say "Stopped gitdocs", :red
+ if self.running?
+ self.runner(:kill => true, :pid_path => self.pid_path).execute
+ say "Stopped gitdocs", :red
+ else # not running
+ say "Gitdocs is not running", :red
+ end
end
desc "restart", "Restarts the gitdocs process"
def restart
self.stop
- sleep(1)
+ until_true(5) { self.running? }
self.start
end
desc "add PATH", "Adds a path to gitdocs"
def add(path)
@@ -105,9 +110,20 @@
false
end
def pid_path
"/tmp/gitdocs.pid"
+ end
+
+ # Runs until the block condition is met or the retry_count is exceeded
+ # until_true(10) { ...return_condition... }
+ def until_true(retry_count, &block)
+ count = 0
+ while count < retry_count && block.call != true
+ count += 1
+ sleep(1)
+ end
+ count < retry_count
end
end
end
end