Sha256: 0192aa217a442eed9906913da34408832a06c815ab21c7bb1b38529664bbed3a

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

#!/usr/bin/env ruby

require "thor"
require "baleen"

def pid
  ### Use this when implement restart command
  #pid = `ps ax | grep -E "baleen-server start|restart" | grep -v grep | awk '{print $1}'`
  pid = `ps ax | grep -E "baleen-server start|restart" | grep -v grep | awk '{print $1}'`
  pid.split("\n")
end

def running?
  pid.size >= 1
end

class BaleenServerCli < Thor

  desc "start", "Start Baleen server"
  option :docker_host, :default => "127.0.0.1"
  option :docker_port, :default => 4243
  option :port,        :default => 5533
  option :debug,       :type    => :boolean
  def start
    if pid.size > 1
      warning "baleen-server is already running"
      warning "Exiting..."
      exit
    end

    docker_host = options[:docker_host]
    docker_port = options[:docker_port]
    port        = options[:port]
    debug       = options[:debug]

    info "Starting baleen-server..."
    info "  Listening on: #{port}"
    info "  Docker API: http://#{docker_host}:#{docker_port}"

    Process.daemon(true, debug)
    Baleen::Server.new(docker_host: docker_host, docker_port: docker_port, port: port)

    # Prevent main thread from exiting for Celluloid actors to continue running
    # See https://github.com/celluloid/celluloid/wiki/Frequently-Asked-Questions
    sleep
  end

  desc "stop", "Stop Baleen server"
  def stop
    if running?
      notice "Stopping Baleen server..."
      `kill -9 #{pid.first}`
    else
      notice "baleen-server is not running"
    end
  end

end

BaleenServerCli.start

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
baleen-0.0.9 bin/baleen-server