lib/bluepill/process.rb in bluepill-0.1.2 vs lib/bluepill/process.rb in bluepill-0.1.3

- old
+ new

@@ -47,11 +47,11 @@ :group_start_noblock, :group_restart_noblock, :group_stop_noblock, :group_unmonitor_noblock, - ] + ].freeze attr_accessor :name, :watches, :triggers, :logger, :skip_ticks_until, :process_running attr_accessor(*CONFIGURABLE_ATTRIBUTES) attr_reader :children, :statistics @@ -143,26 +143,26 @@ # Let state_machine do its initialization stuff super() # no arguments intentional end def tick - return if self.skipping_ticks? + return if skipping_ticks? self.skip_ticks_until = nil # clear the memoization per tick @process_running = nil # Deal with thread cleanup here since the stopping state isn't used - clean_threads if self.unmonitored? + clean_threads if unmonitored? # run state machine transitions super - return unless self.up? + return unless up? run_watches - return unless self.monitor_children? + return unless monitor_children? refresh_children! children.each(&:tick) end def logger=(logger) @@ -173,11 +173,11 @@ # State machine methods def dispatch!(event, reason = nil) @event_mutex.synchronize do @statistics.record_event(event, reason) - send("#{event}") + send(event.to_s) end end def record_transition(transition) return if transition.loopback? @@ -185,11 +185,11 @@ # When a process changes state, we should clear the memory of all the watches watches.each(&:clear_history!) # Also, when a process changes state, we should re-populate its child list - if self.monitor_children? + if monitor_children? logger.warning 'Clearing child list' children.clear end logger.info "Going from #{transition.from_name} => #{transition.to_name}" end @@ -230,26 +230,26 @@ thread[:events].each do |event| events << [event, watch.to_s] end end.each do |event, reason| # rubocop:disable Style/MultilineBlockChain break if @transitioned - self.dispatch!(event, reason) + dispatch!(event, reason) end end def determine_initial_state - if self.process_running?(true) + if process_running?(true) self.state = 'up' - else - self.state = (auto_start == false) ? 'unmonitored' : 'down' # we need to check for false value + return end + self.state = (auto_start == false) ? 'unmonitored' : 'down' # we need to check for false value end def handle_user_command(cmd) case cmd when 'start' - if self.process_running?(true) + if process_running?(true) logger.warning('Refusing to re-run start command on an already running process.') else dispatch!(:start, 'user initiated') end when 'stop' @@ -277,17 +277,17 @@ def start_process ProcessJournal.kill_all_from_journal(name) # be sure nothing else is running from previous runs pre_start_process logger.warning "Executing start command: #{start_command}" - if self.daemonize? + if daemonize? daemon_id = System.daemonize(start_command, system_command_options) if daemon_id ProcessJournal.append_pid_to_journal(name, daemon_id) - children.each do|child| + children.each do |child| ProcessJournal.append_pid_to_journal(name, child.actual_pid) - end if self.monitor_children? + end if monitor_children? end daemon_id else # This is a self-daemonizing process with_timeout(start_grace_time, on_start_timeout) do @@ -428,10 +428,10 @@ return @actual_pid if cache_actual_pid? && @actual_pid @actual_pid = begin if pid_file if File.exist?(pid_file) str = File.read(pid_file) - str.to_i if str.size > 0 + str.to_i unless str.empty? else logger.warning("pid_file #{pid_file} does not exist or cannot be read") nil end end