class Guard::Rpush
Constants
- DEFAULT_SIGNAL
Public Instance Methods
capture_logging?()
click to toggle source
# File lib/guard/rpush.rb, line 128 def capture_logging? options.fetch(:capture_logging) { false } end
check_init_pidfile_directory()
click to toggle source
# File lib/guard/rpush.rb, line 68 def check_init_pidfile_directory pidfile_dir = File.dirname(pidfile_path) unless Dir.exist? pidfile_dir UI.info "Creating directory #{pidfile_dir} for pidfile" FileUtils.mkdir_p pidfile_dir end unless File.writable? pidfile_dir raise "No write access to pidfile directory #{pidfile_dir}" end end
cmd()
click to toggle source
# File lib/guard/rpush.rb, line 95 def cmd command = ['bundle exec rpush start'] command << "-e #{@options[:environment]}" if @options[:environment] command.join(' ') end
logfile()
click to toggle source
# File lib/guard/rpush.rb, line 101 def logfile options.fetch(:logfile) { if capture_logging? then "log/rpush.log" else 'stdout' end } end
pid()
click to toggle source
# File lib/guard/rpush.rb, line 80 def pid count = 0 loop do if count > 5 raise "pidfile was never written to #{pidfile_path}" end break if File.exists? pidfile_path UI.info "Waiting for pidfile to appear at #{pidfile_path}..." count += 1 sleep 1 end File.read(pidfile_path).to_i end
pidfile_path()
click to toggle source
# File lib/guard/rpush.rb, line 62 def pidfile_path options.fetch(:pidfile) { File.expand_path('/tmp/rpush.pid', File.dirname(__FILE__)) } end
process_running?()
click to toggle source
# File lib/guard/rpush.rb, line 119 def process_running? begin Process.getpgid pid true rescue Errno::ESRCH false end end
reload()
click to toggle source
# File lib/guard/rpush.rb, line 32 def reload UI.info "Reloading Rpush..." stop start UI.info "Rpush restarted successfully." end
reload_on_change?()
click to toggle source
# File lib/guard/rpush.rb, line 115 def reload_on_change? options.fetch(:reload_on_change) { false } end
run_all()
click to toggle source
# File lib/guard/rpush.rb, line 39 def run_all true end
run_on_change(paths)
click to toggle source
# File lib/guard/rpush.rb, line 43 def run_on_change(paths) reload if reload_on_change? end
shutdown_retries()
click to toggle source
# File lib/guard/rpush.rb, line 107 def shutdown_retries options.fetch(:shutdown_retries) { 0 } end
shutdown_rpush()
click to toggle source
# File lib/guard/rpush.rb, line 47 def shutdown_rpush return UI.info "No instance of Rpush to stop." unless pid return UI.info "Rpush (#{pid}) was already stopped." unless process_running? UI.info "Sending TERM signal to Rpush (#{pid})..." Process.kill("TERM", pid) return if shutdown_retries == 0 shutdown_retries.times do return UI.info "Rpush stopped." unless process_running? UI.info "Rpush is still shutting down. Retrying in #{ shutdown_wait } second(s)..." sleep shutdown_wait end UI.error "Rpush didn't shut down after #{ shutdown_retries * shutdown_wait } second(s)." end
shutdown_wait()
click to toggle source
# File lib/guard/rpush.rb, line 111 def shutdown_wait options.fetch(:shutdown_wait) { 0 } end
start()
click to toggle source
# File lib/guard/rpush.rb, line 7 def start @rpush_started = false begin check_init_pidfile_directory UI.info "Starting Rpush daemon.." sid = spawn({},cmd) Process.wait(sid) UI.info "Rpush is running with PID #{pid}" @rpush_started = $?.success? rescue ::Exception => err UI.error "Unable to start Rpush. Errors: #{err}" end @rpush_started end
stop()
click to toggle source
# File lib/guard/rpush.rb, line 22 def stop if @rpush_started shutdown_rpush true else UI.info "Rpush was not started. Skipping stop process.." true end end