File: reporter.rb

package info (click to toggle)
ruby-daemons 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: ruby: 2,133; makefile: 7
file content (54 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Daemons
  class Reporter
    attr_reader :options

    def initialize(options)
      @options = options

      if !options[:shush]
        $stdout.sync = true
      end
    end

    def output_message(message)
      if !options[:shush]
        puts message
      end
    end

    def changing_process_privilege(user, group = user)
      output_message "Changing process privilege to #{user}:#{group}"
    end

    def deleted_found_pidfile(pid, f)
      output_message "pid-file for killed process #{pid} found (#{f}), deleting."
    end

    def process_started(app_name, pid)
      output_message  "#{app_name}: process with pid #{pid} started."
    end

    def backtrace_not_supported 
      output_message 'option :backtrace is not supported with :mode => :exec, ignoring'
    end

    def stopping_process(app_name, pid, sig, wait)
      output_message "#{app_name}: trying to stop process with pid #{pid}#{' forcefully :(' if sig == 'KILL'} sending #{sig} and waiting #{wait}s ..."
      $stdout.flush
    end

    def cannot_stop_process(app_name, pid)
      output_message "#{app_name}: unable to forcefully kill process with pid #{pid}."
      $stdout.flush
    end

    def stopped_process(app_name, pid)
      output_message "#{app_name}: process with pid #{pid} successfully stopped."
      $stdout.flush
    end

    def status(app_name, running, pid_exists, pid)
      output_message "#{app_name}: #{running ? '' : 'not '}running#{(running and pid_exists) ? ' [pid ' + pid.to_s + ']' : ''}#{(pid_exists and not running) ? ' (but pid-file exists: ' + pid.to_s + ')' : ''}"
    end
  end
end