-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bin/cucub-vm and all Servolux/CLI/Configuration stuff
- Loading branch information
Fernando Alonso
committed
Oct 24, 2012
1 parent
e52c1d7
commit 4da0fc0
Showing
11 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
#!/usr/bin/env ruby | |||
|
|||
STDERR.sync = STDOUT.sync = true | |||
|
|||
require 'bundler' | |||
Bundler.require(:default, :cli) | |||
|
|||
require File.expand_path('../../lib/cucub-vm.rb', __FILE__) | |||
require File.expand_path('../../lib/vm/servolux.rb', __FILE__) | |||
require File.expand_path('../../lib/vm/cli.rb', __FILE__) | |||
|
|||
Cucub::VM::CLI.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
# Run it on root with this command: ruby bin/cucub-vm start examples/boot.rb | |||
|
|||
require './examples/reply_channel_test' | |||
|
|||
core = Core.new | |||
#core.oid = 1 | |||
|
|||
#Cucub.start!('10.0.0.5', Proc.new {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
[engine] | |||
role = receiver | |||
default_uses = mailbox | |||
serialize = msgpack | |||
compression = gzip | |||
; cp = 1425 | |||
|
|||
[engine#create_vps] | |||
from = core | |||
respond_to = class+object | |||
uses_board = true | |||
serialize = none | |||
read_by = core | |||
|
|||
[agent] | |||
default_uses = board | |||
role = emitter | |||
|
|||
[agent#metric] | |||
serialize = none | |||
|
|||
[agent#adelantar_metric] | |||
from = trigger | |||
; respond_to = broadcast | |||
respond_to = box | |||
read_by = monitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
class Core | |||
def state(i) | |||
puts "--ack--" | |||
sleep(i) | |||
puts "Hola! #{i}" | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
require 'singleton' | |||
require './lib/vm/configuration' | |||
|
|||
module Cucub | |||
class VM | |||
include Singleton | |||
|
|||
def initialize | |||
#@dispatcher = Cucub::Dispatcher.instance | |||
end | |||
|
|||
def start!(vm_opts={}) | |||
@config_filepath = vm_opts[:config] | |||
@configuration = Cucub::VM::Configuration.instance | |||
#@address = server_opts[:host] | |||
#@dispatcher.start | |||
end | |||
|
|||
def shutdown! | |||
#@dispatcher.stop | |||
end | |||
|
|||
def config_filepath | |||
@config_filepath | |||
end | |||
|
|||
#def address | |||
# @address | |||
#end | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
require 'thor' | |||
require 'thor/actions' | |||
|
|||
# check reference | |||
# https://github.com/carlhuda/bundler/blob/master/lib/bundler/cli.rb | |||
|
|||
module Cucub | |||
class VM | |||
class CLI < Thor | |||
include Thor::Actions | |||
|
|||
#default_task :start | |||
|
|||
desc "start", "start cucub-vm" | |||
#method_option :host, :aliases => '-h', :default => '127.0.0.1', :type => :string | |||
method_option :config, :aliases => '-c', :default => 'config/protocol.ini', :type => :string | |||
def start(boot_file) | |||
opts = options.dup | |||
|
|||
# puts opts.inspect | |||
# puts gem | |||
|
|||
# encapsular esto en una clase de Cucub::Server | |||
# mover esto a una clase de cucub:server | |||
logger = Logger.new($stderr) | |||
logger.level = Logger::DEBUG | |||
|
|||
# encapsular esto en una clase de Cucub::Server | |||
pid_file = File.expand_path('cucub-vm.pid') | |||
|
|||
# before server | |||
#driver = Driver.instance | |||
#core = Antir::Core.instance | |||
#core.oid = 1 | |||
servolux = Cucub::VM::Servolux.new('Cucub-VM', :logger => logger, :pid_file => pid_file) | |||
servolux.vm_opts = opts # opts are passed raw to the servolux. They are read by a Cucub::Server instance. | |||
|
|||
boot_file = "./#{boot_file}" unless boot_file.match(/^[\/.]/) | |||
require boot_file | |||
|
|||
# after server | |||
|
|||
servolux.startup | |||
end | |||
|
|||
def help(cli = nil) | |||
puts "ping" | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
require 'singleton' | |||
|
|||
module Cucub | |||
class VM | |||
class Configuration | |||
include Singleton | |||
|
|||
def initialize | |||
@loader = Cucub::Protocol::Loader.instance | |||
set_config_file | |||
reload | |||
end | |||
|
|||
def set_config_file | |||
@loader.set_path(Cucub::VM.instance.config_filepath) | |||
end | |||
|
|||
def reload | |||
@specification_set = @loader.parse | |||
$stdout.puts self.classes.inspect | |||
@uses = nil | |||
end | |||
|
|||
def classes | |||
# lazy load array of classes | |||
return @classes if @classes | |||
#uses = [] | |||
#uses << "box" if @specification_set.uses_box | |||
#uses << "mailbox" if @specification_set.uses_mailbox | |||
#uses << "board" if @specification_set.uses_board | |||
@uses = @specification_set.classes | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
require 'servolux' | |||
require 'logger' | |||
|
|||
module Cucub | |||
class VM | |||
class Servolux < Servolux::Server | |||
attr_accessor :vm_opts | |||
|
|||
def run | |||
Cucub::VM.instance.start!(@vm_opts) | |||
Process.waitall | |||
end | |||
|
|||
def prefork | |||
end | |||
|
|||
def before_stopping | |||
Cucub::VM.instance.shutdown! | |||
end | |||
end | |||
end | |||
end | |||
|
|||
# TODO implement Servolux running as a Daemon | |||
# daemon = Servolux::Daemon.new(:server => server) | |||
# daemon.startup | |||
# daemon.shutdown | |||
#Cucub.start!('10.0.0.4') |