adminix 0.1.0 → 0.1.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 +4 -4
- data/.byebug_history +119 -8
- data/adminix.gemspec +5 -3
- data/exe/adminix +86 -2
- data/lib/adminix/config.rb +4 -1
- data/lib/adminix/entrypoint.rb +4 -3
- data/lib/adminix/service.rb +92 -15
- data/lib/adminix/system.rb +96 -0
- data/lib/adminix/version.rb +1 -1
- data/lib/adminix/watcher.rb +29 -32
- data/lib/adminix.rb +9 -1
- data/views/daemon_scripts/upstart.conf.erb +23 -0
- metadata +22 -18
- data/lib/adminix/.config.rb.swp +0 -0
- data/lib/adminix/.entrypoint.rb.swp +0 -0
- data/lib/adminix/.service.rb.swo +0 -0
- data/lib/adminix/.service.rb.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa09928aefcfe976248217053c3f54809122d4d
|
4
|
+
data.tar.gz: 262d96bc6d210d70e8604035ed5dbb558565e0ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ede0608a07eaf5e8fda6d0b8d5878ada193d6ee3293b964a4aed8bd03d432db386491db5179843a61453355e148aef9ba91c69d73c94dbe16c2addba283ca08
|
7
|
+
data.tar.gz: 75070320f47c6291103b3194aa629b31bc5237bbf65baf20140f845208797d756a50cfab8e84f8113a2cb0da72f44199b50febbbbc9a9c5984f477f7142a5fb6
|
data/.byebug_history
CHANGED
@@ -1,4 +1,123 @@
|
|
1
1
|
q
|
2
|
+
System.instance.eval(script)
|
3
|
+
script
|
4
|
+
args['args'].each { |hs| script.gsub!("%{#{hs[0]}}", hs[1]) }
|
5
|
+
script = "echo \"%{message}\""
|
6
|
+
script = "echo \"#{message}\""
|
7
|
+
script = command['command']
|
8
|
+
System.instance.eval(script)
|
9
|
+
script
|
10
|
+
System.instance.eval(script)
|
11
|
+
script
|
12
|
+
args["args"].each { |hs| script.gsub!(hs[0], hs[1]) }
|
13
|
+
args["args"].each { |hs| hs.gsub!(hs[0], hs[1]) }
|
14
|
+
args[:args].each { |hs| hs.gsub!(hs[0], hs[1]) }
|
15
|
+
args
|
16
|
+
script
|
17
|
+
args.each { |hs| script.gsub(hs[0], hs[1]) }
|
18
|
+
script
|
19
|
+
args.each { |hs| script.gsub!(hs[0], hs[1]) }
|
20
|
+
args.each { |hs| hs.gsub!(hs[0], hs[1]) }
|
21
|
+
script = command['command']
|
22
|
+
command = config.commands.find { |c| c['key'] == key }
|
23
|
+
config.commands
|
24
|
+
commands
|
25
|
+
command = commands.find { |c| c['key'] == key }
|
26
|
+
args
|
27
|
+
key
|
28
|
+
q
|
29
|
+
File.open(file_path, 'w') { |file| file.write(file_content) }
|
30
|
+
File.delete(file_path) if File.exists?(file_path)
|
31
|
+
sudo?
|
32
|
+
next
|
33
|
+
c
|
34
|
+
`showami`
|
35
|
+
render = ERB.new(template).result(binding)
|
36
|
+
render = ERB.new(@template).result(binding)
|
37
|
+
template = File.read("views/daemon_scripts/upstart.conf.erb")
|
38
|
+
binding
|
39
|
+
q
|
40
|
+
(b.local_variable_set(:username, 'ubuntu'))
|
41
|
+
b.local_variable_set(:username, 'ubuntu')
|
42
|
+
b.local_variable_set(:b, 'b')
|
43
|
+
b.local_variable_set(:a, 'a')
|
44
|
+
b = binding
|
45
|
+
(b = binding)
|
46
|
+
b = binding
|
47
|
+
puts output = renderer.result(deploy: 'deploy')
|
48
|
+
puts output = renderer.result()
|
49
|
+
renderer = ERB.new(template)
|
50
|
+
puts output = renderer.result()
|
51
|
+
renderer = ERB.new(template, username: 'deploy')
|
52
|
+
puts output = renderer.result()
|
53
|
+
renderer = ERB.new(template)
|
54
|
+
template = File.read("views/daemon_scripts/upstart.conf.erb")
|
55
|
+
require 'views/daemon_scripts/upstart.conf.erb'
|
56
|
+
q
|
57
|
+
Adminix::System.instance
|
58
|
+
Adminix::System.mac?
|
59
|
+
Adminix::System.instance.processor_load
|
60
|
+
c
|
61
|
+
Adminix::System.instance.processor_load
|
62
|
+
c
|
63
|
+
Adminix::System.instance.processor_load
|
64
|
+
c
|
65
|
+
`grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'`
|
66
|
+
ps -A -o %cpu | awk '{s+=$1} END {print s "%"}
|
67
|
+
ps -A -o %cpu | awk '{s+=$1} END {print s "%"}'
|
68
|
+
Adminix::System.instance.processor_load
|
69
|
+
Adminix::System.instance.os
|
70
|
+
c
|
71
|
+
Adminix::System.instance.os
|
72
|
+
c
|
73
|
+
Adminix::System.instance.os
|
74
|
+
Adminix::System.instance.processor_load
|
75
|
+
c
|
76
|
+
Adminix::System.instance.processor_load
|
77
|
+
Adminix::System.instance.os
|
78
|
+
Adminix::System.linux?
|
79
|
+
Adminix::System.unix?
|
80
|
+
Adminix::System.instance.processor_load
|
81
|
+
Adminix::System.instance
|
82
|
+
Adminix::System.unix?
|
83
|
+
c
|
84
|
+
Adminix::System.unix?
|
85
|
+
Adminix::System.mac?
|
86
|
+
Adminix::System.instance.os
|
87
|
+
Adminix::System.instance
|
88
|
+
c
|
89
|
+
Adminix::System.instance
|
90
|
+
c
|
91
|
+
Adminix::System.instance
|
92
|
+
Adminix::System
|
93
|
+
c
|
94
|
+
Adminix::Service
|
95
|
+
Adminix::System
|
96
|
+
c
|
97
|
+
Adminix::System
|
98
|
+
Adminix::Config
|
99
|
+
System
|
100
|
+
Adminix::System
|
101
|
+
c
|
102
|
+
Adminix::System
|
103
|
+
Adminix
|
104
|
+
c
|
105
|
+
config.valid?
|
106
|
+
config.errors
|
107
|
+
config.import
|
108
|
+
config
|
109
|
+
config.errors
|
110
|
+
config.valid?
|
111
|
+
config.errors
|
112
|
+
config.service_name
|
113
|
+
config.name
|
114
|
+
config.to_api
|
115
|
+
c
|
116
|
+
config.errors
|
117
|
+
config.valid?
|
118
|
+
config = Adminix::Config.instance
|
119
|
+
ENV['ADMINIX_CONFIG_PATH'] = generate_fake_config_file
|
120
|
+
q
|
2
121
|
service.options_to_envs
|
3
122
|
service.options_to_env
|
4
123
|
service.id = 1
|
@@ -135,11 +254,3 @@ q
|
|
135
254
|
require 'faker'
|
136
255
|
Faker
|
137
256
|
q
|
138
|
-
require 'faker'
|
139
|
-
generate_config_file
|
140
|
-
q
|
141
|
-
File.open('tmp/spec/adminix.json', 'w') { |file| file.write(hs.to_json) }
|
142
|
-
@config_file_path = 'tmp/spec/adminix.json'
|
143
|
-
File.open('adminix.json', 'w') { |file| file.write(hs.to_json) }
|
144
|
-
hs.to_json
|
145
|
-
JSON
|
data/adminix.gemspec
CHANGED
@@ -30,11 +30,13 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency "
|
33
|
+
#spec.add_dependency "daemons", "~> 1.2.4"
|
34
|
+
#spec.add_dependency "action_cable_client", "~> 1.3", ">= 1.3.4"
|
35
|
+
spec.add_dependency "eventmachine", "1.2.2"
|
34
36
|
|
35
37
|
spec.add_development_dependency "bundler", "~> 1.14"
|
36
38
|
spec.add_development_dependency "rake", "~> 10.0"
|
37
39
|
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
-
spec.add_development_dependency "byebug", "~> 9.0.6"
|
39
|
-
spec.add_development_dependency "faker", "~> 1.7.2"
|
40
|
+
spec.add_development_dependency "byebug", "~> 9.0", ">= 9.0.6"
|
41
|
+
spec.add_development_dependency "faker", "~> 1.7", ">= 1.7.2"
|
40
42
|
end
|
data/exe/adminix
CHANGED
@@ -1,5 +1,89 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
2
3
|
|
3
|
-
require '
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = { action: "help" }
|
7
|
+
parsers = {}
|
8
|
+
|
9
|
+
parsers[:env] = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Display the commands to define ENV variables"
|
11
|
+
opts.separator " Usage: adminix env"
|
12
|
+
opts.separator ""
|
13
|
+
end
|
14
|
+
|
15
|
+
parsers[:watch] = OptionParser.new do |opts|
|
16
|
+
opts.banner = "Launch Adminix watcher"
|
17
|
+
opts.separator " Usage: adminix watch"
|
18
|
+
#opts.separator " Usage: adminix watcher [options]"
|
19
|
+
#opts.separator " Options:"
|
20
|
+
#opts.on("-d", "--daemonize", "run watcher in background process") { options[:daemonize] = true }
|
21
|
+
opts.separator ""
|
22
|
+
end
|
23
|
+
|
24
|
+
parsers[:generate_daemon] = OptionParser.new do |opts|
|
25
|
+
opts.banner = "Generate upstart script for watcher"
|
26
|
+
opts.separator " Usage: adminix generate_daemon"
|
27
|
+
opts.separator ""
|
28
|
+
end
|
29
|
+
|
30
|
+
parsers[:setup] = OptionParser.new do |opts|
|
31
|
+
opts.banner = "Generage adminix.json"
|
32
|
+
opts.separator " Usage: adminix setup"
|
33
|
+
opts.separator ""
|
34
|
+
end
|
35
|
+
|
36
|
+
parsers[:version] = OptionParser.new do |opts|
|
37
|
+
opts.banner = "Show the Adminix version"
|
38
|
+
opts.separator " Usage: adminix version"
|
39
|
+
opts.separator ""
|
40
|
+
end
|
41
|
+
|
42
|
+
options[:action] = ARGV[0] || "help"
|
43
|
+
parsers[options[:action].to_sym].parse!(ARGV) rescue nil
|
44
|
+
|
45
|
+
require "adminix" unless options[:action] == "help"
|
46
|
+
|
47
|
+
case options[:action]
|
48
|
+
when "env"
|
49
|
+
puts Adminix::Service.instance.options_to_envs
|
50
|
+
when "watch"
|
51
|
+
puts Adminix::Watcher.run!(options)
|
52
|
+
when "generate_daemon"
|
53
|
+
path = Adminix::System.instance.generate_daemon
|
54
|
+
puts "# Daemon has been generated in path #{path}\n" +
|
55
|
+
"# Please execute this command to copy adminix.conf to /etc/init folder:\n" +
|
56
|
+
"sudo mv adminix.conf /etc/init/adminix.conf\n"
|
57
|
+
|
58
|
+
when "setup"
|
59
|
+
approved = true
|
60
|
+
if Adminix::Config.instance.file_exists?
|
61
|
+
puts "File \"#{ENV['HOME']}/.adminix.json\" already exists, overwrite config (yes/no):"
|
62
|
+
approved = ['yes', 'y'].include?($stdin.gets.chomp)
|
63
|
+
end
|
64
|
+
|
65
|
+
if approved
|
66
|
+
puts "Enter secret key:"
|
67
|
+
secret_key = $stdin.gets.chomp
|
68
|
+
|
69
|
+
puts "Enter service id (empty to create a new service)"
|
70
|
+
service_id = $stdin.gets.chomp
|
71
|
+
|
72
|
+
service_name = ''
|
73
|
+
if service_id == ''
|
74
|
+
puts "Enter service name"
|
75
|
+
service_name = $stdin.gets.chomp
|
76
|
+
end
|
77
|
+
|
78
|
+
Adminix::Config.setup(
|
79
|
+
secret_key: secret_key,
|
80
|
+
service_id: service_id,
|
81
|
+
service_name: service_name
|
82
|
+
)
|
83
|
+
end
|
84
|
+
when "version"
|
85
|
+
puts "adminix version #{Adminix::VERSION}"
|
86
|
+
else
|
87
|
+
puts parsers.map { |v| v[1].to_s }
|
88
|
+
end
|
4
89
|
|
5
|
-
Adminix::Entrypoint.execute_action(ARGV || [])
|
data/lib/adminix/config.rb
CHANGED
@@ -10,6 +10,7 @@ module Adminix
|
|
10
10
|
attr_accessor(
|
11
11
|
:service_name,
|
12
12
|
:service_id,
|
13
|
+
:service_address,
|
13
14
|
:host,
|
14
15
|
:secret_key,
|
15
16
|
:monitor_logs_paths,
|
@@ -31,6 +32,7 @@ module Adminix
|
|
31
32
|
{
|
32
33
|
service_name: service_name,
|
33
34
|
service_id: service_id,
|
35
|
+
service_address: service_address,
|
34
36
|
secret_key: secret_key,
|
35
37
|
options: options || [],
|
36
38
|
commands: commands || []
|
@@ -54,11 +56,12 @@ module Adminix
|
|
54
56
|
|
55
57
|
self.service_name = hs['service_name']
|
56
58
|
self.service_id = hs['service_id']
|
59
|
+
self.service_address = hs['service_address']
|
57
60
|
self.secret_key = hs['secret_key']
|
58
61
|
self.host = hs['host'] || ENV['ADMINIX_CONFIG_HOST'] || DEFAULT_HOST
|
59
62
|
self.options = hs['options'] || []
|
60
63
|
self.commands = hs['commands'] || []
|
61
|
-
|
64
|
+
|
62
65
|
valid?
|
63
66
|
end
|
64
67
|
|
data/lib/adminix/entrypoint.rb
CHANGED
data/lib/adminix/service.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'json'
|
3
|
-
|
3
|
+
require 'net/http'
|
4
|
+
require 'byebug'
|
4
5
|
module Adminix
|
5
6
|
class Service
|
6
7
|
include Singleton
|
7
8
|
|
8
|
-
attr_accessor :id, :process_id, :name, :address
|
9
|
+
attr_accessor :id, :process_id, :name, :address, :completed_commands
|
9
10
|
|
10
11
|
def initialize
|
12
|
+
config.import
|
13
|
+
|
11
14
|
self.id = config.service_id
|
12
15
|
self.name = config.service_name
|
13
|
-
self.address =
|
14
|
-
|
15
|
-
config.import
|
16
|
+
self.address = config.service_address
|
17
|
+
self.completed_commands = []
|
16
18
|
end
|
17
19
|
|
18
20
|
# Send info about container
|
@@ -24,28 +26,56 @@ module Adminix
|
|
24
26
|
|
25
27
|
payload = {
|
26
28
|
service: {
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
id: id,
|
30
|
+
process_id: process_id,
|
31
|
+
completed_commands: completed_commands
|
30
32
|
}
|
31
33
|
}
|
32
|
-
|
33
|
-
payload[:service][:id] = id unless id.nil?
|
34
34
|
|
35
|
-
|
35
|
+
if process_id.nil?
|
36
|
+
payload[:service][:name] = name
|
37
|
+
payload[:service][:address] = address
|
38
|
+
payload[:service][:options] = service_options_payload
|
39
|
+
payload[:service][:commands] = service_commands_payload
|
40
|
+
end
|
36
41
|
|
42
|
+
puts payload
|
43
|
+
puts "=========="
|
44
|
+
|
45
|
+
request.body = payload.to_json
|
37
46
|
req_options = {}
|
38
47
|
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
39
48
|
http.request(request)
|
40
49
|
end
|
41
|
-
data = JSON.parse(response.body)
|
50
|
+
data = JSON.parse(response.body)['result']
|
51
|
+
|
52
|
+
self.completed_commands = []
|
53
|
+
self.process_id = data['process_id']
|
54
|
+
|
55
|
+
if id.nil?
|
56
|
+
self.id = data['id']
|
57
|
+
config.service_id = id
|
58
|
+
config.export
|
59
|
+
end
|
60
|
+
|
61
|
+
commands_queue = data['commands_queue'] || []
|
62
|
+
puts commands_queue
|
63
|
+
commands_queue.each do |q|
|
64
|
+
if q['status'] != 'processed'
|
65
|
+
execute_command(q['command_key'], q['process_id'], q['args'] || {})
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def run_cmd(cmd)
|
71
|
+
`#{cmd}`
|
42
72
|
end
|
43
73
|
|
44
74
|
def config
|
45
75
|
Config.instance
|
46
76
|
end
|
47
77
|
|
48
|
-
def
|
78
|
+
def service_options_payload
|
49
79
|
config.options.map do |o|
|
50
80
|
{
|
51
81
|
key: o['key'],
|
@@ -54,12 +84,53 @@ module Adminix
|
|
54
84
|
value_type: o['type'],
|
55
85
|
options: o['options'],
|
56
86
|
validations: o['validations'],
|
57
|
-
default_value: o['default_value']
|
87
|
+
default_value: o['default_value'],
|
88
|
+
value: o['default_value']
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def service_commands_payload
|
94
|
+
config.commands.map do |o|
|
95
|
+
{
|
96
|
+
key: o['key'],
|
97
|
+
name: o['name'],
|
98
|
+
description: o['description'],
|
99
|
+
#command: o['command'],
|
100
|
+
arguments: o['arguments']
|
58
101
|
}
|
59
102
|
end
|
60
103
|
end
|
61
104
|
|
62
|
-
def execute_command
|
105
|
+
def execute_command(key, process_id, args)
|
106
|
+
command = config.commands.find { |c| c['key'] == key }
|
107
|
+
script = command['command'].dup
|
108
|
+
|
109
|
+
# TODO frontend fix attribute args
|
110
|
+
args['args'].each { |hs| script.gsub!("%{#{hs[0]}}", hs[1]) }
|
111
|
+
|
112
|
+
puts System.instance.eval(script)
|
113
|
+
|
114
|
+
#self.completed_commands << process_id
|
115
|
+
|
116
|
+
uri = URI.parse("#{config.host}/v1/services/#{id}")
|
117
|
+
request = Net::HTTP::Put.new(uri)
|
118
|
+
request.content_type = "application/json"
|
119
|
+
request["Authorization"] = "Bearer #{config.secret_key}"
|
120
|
+
|
121
|
+
payload = {
|
122
|
+
service: {
|
123
|
+
completed_command_process_id: process_id
|
124
|
+
}
|
125
|
+
}
|
126
|
+
puts "-------"
|
127
|
+
puts payload
|
128
|
+
request.body = payload.to_json
|
129
|
+
req_options = {}
|
130
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
131
|
+
http.request(request)
|
132
|
+
end
|
133
|
+
data = JSON.parse(response.body)['result']
|
63
134
|
end
|
64
135
|
|
65
136
|
def options_to_envs
|
@@ -79,6 +150,12 @@ module Adminix
|
|
79
150
|
puts "# Run this command to configure your shell:\n" +
|
80
151
|
"# eval $(adminix env)"
|
81
152
|
end
|
153
|
+
|
154
|
+
def start_watcher
|
155
|
+
loop do
|
156
|
+
puts 'ok'
|
157
|
+
end
|
158
|
+
end
|
82
159
|
end
|
83
160
|
end
|
84
161
|
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Adminix
|
5
|
+
class System
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def self.windows?
|
9
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.mac?
|
13
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.unix?
|
17
|
+
!self.windows?
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.linux?
|
21
|
+
self.unix? and not self.mac?
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.rvm?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :os, :processor_load, :memory_load, :username, :home, :adminix_bin, :ruby_version
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
_define_os
|
32
|
+
_parse_system_info
|
33
|
+
_define_adminix_bin
|
34
|
+
_check_system_load
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_daemon
|
38
|
+
template = File.read("#{Adminix::root}/views/daemon_scripts/upstart.conf.erb")
|
39
|
+
file_content = ERB.new(template).result(binding)
|
40
|
+
|
41
|
+
file_path = `pwd`.split("\n")[0] + '/adminix.conf'
|
42
|
+
File.delete(file_path) if File.exists?(file_path)
|
43
|
+
File.open(file_path, 'w') { |file| file.write(file_content) }
|
44
|
+
|
45
|
+
file_path
|
46
|
+
end
|
47
|
+
|
48
|
+
def eval(cmd)
|
49
|
+
`#{cmd}`
|
50
|
+
end
|
51
|
+
|
52
|
+
def sudo?
|
53
|
+
@username == 'root'
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def _define_os
|
59
|
+
@os = if self.class.windows?
|
60
|
+
:windows
|
61
|
+
elsif self.class.mac?
|
62
|
+
:mac
|
63
|
+
elsif self.class.unix?
|
64
|
+
:unix
|
65
|
+
elsif self.class.linux?
|
66
|
+
:linux
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def _parse_system_info
|
71
|
+
@username = ENV['USER'] || `whoami`.split("\n")[0]
|
72
|
+
@home = "/home/#{@username}"
|
73
|
+
@ruby_version = RUBY_VERSION
|
74
|
+
end
|
75
|
+
|
76
|
+
def _define_adminix_bin
|
77
|
+
@adminix_bin = if self.class.rvm?
|
78
|
+
"/home/#{@username}/.rvm/gems/ruby-#{@ruby_version}/wrappers/adminix"
|
79
|
+
else
|
80
|
+
"/usr/local/bin/adminix"
|
81
|
+
end
|
82
|
+
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
|
+
end
|
95
|
+
end
|
96
|
+
|
data/lib/adminix/version.rb
CHANGED
data/lib/adminix/watcher.rb
CHANGED
@@ -1,45 +1,42 @@
|
|
1
|
+
require "eventmachine"
|
2
|
+
|
1
3
|
module Adminix
|
2
|
-
|
3
|
-
def
|
4
|
-
|
4
|
+
class Watcher
|
5
|
+
def self.run!(options)
|
6
|
+
Watcher.new(options).run!
|
5
7
|
end
|
6
8
|
|
7
|
-
|
8
|
-
puts "#{path} moved"
|
9
|
-
end
|
9
|
+
DEFAULT_PERIOD = 5
|
10
10
|
|
11
|
-
|
12
|
-
puts "#{path} deleted"
|
13
|
-
end
|
11
|
+
attr_reader :period, :service
|
14
12
|
|
15
|
-
def
|
16
|
-
|
13
|
+
def initialize(opts)
|
14
|
+
@period = opts[:period] || DEFAULT_PERIOD
|
15
|
+
@service = Service.instance
|
17
16
|
end
|
18
|
-
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
client = ActionCableClient.new(CABLE_URL, 'MessagesChannel')
|
27
|
-
# the connected callback is required, as it triggers
|
28
|
-
# the actual subscribing to the channel but it can just be
|
29
|
-
# client.connected {}
|
30
|
-
client.connected { puts 'successfully connected.' }
|
31
|
-
|
32
|
-
# called whenever a message is received from the server
|
33
|
-
client.received do |message|
|
34
|
-
puts message
|
18
|
+
def run!
|
19
|
+
trap_signal
|
20
|
+
|
21
|
+
EventMachine.run do
|
22
|
+
EventMachine.add_periodic_timer(period) do
|
23
|
+
sync_service
|
35
24
|
end
|
25
|
+
end
|
26
|
+
end
|
36
27
|
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
def sync_service
|
29
|
+
puts "Syncing service"
|
30
|
+
#puts @service.run_cmd('whoami')
|
31
|
+
service.sync
|
32
|
+
end
|
40
33
|
|
41
|
-
|
42
|
-
|
34
|
+
def trap_signal
|
35
|
+
Signal.trap("SIGINT") do
|
36
|
+
puts "Stopping..."
|
37
|
+
EventMachine.stop
|
38
|
+
end
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
42
|
+
|
data/lib/adminix.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'adminix/version'
|
2
2
|
require 'adminix/config'
|
3
3
|
require 'adminix/service'
|
4
|
+
require 'adminix/system'
|
4
5
|
require 'adminix/watcher'
|
5
|
-
require 'adminix/entrypoint'
|
6
|
+
require 'adminix/entrypoint'
|
7
|
+
|
8
|
+
module Adminix
|
9
|
+
def self.root
|
10
|
+
File.dirname __dir__
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
description "Ruby example upstart conf"
|
2
|
+
|
3
|
+
setuid <%= @username %>
|
4
|
+
setgid <%= @username %>
|
5
|
+
|
6
|
+
<%#start on runlevel [2345]%>
|
7
|
+
<%#stop on runlevel [06]%>
|
8
|
+
|
9
|
+
respawn
|
10
|
+
respawn limit 3 30
|
11
|
+
|
12
|
+
# env RAILS_ENV=production
|
13
|
+
|
14
|
+
# pre-start script
|
15
|
+
# use this for any pre-start stuff
|
16
|
+
# end script
|
17
|
+
|
18
|
+
script
|
19
|
+
exec /bin/bash <<EOS
|
20
|
+
export HOME=<%= @home %>
|
21
|
+
exec <%= @adminix_bin %> watch
|
22
|
+
EOS
|
23
|
+
end script
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adminix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2017-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: eventmachine
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
20
|
-
- - ">="
|
17
|
+
- - '='
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
19
|
+
version: 1.2.2
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '='
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.3.4
|
26
|
+
version: 1.2.2
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: bundler
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +71,9 @@ dependencies:
|
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
78
72
|
requirements:
|
79
73
|
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '9.0'
|
76
|
+
- - ">="
|
80
77
|
- !ruby/object:Gem::Version
|
81
78
|
version: 9.0.6
|
82
79
|
type: :development
|
@@ -84,6 +81,9 @@ dependencies:
|
|
84
81
|
version_requirements: !ruby/object:Gem::Requirement
|
85
82
|
requirements:
|
86
83
|
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '9.0'
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 9.0.6
|
89
89
|
- !ruby/object:Gem::Dependency
|
@@ -91,6 +91,9 @@ dependencies:
|
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.7'
|
96
|
+
- - ">="
|
94
97
|
- !ruby/object:Gem::Version
|
95
98
|
version: 1.7.2
|
96
99
|
type: :development
|
@@ -98,6 +101,9 @@ dependencies:
|
|
98
101
|
version_requirements: !ruby/object:Gem::Requirement
|
99
102
|
requirements:
|
100
103
|
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.7'
|
106
|
+
- - ">="
|
101
107
|
- !ruby/object:Gem::Version
|
102
108
|
version: 1.7.2
|
103
109
|
description: Adminix
|
@@ -122,15 +128,13 @@ files:
|
|
122
128
|
- bin/setup
|
123
129
|
- exe/adminix
|
124
130
|
- lib/adminix.rb
|
125
|
-
- lib/adminix/.config.rb.swp
|
126
|
-
- lib/adminix/.entrypoint.rb.swp
|
127
|
-
- lib/adminix/.service.rb.swo
|
128
|
-
- lib/adminix/.service.rb.swp
|
129
131
|
- lib/adminix/config.rb
|
130
132
|
- lib/adminix/entrypoint.rb
|
131
133
|
- lib/adminix/service.rb
|
134
|
+
- lib/adminix/system.rb
|
132
135
|
- lib/adminix/version.rb
|
133
136
|
- lib/adminix/watcher.rb
|
137
|
+
- views/daemon_scripts/upstart.conf.erb
|
134
138
|
homepage: http://adminix.io
|
135
139
|
licenses:
|
136
140
|
- MIT
|
@@ -151,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
155
|
version: '0'
|
152
156
|
requirements: []
|
153
157
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.5.1
|
155
159
|
signing_key:
|
156
160
|
specification_version: 4
|
157
161
|
summary: Adminix
|
data/lib/adminix/.config.rb.swp
DELETED
Binary file
|
Binary file
|
data/lib/adminix/.service.rb.swo
DELETED
Binary file
|
data/lib/adminix/.service.rb.swp
DELETED
Binary file
|