Adding --version and fixing the config and command line options

This commit is contained in:
Chris Cowan 2014-08-28 09:41:11 -07:00
parent 0fa83908e0
commit 156b597010
9 changed files with 95 additions and 39 deletions

View file

@ -20,6 +20,7 @@
"grunt-contrib-requirejs": "~0.4.4",
"grunt-contrib-watch": "~0.5.3",
"grunt-mocha": "~0.4.10",
"grunt-replace": "^0.7.9",
"grunt-run": "^0.2.3",
"http-proxy": "~1.1.4",
"husky": "~0.6.0",

View file

@ -1,36 +1,68 @@
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'puma' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "optparse"
require "pp"
require 'rubygems'
version = ">= 0"
require 'puma/cli'
require "yaml"
HERE = File.expand_path(File.dirname(__FILE__))
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
# Defaults for the options
options = {
:config => File.expand_path("#{HERE}/../config/kibana.yml") || ENV["CONFIG_PATH"]
}
# Create a new parser
parser = OptionParser.new do |opts|
opts.on('-e', '--elasticsearch URI', 'Elasticsearch instance') do |arg|
options[:elasticsearch] = arg
end
opts.on('-c', '--config PATH', 'Path to config file') do |arg|
options[:config] = arg
end
opts.on('-p', '--port PORT', 'Kibana port') do |arg|
options[:port] = arg
end
opts.on('-v', '--version', 'Display version') do |arg|
puts ENV['KIBANA_VERSION'] || 'dev-build'
exit
end
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
end
# Include the puma config unless it's been overriden
unless ARGV.include?('--port') or ARGV.include?('-p')
ARGV << '--port'
ARGV << '5601'
end
# Set the usage banner
parser.banner = "Usage: kibana <options>\n\n"
# Include the rack config if it hasn't been included
if (ARGV.grep(/config\/web\.ru/)).empty?
ARGV << "#{HERE}/../config/web.ru"
end
# Parse the command line arguments
parser.parse! ARGV
gem 'puma', version
load Gem.bin_path('puma', 'puma', version)
# Load the config from default
config = YAML.load(IO.read(options[:config]))
# Set the override for the port
port = (options[:port] || config['port'])
# Set the override for Elasticsaerch
elasticsearch = (options[:elasticsearch] || config['elasticsearch'])
# Set the enviroment vars
ENV["KIBANA_PORT"] = port.to_s
ENV["KIBANA_CONFIG_FILE"] = options[:config]
ENV["KIBANA_ELASTICSEARCH"] = elasticsearch
# Clone argv and then clear it and set up the defaults for the Puma CLI
puma_args = ARGV.clone()
puma_args.clear
puma_args << '--port'
puma_args << port.to_s
puma_args << "#{HERE}/../config/web.ru"
# gem 'puma', version
# load Gem.bin_path('puma', 'puma', version)
#
cli = Puma::CLI.new puma_args
cli.run

View file

@ -1,22 +1,24 @@
@echo off
SETLOCAL
if NOT DEFINED JAVA_HOME goto java_home_err
if not defined JAVA_HOME goto java_home_err
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI
set RACK_ENV=production
set CONFIG_PATH=%DIR%\config\kibana.yml
set KIBANA_VERSION=@@version
TITLE Kibana 4.0.0-BETA
TITLE Kibana %KIBANA_VERSION%
"%JAVA_HOME%\bin\java" -jar "%DIR%\lib\kibana.jar" %*
:java_home_err
echo JAVA_HOME enviroment variable must be set!
pause
goto finally
:finally

View file

@ -27,4 +27,4 @@ if [ ! -x "${JAVA}" ]; then
exit 1
fi
CONFIG_PATH=${DIR}/../config/kibana.yml RACK_ENV=production exec "${JAVA}" -jar "${DIR}/../lib/kibana.jar" "$@"
KIBANA_VERSION=@@version CONFIG_PATH=${DIR}/../config/kibana.yml RACK_ENV=production exec "${JAVA}" -jar "${DIR}/../lib/kibana.jar" "$@"

View file

@ -1,11 +1,11 @@
ROOT = File.expand_path("#{File.dirname(__FILE__)}/../")
if ENV['RACK_ENV'] == ('development')
ROOT = File.expand_path("#{File.dirname(__FILE__)}/../")
PUBLIC_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../kibana/")
CONFIG_PATH = File.expand_path("#{File.dirname(__FILE__)}/kibana.yml")
end
if ENV['RACK_ENV'] == ('production')
ROOT = File.expand_path("#{File.dirname(__FILE__)}/../")
PUBLIC_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../public/")
CONFIG_PATH = ENV["CONFIG_PATH"]
end

View file

@ -15,6 +15,8 @@ module Kibana
config = YAML.load(IO.read(CONFIG_PATH))
set :config, config
config['elasticsearch'] = ENV['KIBANA_ELASTICSEARCH']
config['port'] = ENV['KIBANA_PORT'].to_i
end
end

View file

@ -10,6 +10,7 @@ module.exports = function (grunt) {
'clean:unneeded_source_in_build',
'copy:server_src',
'warble',
'replace:dist',
'copy:dist',
'chmod_kibana',
'compress:build_zip',

View file

@ -22,14 +22,6 @@ module.exports = function (grunt) {
src: '<%= build %>/kibana/INSTALL',
dest: '<%= build %>/dist/INSTALL',
},
{
src: '<%= build %>/kibana/bin/kibana.bat',
dest: '<%= build %>/dist/bin/kibana.bat',
},
{
src: '<%= build %>/kibana/bin/kibana.sh',
dest: '<%= build %>/dist/bin/kibana',
},
{
expand: true,
cwd: '<%= build %>/kibana/',

26
tasks/config/replace.js Normal file
View file

@ -0,0 +1,26 @@
var join = require('path').join;
module.exports = function (grunt) {
var pkg = grunt.config.get('pkg');
var build = grunt.config.get('build');
var config = {
dist: {
options: {
patterns: [
{ match: 'version', replacement: pkg.version }
]
},
files: [
{
src: [join(build, 'kibana', 'bin', 'kibana.sh')],
dest: join(build, 'dist', 'bin', 'kibana')
},
{
src: [join(build, 'kibana', 'bin', 'kibana.bat')],
dest: join(build, 'dist', 'bin', 'kibana.bat')
}
]
}
};
return config;
};