Sha256: 2a4d93b1891756cc4ee109d7849bda3797c5f1d9a710d9946511c2b766425a3c

Contents?: true

Size: 1.96 KB

Versions: 11

Compression:

Stored size: 1.96 KB

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

require 'optparse'
require 'vines'

COMMANDS = %w[start stop restart init bcrypt cert ldap schema]

def parse(args)
  options = {}
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: vines [options] #{COMMANDS.join('|')}"

    opts.separator ""
    opts.separator "Daemon options:"

    opts.on('-d', '--daemonize', 'Run daemonized in the background') do |daemonize|
      options[:daemonize] = daemonize
    end

    options[:log] = 'log/vines.log'
    opts.on('-l', '--log FILE', 'File to redirect output (default: log/vines.log)') do |log|
      options[:log] = log
    end

    options[:pid] = 'pid/vines.pid'
    opts.on('-P', '--pid FILE', 'File to store PID (default: pid/vines.pid)') do |pid|
      options[:pid] = pid
    end

    opts.separator ""
    opts.separator "Common options:"

    opts.on('-h', '--help', 'Show this message') do |help|
      options[:help] = help
    end

    opts.on('-v', '--version', 'Show version') do |version|
      options[:version] = version
    end
  end

  begin
    parser.parse!(args)
  rescue
    puts parser
    exit(1)
  end

  if options[:version]
    puts Vines::VERSION
    exit
  end

  if options[:help]
    puts parser
    exit
  end

  command = args.shift
  unless COMMANDS.include?(command)
    puts parser
    exit(1)
  end

  options.tap do |opts|
    opts[:args]    = args
    opts[:command] = command
    opts[:config]  = File.expand_path('conf/config.rb')
    opts[:pid]     = File.expand_path(opts[:pid])
    opts[:log]     = File.expand_path(opts[:log])
  end
end

def check_config(opts)
  return if %w[bcrypt init].include?(opts[:command])
  unless File.exists?(opts[:config])
    puts "No config file found at #{opts[:config]}"
    exit(1)
  end
end

VINES_ROOT = Dir.pwd
opts = parse(ARGV)
check_config(opts)
command = Vines::Command.const_get(opts[:command].capitalize).new
begin
  command.run(opts)
rescue SystemExit
  # do nothing
rescue Exception => e
  puts e.message
  exit(1)
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vines-0.4.5 bin/vines
vines-0.4.4 bin/vines
vines-0.4.3 bin/vines
vines-0.4.2 bin/vines
vines-0.4.1 bin/vines
vines-0.4.0 bin/vines
vines-0.3.2 bin/vines
vines-0.3.1 bin/vines
vines-0.3.0 bin/vines
vines-0.2.1 bin/vines
vines-0.2.0 bin/vines