ragent 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 999619886a83bc4e675bfd0c36ca4060e2aca9ea
4
+ data.tar.gz: 0833d94323484ab7f49f3c71d8f67a74ddd6e127
5
+ SHA512:
6
+ metadata.gz: a180cc6437d2bea1a427e7d573225b12685f41e8ce04346c9f1f0b9070c5d49b86cd037c88729e29d3be51a12c3d4f79db2d54e7b82ffb4721a3e2e149e6d92c
7
+ data.tar.gz: d3e32e38e582b77ef372c8bf82e1769a0392b384cff2c6cb0d6f4354171b7bb26f80566c6c947f556961ce92914c145e93dc9cf0196c1420ebecc915cd6f4d0f
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+
2
+ *~
3
+ *.gem
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at peter.schrammel@preisanalytics.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ragent (0.0.1)
5
+ celluloid (~> 0.17.0)
6
+ logging (~> 2.1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ celluloid (0.17.3)
12
+ celluloid-essentials
13
+ celluloid-extras
14
+ celluloid-fsm
15
+ celluloid-pool
16
+ celluloid-supervision
17
+ timers (>= 4.1.1)
18
+ celluloid-essentials (0.20.5)
19
+ timers (>= 4.1.1)
20
+ celluloid-extras (0.20.5)
21
+ timers (>= 4.1.1)
22
+ celluloid-fsm (0.20.5)
23
+ timers (>= 4.1.1)
24
+ celluloid-pool (0.20.5)
25
+ timers (>= 4.1.1)
26
+ celluloid-supervision (0.20.6)
27
+ timers (>= 4.1.1)
28
+ diff-lcs (1.2.5)
29
+ hitimes (1.2.4)
30
+ little-plugger (1.1.4)
31
+ logging (2.1.0)
32
+ little-plugger (~> 1.1)
33
+ multi_json (~> 1.10)
34
+ multi_json (1.12.1)
35
+ rake (10.5.0)
36
+ rspec (3.5.0)
37
+ rspec-core (~> 3.5.0)
38
+ rspec-expectations (~> 3.5.0)
39
+ rspec-mocks (~> 3.5.0)
40
+ rspec-core (3.5.4)
41
+ rspec-support (~> 3.5.0)
42
+ rspec-expectations (3.5.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.5.0)
45
+ rspec-mocks (3.5.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.5.0)
48
+ rspec-support (3.5.0)
49
+ timers (4.1.2)
50
+ hitimes
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ bundler (~> 1.13)
57
+ ragent!
58
+ rake (~> 10.0)
59
+ rspec (~> 3.0)
60
+
61
+ BUNDLED WITH
62
+ 1.13.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Peter Schrammel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # About
2
+ Ragent is am agent framework. It's meant to be installed on a host and do it's jobs.
3
+ It's exact job depends on the plugins you install.
4
+
5
+ # Usage
6
+
7
+
8
+
9
+ Built in commands
10
+
11
+ * help
12
+ * shutdown
13
+
14
+
15
+
16
+
17
+ # FAQ
18
+
19
+ Why doesn't it daemonize. We'll leave this problem to docker or daemonize and other similar tools.
20
+
21
+
22
+ # TODO
23
+ * plugins
24
+ * websocket (endpoint)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/ragent ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/ragent'
4
+
5
+ workdir=Dir.pwd
6
+
7
+ ragent=Ragent.setup(
8
+ log_level: ENV['RAGENT_LOG_LEVEL'] || 'info',
9
+ workdir: workdir
10
+ )
11
+
12
+ eval File.read(ragent.workdir.join("config.ragent"))
data/examples/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'ragent', path: "#{__dir__}/../"
4
+ gem 'celluloid-io'
5
+
6
+
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: /vagrant/apps/ragent
3
+ specs:
4
+ ragent (0.0.1)
5
+ celluloid (~> 0.17.0)
6
+ logging (~> 2.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ celluloid (0.17.3)
12
+ celluloid-essentials
13
+ celluloid-extras
14
+ celluloid-fsm
15
+ celluloid-pool
16
+ celluloid-supervision
17
+ timers (>= 4.1.1)
18
+ celluloid-essentials (0.20.5)
19
+ timers (>= 4.1.1)
20
+ celluloid-extras (0.20.5)
21
+ timers (>= 4.1.1)
22
+ celluloid-fsm (0.20.5)
23
+ timers (>= 4.1.1)
24
+ celluloid-io (0.17.3)
25
+ celluloid (>= 0.17.2)
26
+ nio4r (>= 1.1)
27
+ timers (>= 4.1.1)
28
+ celluloid-pool (0.20.5)
29
+ timers (>= 4.1.1)
30
+ celluloid-supervision (0.20.6)
31
+ timers (>= 4.1.1)
32
+ hitimes (1.2.4)
33
+ little-plugger (1.1.4)
34
+ logging (2.1.0)
35
+ little-plugger (~> 1.1)
36
+ multi_json (~> 1.10)
37
+ multi_json (1.12.1)
38
+ nio4r (2.0.0)
39
+ timers (4.1.2)
40
+ hitimes
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ celluloid-io
47
+ ragent!
48
+
49
+ BUNDLED WITH
50
+ 1.13.7
@@ -0,0 +1,4 @@
1
+ Ragent.plugin :time_bomb
2
+ Ragent.plugin :login
3
+
4
+ Ragent.run
@@ -0,0 +1,79 @@
1
+ require 'celluloid/current'
2
+ require 'celluloid/io'
3
+
4
+ module Ragent
5
+ module Plugin
6
+ class Login
7
+ include Ragent::Plugin
8
+ include Celluloid::IO
9
+
10
+ def configure
11
+ end
12
+
13
+ def start
14
+ @server = TCPServer.new('127.0.0.1', 6666)
15
+ async.run
16
+ end
17
+
18
+ def stop
19
+ @server.close if @server
20
+ end
21
+
22
+ private
23
+
24
+ def run
25
+ loop { async.handle_connection @server.accept }
26
+ end
27
+
28
+ def handle_connection(socket)
29
+ _, port, host = socket.peeraddr
30
+ info "connection from #{host}:#{port}"
31
+ looping = true
32
+ while looping
33
+ line = socket.readpartial(4096)
34
+ if line.strip == 'exit'
35
+ socket.puts 'exiting'
36
+ looping = false
37
+ else
38
+ cmd, options = parse_line(line)
39
+ if cmd
40
+ socket.puts cmd.execute(options)
41
+ else
42
+ socket.puts "unknown command: #{line}"
43
+ end
44
+ end
45
+ end
46
+ socket.close
47
+ rescue EOFError
48
+ info 'disconnected'
49
+ socket.close
50
+ end
51
+
52
+ def parse_line(line)
53
+ words = line.split(' ')
54
+ # do we have a sub?
55
+ main_command = words.shift
56
+ sub_command = nil
57
+ sub_command = words.shift if !words.empty? && words[0][0] != '-'
58
+ options = parse_options(words)
59
+ cmd = @ragent.commands.lookup(main_command, sub_command, options)
60
+ if cmd
61
+ return cmd, options
62
+ else
63
+ return nil, nil
64
+ end
65
+ end
66
+
67
+ # currently we parse everything into a hash
68
+ # (ignoring the first two char - should be --)
69
+ #
70
+ def parse_options(words)
71
+ words.each_slice(2).to_a.map do |key, value|
72
+ [key[2..-1], value]
73
+ end.to_h
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ Ragent.ragent.plugins.register('login', Ragent::Plugin::Login)
@@ -0,0 +1,85 @@
1
+ module Ragent
2
+ module Plugin
3
+ class TimeBomb
4
+ class TestBomb
5
+ include Celluloid
6
+ include Celluloid::Notifications
7
+ include Ragent::Logging
8
+
9
+ finalizer :stop
10
+
11
+ def initialize
12
+ async.start
13
+ end
14
+
15
+ def start
16
+ every(5) do
17
+ publish 'time-bomb-boom', expode_at: Time.now
18
+ end
19
+ end
20
+
21
+ def stop
22
+ info 'disarmed'
23
+ end
24
+ end
25
+
26
+ include Ragent::Plugin
27
+
28
+ def configure
29
+ @next_time_bomb_id = 1
30
+ @time_bombs = {}
31
+ command('tick', :command_tick)
32
+ command('list', :command_list)
33
+ command('disarm', :command_disarm)
34
+ subscribe('time-bomb-boom', :boom_callback)
35
+ end
36
+
37
+ def start
38
+ end
39
+
40
+ def command(sub, method)
41
+ cmd = Ragent::Command.new(main: 'time_bomb',
42
+ sub: sub,
43
+ recipient: self,
44
+ method: method)
45
+ @ragent.commands.add(cmd)
46
+ end
47
+
48
+ def command_disarm(options)
49
+ bomb_name = "time_bomb_#{options['bomb']}"
50
+ bomb = Actor[bomb_name]
51
+ if bomb
52
+ bomb.terminate
53
+ @time_bombs.delete(bomb_name)
54
+ "terminated #{bomb_name}"
55
+ else
56
+ "no such bomb #{bomb_name}"
57
+ end
58
+ end
59
+
60
+ def command_list(_options)
61
+ @time_bombs.keys.join("\n")
62
+ end
63
+
64
+ def command_tick(_options)
65
+ # how to track the bombs to disarm them?
66
+ as = "time_bomb_#{@next_time_bomb_id}"
67
+ @time_bombs[as] = true
68
+ @next_time_bomb_id += 1
69
+
70
+ @ragent.supervisor.supervise(
71
+ type: TimeBomb::TestBomb,
72
+ as: as
73
+ )
74
+
75
+ 'starting timebomb'
76
+ end
77
+
78
+ def boom_callback(_topic, params)
79
+ debug "boom: #{params.inspect}"
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ Ragent.ragent.plugins.register('time_bomb', Ragent::Plugin::TimeBomb)
@@ -0,0 +1,22 @@
1
+ module Ragent
2
+ class Command
3
+
4
+ include Ragent::Logging
5
+
6
+ attr_reader :main, :sub
7
+ def initialize(main:, sub: nil, recipient:, method:)
8
+ @main=main
9
+ @sub=sub
10
+ @recipient=recipient
11
+ @method=method
12
+ end
13
+
14
+ def execute(options={})
15
+ info "running: #{@main} #{@sub}, calling: #{@method}"
16
+ @recipient.send(@method,options)
17
+ end
18
+
19
+ def help
20
+ "#{@main} #{@sub}"
21
+ end end
22
+ end
@@ -0,0 +1,56 @@
1
+ module Ragent
2
+ class Commands
3
+ include Ragent::Logging
4
+
5
+ def initialize(ragent)
6
+ @ragent=ragent
7
+ @commands={}
8
+ add_help_command
9
+ end
10
+
11
+ def add(command)
12
+ if command.sub
13
+ @commands[command.main] ||= {}
14
+ @commands[command.main][command.sub]=command
15
+ else
16
+ @commands[command.main] ||= command
17
+ end
18
+ info "registered command: #{command.help}"
19
+ end
20
+
21
+ def lookup(main,sub,options)
22
+ debug "checkig command: #{main},#{sub},#{options}"
23
+ cmd=@commands[main]
24
+ if cmd
25
+ if cmd.kind_of?(Hash) && sub
26
+ return @commands[main][sub]
27
+ else
28
+ return cmd
29
+ end
30
+ end
31
+ nil
32
+ end
33
+ private
34
+
35
+ def help_command(options={})
36
+ @commands.values.map do |subs|
37
+ if subs.kind_of?(Hash)
38
+ subs.values.map do |cmd|
39
+ cmd.help
40
+ end
41
+ else
42
+ subs.help
43
+ end
44
+ end.flatten.join("\n")
45
+ end
46
+
47
+ def add_help_command
48
+ add(Ragent::Command.new(main: 'help',
49
+ recipient: self,
50
+ method: :help_command
51
+ ))
52
+ end
53
+
54
+
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ module Ragent
2
+ module Logging
3
+
4
+ def self.logger=(logger)
5
+ @logger=logger
6
+ end
7
+
8
+ def self.logger
9
+ @logger
10
+ end
11
+
12
+ def logger
13
+ Ragent::Logging.logger
14
+ end
15
+
16
+ def debug str
17
+ logger.debug(str)
18
+ end
19
+
20
+ def warn str
21
+ logger.warn(str)
22
+ end
23
+
24
+ def info str
25
+ logger.info(str)
26
+ end
27
+
28
+ def error str
29
+ logger.error(str)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ module Ragent
2
+ module Plugin
3
+ def self.included(klass)
4
+ klass.send(:include, Ragent::Logging)
5
+ klass.send(:include, Celluloid)
6
+ klass.send(:include, Celluloid::Notifications)
7
+ klass.send(:finalizer, :stop)
8
+ def initialize(ragent)
9
+ @ragent = ragent
10
+ @logger = ragent.logger
11
+ end
12
+
13
+ def configure(*args, &block)
14
+ end
15
+
16
+ def stop
17
+ end
18
+ end
19
+
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,63 @@
1
+ # Ragent::Plugin is reserved for plugins!
2
+ module Ragent
3
+ class Plugins
4
+ include Ragent::Logging
5
+
6
+ def initialize(ragent)
7
+ @ragent=ragent
8
+ @logger=ragent.logger
9
+ @plugins={}
10
+ @running_plugins=[]
11
+ end
12
+
13
+ def load(name,*args, &block)
14
+ info "loading plugin #{name}"
15
+ require "ragent/plugin/#{name}"
16
+ raise "plugin #{name} didn't register" unless @plugins[name.to_s]
17
+ info "loaded plugin #{name}"
18
+ #TODO: load and configure dependencies
19
+ plugin=@plugins[name.to_s]
20
+ info "Configure: #{plugin.name}"
21
+ running_plugin=plugin.new(@ragent)
22
+ running_plugin.configure(*args, &block)
23
+ debug "Configured: #{plugin.name}"
24
+ @running_plugins << running_plugin
25
+ end
26
+
27
+ def register(name, mod)
28
+ @plugins[name.to_s] = mod
29
+ end
30
+
31
+ def start
32
+ @running_plugins.each do |plugin|
33
+ info "Starting: #{plugin.name}"
34
+ # TODO: start dependencies
35
+ plugin.start
36
+ debug "Started: #{plugin.name}"
37
+ end
38
+ end
39
+
40
+ def stop
41
+ @running_plugins.each do |plugin|
42
+ info "Stopping: #{plugin.name}"
43
+ plugin.stop
44
+ debug "Stopped: #{plugin.name}"
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def register_commands
51
+ # stop
52
+ cmd=Ragent::Command.new(main: 'plugins',
53
+ sub: 'list',
54
+ recipient: self,
55
+ method: :plugins_list_command)
56
+ @ragent.commands.add(cmd)
57
+ end
58
+
59
+ def plugins_list_command(options)
60
+ @plugins.values.map do |plugin| plugin.name end.join("\n")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,4 @@
1
+ module Ragent
2
+ VERSION="0.0.1"
3
+ end
4
+
data/lib/ragent.rb ADDED
@@ -0,0 +1,124 @@
1
+ #require 'faye/websocket'
2
+ require 'eventmachine'
3
+ require 'thread'
4
+ require 'celluloid/current'
5
+ require 'celluloid/autostart'
6
+
7
+ require 'active_support/inflector'
8
+
9
+ require 'logging'
10
+ require 'pathname'
11
+
12
+ require_relative 'ragent/logging'
13
+ require_relative 'ragent/plugins'
14
+ require_relative 'ragent/plugin'
15
+ require_relative 'ragent/commands'
16
+ require_relative 'ragent/command'
17
+
18
+ module Ragent
19
+ def self.ragent
20
+ @ragent
21
+ end
22
+
23
+ def self.setup(*args)
24
+ @ragent=Agent.new(*args)
25
+ end
26
+
27
+
28
+ def self.plugin(name,*args, &block)
29
+ @ragent.plugins.load(name,*args, &block) if name.is_a?(Symbol)
30
+ end
31
+
32
+ def self.run
33
+ @ragent.run
34
+ end
35
+
36
+ class Agent
37
+ include Ragent::Logging
38
+
39
+ attr_reader :workdir
40
+ attr_reader :supervisor
41
+ attr_reader :commands
42
+ attr_reader :plugins
43
+
44
+ def initialize(log_level:, workdir:)
45
+ @workdir=Pathname.new(workdir)
46
+ $: << @workdir.join('lib').to_s
47
+
48
+
49
+ Ragent::Logging.logger=::Logging.logger['ragent']
50
+ logger.add_appenders ::Logging.appenders.stdout
51
+
52
+ @commands=Ragent::Commands.new(self)
53
+ register_commands
54
+ @plugins=Plugins.new(self)
55
+ end
56
+
57
+ def run
58
+ @supervisor = Celluloid::Supervision::Container.run!
59
+
60
+
61
+ self_read, @self_write = IO.pipe
62
+
63
+ %w(TERM TTIN INT).each do |sig|
64
+ Signal.trap sig do
65
+ @self_write.puts(sig)
66
+ end
67
+ end
68
+
69
+ #start_em
70
+ @plugins.start
71
+
72
+ stop=false
73
+ while stop || readable_io = IO.select([self_read])
74
+ signal = readable_io.first[0].gets.strip
75
+ stop=handle_signal(signal)
76
+ exit(0)
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ #def start_em
83
+ # EM.epoll
84
+ # Thread.new { EventMachine.run } unless EventMachine.reactor_running?
85
+ # sleep 0.01 until EventMachine.reactor_running?
86
+ #end
87
+
88
+ def handle_signal(signal)
89
+ info "Got signal #{signal}"
90
+ case signal
91
+ when 'TERM','INT'
92
+ info "Shutting down..."
93
+ EM.stop if EventMachine.reactor_running?
94
+ @plugins.stop
95
+ @supervisor.shutdown
96
+ true
97
+ when 'TTIN'
98
+ Thread.list.each do |thread|
99
+ warn "Thread #{thread.object_id.to_s(36)} #{thread['label']}"
100
+ if thread.backtrace
101
+ warn thread.backtrace.join("\n")
102
+ else
103
+ warn "no backtrace available"
104
+ end
105
+ end
106
+ false
107
+ end
108
+ end
109
+
110
+
111
+ def shutdown_command(options={})
112
+ @self_write.puts("TERM")
113
+ end
114
+
115
+ def register_commands
116
+ # stop
117
+ cmd=Ragent::Command.new(main: 'shutdown',
118
+ sub: nil,
119
+ recipient: self,
120
+ method: :shutdown_command)
121
+ @commands.add(cmd)
122
+ end
123
+ end
124
+ end
data/ragent.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ragent/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ragent"
8
+ spec.version = Ragent::VERSION
9
+ spec.authors = ["Peter Schrammel"]
10
+ spec.email = ["peter.schrammel@gmx.de"]
11
+
12
+ spec.summary = %q{An agent framework}
13
+ spec.description = %q{Writing of agents for monitoring, chatting, ... should be easy. Ragent eases this with a small extraction layer over celluloid.}
14
+ spec.homepage = "https://github.com/pschrammel/ragent"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency 'celluloid', '~>0.17.0'
34
+ # spec.add_dependency 'activesupport'
35
+ # spec.add_dependency 'eventmachine'
36
+ # spec.add_dependency 'faye-websocket'
37
+ spec.add_dependency 'logging', '~>2.1'
38
+ # spec.add_dependency 'celluloid-io' #needed for a plugin, should be removed
39
+
40
+ spec.add_development_dependency "bundler", "~> 1.13"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ragent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Schrammel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: celluloid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.17.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.17.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: logging
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Writing of agents for monitoring, chatting, ... should be easy. Ragent
84
+ eases this with a small extraction layer over celluloid.
85
+ email:
86
+ - peter.schrammel@gmx.de
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/ragent
99
+ - examples/Gemfile
100
+ - examples/Gemfile.lock
101
+ - examples/config.ragent
102
+ - examples/lib/ragent/plugin/login.rb
103
+ - examples/lib/ragent/plugin/time_bomb.rb
104
+ - lib/ragent.rb
105
+ - lib/ragent/command.rb
106
+ - lib/ragent/commands.rb
107
+ - lib/ragent/logging.rb
108
+ - lib/ragent/plugin.rb
109
+ - lib/ragent/plugins.rb
110
+ - lib/ragent/version.rb
111
+ - ragent.gemspec
112
+ homepage: https://github.com/pschrammel/ragent
113
+ licenses:
114
+ - MIT
115
+ metadata:
116
+ allowed_push_host: https://rubygems.org
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.5.1
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: An agent framework
137
+ test_files: []