Class: Jubilee::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



11
12
13
14
# File 'lib/jubilee/cli.rb', line 11

def initialize(argv)
  @argv = argv
  setup_options
end

Instance Attribute Details

#optionsObject

Parsed options



10
11
12
# File 'lib/jubilee/cli.rb', line 10

def options
  @options
end

Instance Method Details

#parse_optionsObject



23
24
25
26
27
28
29
# File 'lib/jubilee/cli.rb', line 23

def parse_options
  argv = @argv.dup
  @parser.parse! argv
  if @argv.last
    @options[:rackup] = argv.shift
  end
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jubilee/cli.rb', line 31

def run
  test_java_version!(System.getProperties["java.runtime.version"])
  parse_options

  ENV["RACK_ENV"] = @options[:environment]

  if @options[:daemon]
    puts "Starting Jubilee in daemon mode..."
    `jubilee_d #{(@argv - ["-d", "--daemon"]).join(" ")}`
  else
    @config = Jubilee::Configuration.new(@options)
    server = Jubilee::Server.new(nil, @config.options)
    #server.start
    thread = Thread.current
    Signal.trap("INT") do
      server.stop
      puts "Jubilee is shutting down gracefully..."
      thread.wakeup
    end
    puts "Jubilee is listening on port #{@config.options[:Port]}, press Ctrl+C to quit"
    sleep
  end
end

#setup_optionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/jubilee/cli.rb', line 55

def setup_options
  @options = {
    debug: false,
    daemon: false,
    ssl: false,
    Port: 8080,
    instances: 4,
    quiet: false,
    environment: ENV["RACK_ENV"] || "development"
  }
  @parser = OptionParser.new do |o|
    o.separator ""
    o.separator "Server options:"

    o.on "-c", "--config PATH", "Load PATH as a config file" do |arg|
      @options[:config_file] = arg
    end
    o.on "-d", "--daemon", "Daemonize the server" do
      @options[:daemon] = true
    end
    o.on "--dir DIR", "Change to DIR before starting" do |arg|
      @options[:chdir] = arg
    end
    o.on "-p", "--port PORT", "Define which PORT the server should bind" do |arg|
      @options[:Port] = arg.to_i
    end
    o.on "-b", "--host HOST", "Define which HOST the server should bind, default 0.0.0.0" do |arg|
      @options[:Host] = arg
    end
    o.on "-e", "--environment ENV", "Rack environment" do |arg|
      @options[:environment] = arg
    end
    o.on "-n", "--instances NUM", "Define how many instances of web servers to run" do |arg|
      @options[:instances] = arg.to_i
    end
    o.separator ""
    o.separator "SSL options:"
    o.on "--ssl", "Enable SSL connection" do
      @options[:ssl] = true
    end
    o.on "--ssl-keystore PATH", "SSL keystore path" do |arg|
      @options[:ssl_keystore] = arg
    end
    o.on "--ssl-password PASS", "SSL keystore password" do |arg|
      @options[:ssl_keystore] = arg
    end
    o.separator ""
    o.separator "Event bus options:"
    o.on "--eventbus PREFIX", "Event bus prefix, use allow-all policy by default" do |arg|
      @options[:eventbus_prefix] = arg
    end

    o.separator ""
    o.separator "Clustering options:"
    o.on "--cluster", "Enable clustering" do
      @options[:clustered] = true
    end
    o.on "--cluster-port PORT", "If the cluster option has also been specified then this determines which port will be used for cluster communication with other Vert.x instances. Default is 0 -which means 'chose a free ephemeral port. You don't usually need to specify this parameter unless you really need to bind to a specific port." do |port|
      @options[:cluster_port] = port.to_i
    end
    o.on "--cluster-host HOST", "If the cluster option has also been specified then this determines which host address will be used for cluster communication with other Vert.x instances. By default it will try and pick one from the available interfaces. If you have more than one interface and you want to use a specific one, specify it here." do |host|
      @options[:cluster_host] = host
    end

    o.separator ""
    o.separator "Common options:"
    o.on "--verbose", "Log low level debug information" do
      @options[:debug] = true
    end

    o.on "-q", "--quiet", "Disable logging" do
      @options[:quiet] = true
    end

    o.on "-v", "--version", "Print the version information" do
      puts "jubilee version #{Jubilee::Version::STRING} on Vert.x 2.1M3"
      exit 0
    end
  end

  @parser.banner = "jubilee <options> <rackup file>"
  @parser.on_tail "-h", "--help", "Show this message" do
    puts @parser
    exit 1
  end
end

#test_java_version!(version) ⇒ Object



16
17
18
19
20
21
# File 'lib/jubilee/cli.rb', line 16

def test_java_version!(version)
  if version[0..2] < "1.7"
    puts("Error: Jubilee requires JDK 1.7.0 or later. You can use the official Oracle distribution or the OpenJDK version.")
    exit 1
  end
end