Class: Daemonic::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/daemonic/cli.rb

Constant Summary collapse

COMMANDS =
%w(start stop status restart help)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, default_options = {}) ⇒ CLI



8
9
10
11
# File 'lib/daemonic/cli.rb', line 8

def initialize(argv, default_options = {})
  @argv            = argv
  @default_options = default_options
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



6
7
8
# File 'lib/daemonic/cli.rb', line 6

def argv
  @argv
end

#default_optionsObject (readonly)

Returns the value of attribute default_options.



6
7
8
# File 'lib/daemonic/cli.rb', line 6

def default_options
  @default_options
end

Instance Method Details

#helpObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/daemonic/cli.rb', line 37

def help
  info "\n    Usage: \#{program} COMMAND OPTIONS\n\n    Available commands:\n    * start              Start the daemon\n    * stop               Stops the daemon\n    * restart            Stops and starts a daemonized process\n    * status             Shows the status\n\n    To get more information about each command, run the command with --help.\n\n    Example: \#{program} start --help\n\n  USAGE\nend\n"

#restartObject



70
71
72
73
# File 'lib/daemonic/cli.rb', line 70

def restart
  options = parse "restart", log: STDOUT, concurrency: 2, stop_timeout: 5, startup_timeout: 1
  [ :restart, options ]
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/daemonic/cli.rb', line 13

def run
  command = argv[0]
  case command
  when nil, "-h", "--help", "help"
    help
    exit
  when "-v", "--version"
    puts "Daemonic version #{Daemonic::VERSION}"
    exit
  when "start"
    start
  when "stop"
    stop
  when "status"
    status
  when "restart"
    restart
  else
    puts "Unknown command #{command.inspect}."
    help
    exit 1
  end
end

#startObject



55
56
57
58
# File 'lib/daemonic/cli.rb', line 55

def start
  options = parse "start", log: STDOUT, concurrency: 2, daemonize: false, startup_timeout: 1
  [ :start, options ]
end

#statusObject



65
66
67
68
# File 'lib/daemonic/cli.rb', line 65

def status
  options = parse "status"
  [ :status, options ]
end

#stopObject



60
61
62
63
# File 'lib/daemonic/cli.rb', line 60

def stop
  options = parse "stop", stop_timeout: 5
  [ :stop, options ]
end