adminix 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95a49d190d16c14ccd3cccc09e06732568f0e9cd
4
- data.tar.gz: 5a2e0e20318f38da17a6e4b118ead094c3ae97a3
3
+ metadata.gz: 7d1340dfd107acc28ac80b42c73ca5a810043d4f
4
+ data.tar.gz: bf6eaa5de07b2efafabcc77c2b4bd7b5df7ffd1e
5
5
  SHA512:
6
- metadata.gz: 9452e2d00bfd6e3ac1aafc78a0293d021050e3018f71dfbe183450ce9a169ec701631c7ad43936a9b747952488ae286a11fb99b0f5d51fc523c1850a1514c559
7
- data.tar.gz: f1731de81b7c47a8ad54b841496e188a86535e66f2f35bd29530c725809a95596911cb4dd31c87bd6a60c3ea3a2d9dfd30e6b5e89fc02c1d9980b3efc51e5d4b
6
+ metadata.gz: fd09d0eb87229096618c129cc0278c31e6f2b19fd6575f35d6f4007d73e11fe95945f70091c32e6b99ebb8e647df7459c12bf18ee11e44d37d8b884569087c35
7
+ data.tar.gz: 64e2bd6508b630a83cf8137e258ee6a0c7c784a765b5b23d4ffab9c9ed855a4bd0c45bdbeb77f21494b3ded7abef77e1a07baf78984f6cb2d8a2cf3f8af8c8c1
data/.byebug_history CHANGED
@@ -1,4 +1,12 @@
1
1
  q
2
+ output = system.eval(script)
3
+ script
4
+ args['args'].each { |hs| script.gsub!("%{#{hs[0]}}", hs[1]) }
5
+ script = command['command'].dup
6
+ command = config.commands.find { |c| c['key'] == key }
7
+ args
8
+ key
9
+ q
2
10
  options
3
11
  options[:action].to_sym
4
12
  parsers[options[:action].to_sym]
@@ -246,11 +254,3 @@ Adminix::Config.instance.errors
246
254
  Adminix::Config.instance
247
255
  q
248
256
  Adminix::Config.instance.errors
249
- Adminix::Config.instance.valid?
250
- Adminix::Config.instance
251
- q
252
- service_id
253
- service_name
254
- q
255
- service_name
256
- self.service_name = hs['service_name']
data/exe/adminix CHANGED
@@ -5,6 +5,8 @@ require 'optparse'
5
5
 
6
6
  options = {
7
7
  action: "help",
8
+ secret_key: ENV['ADMINIX_SECRET_KEY'],
9
+ service_id: ENV['ADMINIX_SERVICE_ID'],
8
10
  daemonize: false,
9
11
  stop_daemon: false
10
12
  }
@@ -12,7 +14,9 @@ parsers = {}
12
14
 
13
15
  parsers[:env] = OptionParser.new do |opts|
14
16
  opts.banner = "Display the commands to define ENV variables"
15
- opts.separator " Usage: adminix env"
17
+ opts.separator " Usage: adminix env [options]"
18
+ opts.on("--secret-key SECRET_KEY", "define api SECRET_KEY") { |key| options[:secret_key] = key }
19
+ opts.on("--service-id SERVICE_ID", "define api SERVICE_ID") { |id| options[:service_id] = id }
16
20
  opts.separator ""
17
21
  end
18
22
 
@@ -21,6 +25,8 @@ parsers[:watch] = OptionParser.new do |opts|
21
25
  opts.separator " Usage: adminix watch"
22
26
  opts.separator " Usage: adminix watch [options]"
23
27
  opts.separator " Options:"
28
+ opts.on("--secret-key SECRET_KEY", "define api SECRET_KEY") { |key| options[:secret_key] = key }
29
+ opts.on("--service-id SERVICE_ID", "define api SERVICE_ID") { |id| options[:service_id] = id }
24
30
  opts.on("-d", "--daemonize", "run watcher in background process") { options[:daemonize] = true }
25
31
  opts.on("-s", "--stop-daemon", "stop daemon watcher") { options[:stop_daemon] = true }
26
32
  opts.separator ""
@@ -35,10 +41,15 @@ end
35
41
  options[:action] = ARGV[0] || "help"
36
42
  parsers[options[:action].to_sym].parse!(ARGV) rescue nil
37
43
 
38
- require "adminix" unless options[:action] == "help"
44
+ unless options[:action] == "help"
45
+ require'adminix'
46
+ Adminix::Config.instance.secret_key = options[:secret_key]
47
+ Adminix::Config.instance.service_id = options[:service_id]
48
+ Adminix::Config.instance.daemon = options[:daemonize]
49
+ end
39
50
 
40
51
  case options[:action]
41
- when "env"
52
+ when "env"
42
53
  puts Adminix::Service.instance.options_to_envs
43
54
  when "watch"
44
55
  puts Adminix::Watcher.run!(options)
@@ -6,12 +6,13 @@ module Adminix
6
6
 
7
7
  DEFAULT_HOST = 'http://api.adminix.io'.freeze
8
8
 
9
- attr_accessor :service_id, :secret_key, :host
9
+ attr_accessor :service_id, :secret_key, :host, :commands, :daemon
10
10
 
11
11
  def initialize
12
- self.service_id = ENV['ADMINIX_SERVICE_ID']
13
- self.secret_key = ENV['ADMINIX_SECRET_KEY']
12
+ #self.service_id = ENV['ADMINIX_SERVICE_ID']
13
+ #self.secret_key = ENV['ADMINIX_SECRET_KEY']
14
14
  self.host = ENV['ADMINIX_CONFIG_HOST'] || DEFAULT_HOST
15
+ self.commands = []
15
16
  end
16
17
  end
17
18
  end
@@ -1,4 +1,5 @@
1
1
  require 'singleton'
2
+ require 'net/http'
2
3
 
3
4
  module Adminix
4
5
  class Service
@@ -11,6 +12,8 @@ module Adminix
11
12
  end
12
13
 
13
14
  def to_cable
15
+ system.check_system_load
16
+
14
17
  {
15
18
  id: id,
16
19
  process_id: process_id,
@@ -23,6 +26,7 @@ module Adminix
23
26
 
24
27
  def sync(watcher, data)
25
28
  @process_id = data['process_id']
29
+ config.commands = data['commands'] || []
26
30
 
27
31
  commands_queue = data['commands_queue'] || []
28
32
  commands_queue.each do |q|
@@ -68,8 +72,11 @@ module Adminix
68
72
  # TODO frontend fix attribute args
69
73
  args['args'].each { |hs| script.gsub!("%{#{hs[0]}}", hs[1]) }
70
74
 
71
- output = system.eval(script)
72
-
75
+ output = system.eval(script)
76
+ system.log "Command execution output: "
77
+ system.log output
78
+ system.log "-----------------------------------"
79
+
73
80
  {
74
81
  id: process_id,
75
82
  success: true,
@@ -28,10 +28,10 @@ module Adminix
28
28
  attr_reader :os, :processor_load, :memory_load, :username, :home, :adminix_bin, :ruby_version
29
29
 
30
30
  def initialize
31
- _define_os
32
- _parse_system_info
33
- _define_adminix_bin
34
- _check_system_load
31
+ define_os
32
+ parse_system_info
33
+ define_adminix_bin
34
+ check_system_load
35
35
  end
36
36
 
37
37
  def generate_daemon
@@ -53,9 +53,28 @@ module Adminix
53
53
  @username == 'root'
54
54
  end
55
55
 
56
+ def check_system_load
57
+ case @os
58
+ when :mac
59
+ @processor_load = `ps -A -o %cpu | awk '{s+=$1} END {print s "%"}'`.to_f
60
+ @memory_load = 0.1
61
+ when :linux, :unix
62
+ @processor_load = `grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'`.to_f
63
+ @memory_load = `free | grep Mem | awk '{print $3/$2 * 100.0}'`.to_f
64
+ end
65
+ end
66
+
67
+ def log(message)
68
+ puts message unless config.daemon
69
+ end
70
+
56
71
  private
57
72
 
58
- def _define_os
73
+ def config
74
+ Config.instance
75
+ end
76
+
77
+ def define_os
59
78
  @os = if self.class.windows?
60
79
  :windows
61
80
  elsif self.class.mac?
@@ -67,30 +86,19 @@ module Adminix
67
86
  end
68
87
  end
69
88
 
70
- def _parse_system_info
89
+ def parse_system_info
71
90
  @username = ENV['USER'] || `whoami`.split("\n")[0]
72
91
  @home = "/home/#{@username}"
73
92
  @ruby_version = RUBY_VERSION
74
93
  end
75
94
 
76
- def _define_adminix_bin
95
+ def define_adminix_bin
77
96
  @adminix_bin = if self.class.rvm?
78
97
  "/home/#{@username}/.rvm/gems/ruby-#{@ruby_version}/wrappers/adminix"
79
98
  else
80
99
  "/usr/local/bin/adminix"
81
100
  end
82
101
  end
83
-
84
- def _check_system_load
85
- case @os
86
- when :mac
87
- @processor_load = `ps -A -o %cpu | awk '{s+=$1} END {print s "%"}'`.to_f
88
- @memory_load = 0.1
89
- when :linux, :unix
90
- @processor_load = `grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'`.to_f
91
- @memory_load = `free | grep Mem | awk '{print $3/$2 * 100.0}'`.to_f
92
- end
93
- end
94
102
  end
95
103
  end
96
104
 
@@ -1,3 +1,3 @@
1
1
  module Adminix
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
@@ -38,7 +38,6 @@ module Adminix
38
38
  end
39
39
 
40
40
  @client.connect do |message|
41
- puts message
42
41
  on_message_receive(@client, message)
43
42
  end
44
43
 
@@ -98,7 +97,7 @@ module Adminix
98
97
  if pid != 0
99
98
  Process.kill('HUP', pid.to_i)
100
99
  File.delete(@pid_full)
101
- puts "Stopped"
100
+ system.log "Stopped"
102
101
  else
103
102
  warn "Daemon is not running"
104
103
  exit -1
@@ -111,13 +110,17 @@ module Adminix
111
110
  Config.instance
112
111
  end
113
112
 
113
+ def system
114
+ System.instance
115
+ end
116
+
114
117
  def on_message_receive(client, message)
115
118
  case message['type']
116
119
  when 'welcome'
117
- puts 'connected to server'
120
+ system.log 'connected to server'
118
121
  on_success_connect(client)
119
122
  when 'ping'
120
- puts 'ping from server'
123
+ #system.log 'ping from server'
121
124
  # do something
122
125
  else
123
126
  # do something
@@ -125,9 +128,9 @@ module Adminix
125
128
  end
126
129
 
127
130
  def on_disconnect(client)
128
- puts 'Disconnected. Reconnecting...'
131
+ system.log 'Disconnected. Reconnecting...'
129
132
  client.connect do |message|
130
- puts message
133
+ system.log message
131
134
  on_message_receive(client, message)
132
135
  end
133
136
 
@@ -143,9 +146,7 @@ module Adminix
143
146
  end
144
147
 
145
148
  def on_service_message_receive(type, data)
146
- puts 'on_service_message_receive'
147
- puts type
148
- puts data
149
+ system.log 'on_service_message_receive'
149
150
  case type
150
151
  when 'confirm_subscription'
151
152
  when 'sync'
@@ -155,7 +156,7 @@ module Adminix
155
156
 
156
157
  def trap_signal
157
158
  Signal.trap("SIGINT") do
158
- puts "Stopping..."
159
+ system.log "Stopping..."
159
160
  EventMachine.stop
160
161
  end
161
162
  end
@@ -19,7 +19,7 @@ module Adminix
19
19
  self.channel_handlers = {}
20
20
  self.client = EventMachine::WebSocketClient.connect(url)
21
21
  client.callback do
22
- puts "Connected WebSocket to #{url}."
22
+ system.log "Connected WebSocket to #{url}."
23
23
  self.connected = true
24
24
  end
25
25
  client.stream do |raw|
@@ -79,6 +79,12 @@ module Adminix
79
79
  result['data'] = JSON.parse(result['data']) if result['data']
80
80
  result
81
81
  end
82
+
83
+ private
84
+
85
+ def system
86
+ System.instance
87
+ end
82
88
  end
83
89
  end
84
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adminix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Dyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  requirements: []
172
172
  rubyforge_project:
173
- rubygems_version: 2.6.10
173
+ rubygems_version: 2.6.8
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Adminix