call_action (God::Process)

    # File lib/god/process.rb, line 158
        def call_action(action)
          command = send(action)

          if action == :stop && command.nil?
            pid = self.pid
            name = self.name
            command = lambda do
              applog(self, :info, "#{self.name} stop: default lambda killer")

              ::Process.kill('TERM', pid) rescue nil
              applog(self, :info, "#{self.name} sent SIGTERM")

              # Poll to see if it's dead
              5.times do
                begin
                  ::Process.kill(0, pid)
                rescue Errno::ESRCH
                  # It died. Good.
                  applog(self, :info, "#{self.name} process stopped")
                  return
                end

                sleep 1
              end

              ::Process.kill('KILL', pid) rescue nil
              applog(self, :info, "#{self.name} still alive; sent SIGKILL")
            end
          end

          if command.kind_of?(String)
            pid = nil

            if @tracking_pid
              # double fork god-daemonized processes
              # we don't want to wait for them to finish
              r, w = IO.pipe
              begin
                opid = fork do
                  STDOUT.reopen(w)
                  r.close
                  pid = self.spawn(command)
                  puts pid.to_s # send pid back to forker
                end

                ::Process.waitpid(opid, 0)
                w.close
                pid = r.gets.chomp
              ensure
                # make sure the file descriptors get closed no matter what
                r.close rescue nil
                w.close rescue nil
              end
            else
              # single fork self-daemonizing processes
              # we want to wait for them to finish
              pid = self.spawn(command)
              status = ::Process.waitpid2(pid, 0)
              exit_code = status[1] >> 8

              if exit_code != 0
                applog(self, :warn, "#{self.name} #{action} command exited with non-zero code = #{exit_code}")
              end

              ensure_stop if action == :stop
            end

            if @tracking_pid or (@pid_file.nil? and WRITES_PID.include?(action))
              File.open(default_pid_file, 'w') do |f|
                f.write pid
              end

              @tracking_pid = true
              @pid_file = default_pid_file
            end
          elsif command.kind_of?(Proc)
            # lambda command
            command.call
          else
            raise NotImplementedError
          end
        end