foreman-console 0.0.1.a

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGI3Y2MyZDVmZTRmOTNiMDY3OTBjNjA1MzIwOTczNmVjODVhNjU3Nw==
5
+ data.tar.gz: !binary |-
6
+ MjM5YWViNjYxNTU3MzA0MjQyYzE3ZmRkODM1ZDhlODg3NjYxMDVlYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWM4MTYxZTkxYmRiMDY4YTA1MjJhYmY4MjEzZmVkZWY5Nzg3MzQxZDk3ODZl
10
+ Yzk4YjUxMWM1OGFlYTcwZjYzOTVlNWRlNDA4YzQ1YzYzMGU0ZTQyNjhlNTg3
11
+ NWRhMmVlZWNjZGE5YmE0NmRiMjk2YThjMjQ1NDlkMmQ3ODkxNzA=
12
+ data.tar.gz: !binary |-
13
+ MGU0ZWI3YjI0NWI3NGU0OTc1MzQyZjBiMzFhMDlkZjA3ODJmNmQwNTZkOWY3
14
+ MjBjODVjYWRhNmJhYzkzZjg2ODE2OGUyY2E1ZTRmNWQxNzIyOTMwOGE4NmY5
15
+ YWJjYzk2MTBkMGJiNjVkZmU2NjEyNjM5NmZjYzE5OTllZDRhZDk=
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Ricardo Valeriano dos Santos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
File without changes
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "foreman/console"
6
+
7
+ $stdout.sync = true
8
+ Foreman::Console.new.start
9
+ #Foreman::Console::Prompt.new.start_prompt
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "foreman/console"
6
+
7
+ Foreman::Console::Prompt.new.start_prompt
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "foreman/cli"
6
+ require "foreman/extensions/engine"
7
+
8
+ Foreman::Console::CLI.start
@@ -0,0 +1,116 @@
1
+ unless defined? Foreman
2
+ module Foreman; end
3
+ end
4
+
5
+ require "highline/import"
6
+ require "fileutils"
7
+
8
+ # descobrir quantas linhas tem o terminal atual
9
+ # guardar em buffer a saída do foreman (ao inves de dar puts)
10
+ # - o buffer vai guardar a qtd de linhas do terminal - 2
11
+ # mensagens do foreman (2 linhas são do meu prompt)
12
+ # - sempre que chega uma mensagem do foreman, pinta todo o
13
+ # terminal com as mensagens do e exibe o prompt
14
+ #
15
+ # problema desse é que perde a entrada do usuário
16
+ # se ainda não deu enter, não? =(
17
+ #
18
+ #
19
+ # OPALHES! :D
20
+ #
21
+ # Façamos assim:
22
+ # forka um foreman e um console::prompt
23
+ # - cria pipe para os dois
24
+ # - quando vier write do foreman
25
+ # - puts a entrada e coloca o console::prompt em gets de novo
26
+ # - quando vier um [enter] do console
27
+ # - entra no modo comando
28
+ # - passa a fazer buffer do foreman para exibir quando voltar
29
+ # => voila
30
+ #
31
+ #
32
+ # OU ASSIM:
33
+ # escreve a saída do foreman na entrada do console
34
+ # - console decide se é modo comando
35
+ # - se for, para de output do foreman e aguarda comando
36
+ # - se não, só mostra saída do foreman
37
+
38
+ class Foreman::Console
39
+ class Prompt
40
+ def initialize
41
+ @last_status = "Hi! Ready for work"
42
+ end
43
+
44
+ def start_prompt
45
+ #loop do
46
+ # cmd = ask(@last_status) do |q|
47
+ # q.readline = true
48
+ # end
49
+
50
+ # say("Going to \"#{cmd}\"...")
51
+ # @last_status = "====== " << process_command(cmd) << "\n $ > "
52
+ # break if cmd == "quit"
53
+ #end
54
+ puts "here is the time to attach a console/prompt/terminal"
55
+ gets
56
+ #puts "------ #{cmd} ------"
57
+ end
58
+
59
+ def process_command(cmd)
60
+ say "processing #{cmd}\n"
61
+ rand(10293)
62
+ end
63
+ end
64
+
65
+ def initialize
66
+ @commands = [:relaunch, :quit]
67
+ @readers = {}
68
+ @foreman_pid = nil
69
+ @prompt_pid = nil
70
+
71
+ @last_status = "Hi! Ready for work"
72
+ end
73
+
74
+ def start
75
+ start_foreman
76
+ start_prompt
77
+
78
+ @foreman_buffer = []
79
+
80
+ loop do
81
+ io = IO.select(@readers.values)
82
+ (io.nil? ? [] : io.first).each do |reader|
83
+ is_from_foreman = @readers.key(reader) == @foreman_pid
84
+ if is_from_foreman
85
+ output reader.gets
86
+ else
87
+ output "...#{reader.gets}"
88
+ #output "YAY!, command mode."
89
+ #command = reader.gets.chomp
90
+ #output "going to: #{command}"
91
+ #next if command == "back"
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ def output(line)
98
+ ## buffer?
99
+ $stdout.write line
100
+ end
101
+
102
+ def pipe_process(command)
103
+ reader, writer = IO.pipe
104
+ pid = Process.spawn({}, command, out: writer)
105
+ @readers[pid] = reader
106
+ pid
107
+ end
108
+
109
+ def start_foreman
110
+ @foreman_pid = pipe_process "./bin/foreman-for-console start"
111
+ end
112
+
113
+ def start_prompt
114
+ @prompt_pid = pipe_process "./bin/foreman-console-prompt"
115
+ end
116
+ end
@@ -0,0 +1,119 @@
1
+ module Foreman::Console; end
2
+
3
+ class Foreman::Console::Engine < Foreman::Engine::CLI
4
+ # here we put the logic to receive and process commands
5
+ def start
6
+ register_signal_handlers
7
+ startup
8
+ spawn_processes
9
+ watch_for_output
10
+ sleep 0.1
11
+ watch_for_input
12
+ sleep 0.1
13
+ watch_for_termination { |pid| child_killed pid }
14
+ shutdown
15
+ end
16
+
17
+ def execute_command(raw_command)
18
+ system ".........."
19
+ system "going to #{raw_command}"
20
+ command, process_name = raw_command.split " "
21
+ if command == "relaunch"
22
+ system "relaunch #{process_name}"
23
+ end
24
+ end
25
+
26
+ def command_mode!
27
+ loop do
28
+ command = $stdin.gets.chomp
29
+ if command == "quit"
30
+ system "good bye command mode"
31
+ break
32
+ else
33
+ execute_command command
34
+ end
35
+ end
36
+ end
37
+
38
+ def watch_for_input
39
+ Thread.new do
40
+ loop do
41
+ raw_command = $stdin.gets
42
+ if raw_command == "\n"
43
+ system "AE!"
44
+ system "command mode! :D"
45
+ system "maybe a good idea is supress the output for now XD"
46
+ system "-------"
47
+ command_mode!
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def watch_for_termination(&terminator)
54
+ pid, status = Process.wait2
55
+ output_with_mutex name_for(pid), termination_message_for(status)
56
+ @running.delete(pid)
57
+ if block_given?
58
+ terminator.arity == 1 ? yield(pid) : yield
59
+ end
60
+ pid
61
+ rescue Errno::ECHILD
62
+ end
63
+
64
+ def child_killed(pid)
65
+ system "good bye #{pid}, it was a good run."
66
+ if @running.size == 0
67
+ system "no processes remaining, going down."
68
+ terminate_gracefully
69
+ else
70
+ watch_for_termination { |pid| child_killed(pid) }
71
+ end
72
+ end
73
+
74
+ def spawn_processes
75
+ @processes.each do |process|
76
+ spawn process
77
+ end
78
+ end
79
+
80
+ def spawn(process)
81
+ 1.upto(formation[@names[process]]) do |n|
82
+ reader, writer = create_pipe
83
+ begin
84
+ pid = process.run(:output => writer, :env => {
85
+ "PORT" => port_for(process, n).to_s,
86
+ "PS" => name_for_index(process, n)
87
+ })
88
+ writer.puts "started with pid #{pid}"
89
+ rescue Errno::ENOENT
90
+ writer.puts "unknown command: #{process.command}"
91
+ end
92
+ @running[pid] = [process, n]
93
+ @readers[pid] = reader
94
+ end
95
+ end
96
+
97
+ def respawn(process_name)
98
+ spawn @names.invert[process_name]
99
+ end
100
+
101
+ private
102
+ def name_for_index(process, index)
103
+ [ @names[process], index.to_s ].compact.join(".")
104
+ end
105
+ end
106
+
107
+ class Foreman::Console::CLI < Foreman::CLI
108
+ def self.start
109
+ puts "-------------"
110
+ puts "PROCESS ID: #{Process.pid}"
111
+ super
112
+ end
113
+
114
+ no_tasks do
115
+ def engine
116
+ @engine ||= Foreman::Console::Engine.new options
117
+ end
118
+ end
119
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman-console
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.a
5
+ platform: ruby
6
+ authors:
7
+ - Ricardo Valeriano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: foreman
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.63.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.63.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.14.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.14.1
41
+ description: ! 'When working on various branches in the same project, you may want
42
+ to relaunch
43
+
44
+ (kill and run again) some process after change branch, but not all.
45
+
46
+ An example can be: restart rails server, but let the redis server alone.
47
+
48
+ foreman-console allows you to do it!
49
+
50
+ '
51
+ email: ricardo.valeriano@gmail.com
52
+ executables:
53
+ - foreman-console
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - lib/foreman/console.rb
58
+ - lib/foreman/extensions/engine.rb
59
+ - bin/foreman-console
60
+ - bin/foreman-console-prompt
61
+ - bin/foreman-for-console
62
+ - LICENSE
63
+ - README.md
64
+ homepage: http://github.com/ricardovaleriano/foreman-console
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>'
80
+ - !ruby/object:Gem::Version
81
+ version: 1.3.1
82
+ requirements: []
83
+ rubyforge_project: foreman-console
84
+ rubygems_version: 2.1.8
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Abillity to relaunch specifics process on foreman
88
+ test_files: []