adminix 0.1.49 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/adminix.gemspec +1 -4
- data/app/assets/images/logo.png +0 -0
- data/app/assets/javascripts/application.js +50 -0
- data/app/assets/javascripts/bootstrap.min.js +7 -0
- data/app/assets/javascripts/dataTables.bootstrap4.js +184 -0
- data/app/assets/javascripts/jquery.dataTables.js +15243 -0
- data/app/assets/javascripts/jquery.min.js +2 -0
- data/app/assets/javascripts/sb-admin-2.min.js +6 -0
- data/app/assets/stylesheets/bootstrap.min.css +6 -0
- data/app/assets/stylesheets/dataTables.bootstrap.css +314 -0
- data/app/assets/stylesheets/dataTables.responsive.css +106 -0
- data/app/assets/stylesheets/font-awesome.min.css +4 -0
- data/app/assets/stylesheets/sb-admin-2.min.css +5 -0
- data/app/views/scripts/restart_watcher.sh.erb +9 -0
- data/app/views/scripts/run_script.sh.erb +12 -0
- data/app/views/scripts/start_process.sh.erb +7 -0
- data/app/views/scripts/stop_process.sh.erb +7 -0
- data/app/views/scripts/update_process.sh.erb +24 -0
- data/app/views/scripts/update_watcher.sh.erb +3 -0
- data/app/views/web/dashboard.html.erb +90 -0
- data/app/views/web/job.html.erb +46 -0
- data/app/views/web/link.html.erb +12 -0
- data/app/views/web/loadstamp.html.erb +57 -0
- data/app/views/web/log.html.erb +49 -0
- data/app/views/web/partials/footer.html.erb +11 -0
- data/app/views/web/partials/header.html.erb +50 -0
- data/bin/install_adminix +40 -0
- data/bin/push +13 -0
- data/development.log +0 -0
- data/exe/adminix +91 -28
- data/lib/adminix.rb +42 -5
- data/lib/adminix/config.rb +170 -96
- data/lib/adminix/entities.rb +5 -0
- data/lib/adminix/entities/job.rb +54 -0
- data/lib/adminix/entities/log.rb +21 -0
- data/lib/adminix/entities/service.rb +211 -0
- data/lib/adminix/entities/sysload_stamp.rb +37 -0
- data/lib/adminix/entities/variable.rb +32 -0
- data/lib/adminix/helpers.rb +7 -2
- data/lib/adminix/helpers/command.rb +73 -0
- data/lib/adminix/helpers/files.rb +82 -0
- data/lib/adminix/helpers/log_reader.rb +16 -0
- data/lib/adminix/helpers/net_http.rb +63 -0
- data/lib/adminix/helpers/output.rb +28 -0
- data/lib/adminix/helpers/systemctl.rb +54 -0
- data/lib/adminix/services.rb +3 -0
- data/lib/adminix/services/app_service.rb +143 -0
- data/lib/adminix/services/logs_service.rb +13 -0
- data/lib/adminix/services/system_load_service.rb +16 -0
- data/lib/adminix/version.rb +1 -1
- data/lib/adminix/watcher.rb +76 -144
- data/lib/adminix/web.rb +4 -0
- data/lib/adminix/web/router.rb +98 -0
- data/lib/adminix/web/server.rb +60 -0
- data/lib/adminix/web/view_helper.rb +14 -0
- data/lib/event_machine.rb +2 -0
- data/lib/event_machine/http_server.rb +2 -0
- data/lib/event_machine/http_server/response.rb +314 -0
- data/lib/event_machine/http_server/server.rb +107 -0
- data/lib/event_machine/tail.rb +2 -0
- data/lib/event_machine/tail/filetail.rb +470 -0
- data/lib/event_machine/tail/globwatcher.rb +294 -0
- metadata +60 -45
- data/lib/adminix/errors.rb +0 -7
- data/lib/adminix/helpers/file.rb +0 -13
- data/lib/adminix/helpers/http.rb +0 -19
- data/lib/adminix/log_watch_handler.rb +0 -23
- data/lib/adminix/server_setup.rb +0 -76
- data/lib/adminix/service.rb +0 -179
- data/lib/adminix/setup.rb +0 -3
- data/lib/adminix/setup/routes.rb +0 -113
- data/lib/adminix/setup/services.rb +0 -139
- data/lib/adminix/setup/views.rb +0 -183
- data/lib/adminix/system.rb +0 -106
- data/views/daemon_scripts/upstart.conf.erb +0 -23
data/development.log
ADDED
File without changes
|
data/exe/adminix
CHANGED
@@ -2,9 +2,14 @@
|
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'optparse'
|
5
|
+
require_relative '../lib/adminix'
|
6
|
+
|
7
|
+
if ENV['DEBUGGING'] == 'true'
|
8
|
+
require 'byebug'
|
9
|
+
end
|
5
10
|
|
6
11
|
options = {
|
7
|
-
action:
|
12
|
+
action: 'help',
|
8
13
|
secret_key: ENV['ADMINIX_SECRET_KEY'],
|
9
14
|
service_id: ENV['ADMINIX_SERVICE_ID'],
|
10
15
|
daemonize: false,
|
@@ -15,6 +20,16 @@ parsers = {}
|
|
15
20
|
parsers[:env] = OptionParser.new do |opts|
|
16
21
|
opts.banner = "Display the commands to define ENV variables"
|
17
22
|
opts.separator " Usage: adminix env [options]"
|
23
|
+
opts.on("--file", "generates .env file") { |key| options[:env_file] ||= "/tmp/#{SecureRandom.uuid}.env" }
|
24
|
+
opts.on("--file-path FILE_PATH", ".env file path") { |key| options[:env_file] = key }
|
25
|
+
opts.on("--secret-key SECRET_KEY", "define api SECRET_KEY") { |key| options[:secret_key] = key }
|
26
|
+
opts.on("--service-id SERVICE_ID", "define api SERVICE_ID") { |id| options[:service_id] = id }
|
27
|
+
opts.separator ""
|
28
|
+
end
|
29
|
+
|
30
|
+
parsers[:define_credentials] = OptionParser.new do |opts|
|
31
|
+
opts.banner = 'Define Adminix credentials'
|
32
|
+
opts.separator " Usage: adminix define_credentials [options]"
|
18
33
|
opts.on("--secret-key SECRET_KEY", "define api SECRET_KEY") { |key| options[:secret_key] = key }
|
19
34
|
opts.on("--service-id SERVICE_ID", "define api SERVICE_ID") { |id| options[:service_id] = id }
|
20
35
|
opts.separator ""
|
@@ -26,6 +41,36 @@ parsers[:download_source] = OptionParser.new do |opts|
|
|
26
41
|
opts.separator ""
|
27
42
|
end
|
28
43
|
|
44
|
+
parsers[:process_start] = OptionParser.new do |opts|
|
45
|
+
opts.banner = 'Starts a process'
|
46
|
+
opts.separator " Usage: adminix process_start"
|
47
|
+
opts.separator ""
|
48
|
+
end
|
49
|
+
|
50
|
+
parsers[:process_restart] = OptionParser.new do |opts|
|
51
|
+
opts.banner = 'Restarts a process'
|
52
|
+
opts.separator " Usage: adminix process_restart"
|
53
|
+
opts.separator ""
|
54
|
+
end
|
55
|
+
|
56
|
+
parsers[:process_stop] = OptionParser.new do |opts|
|
57
|
+
opts.banner = 'Stops a process'
|
58
|
+
opts.separator ' Usage: adminix process_stop'
|
59
|
+
opts.separator ''
|
60
|
+
end
|
61
|
+
|
62
|
+
parsers[:process_update] = OptionParser.new do |opts|
|
63
|
+
opts.banner = 'Updates a process'
|
64
|
+
opts.separator ' Usage: adminix process_update'
|
65
|
+
opts.separator ''
|
66
|
+
end
|
67
|
+
|
68
|
+
parsers[:write_systemctl] = OptionParser.new do |opts|
|
69
|
+
opts.banner = 'Creates a systemctl file'
|
70
|
+
opts.separator ' Usage: adminix write_systemctl'
|
71
|
+
opts.separator ''
|
72
|
+
end
|
73
|
+
|
29
74
|
parsers[:watch] = OptionParser.new do |opts|
|
30
75
|
opts.banner = "Launch Adminix watcher"
|
31
76
|
opts.separator " Usage: adminix watch"
|
@@ -33,8 +78,6 @@ parsers[:watch] = OptionParser.new do |opts|
|
|
33
78
|
opts.separator " Options:"
|
34
79
|
opts.on("--secret-key SECRET_KEY", "define api SECRET_KEY") { |key| options[:secret_key] = key }
|
35
80
|
opts.on("--service-id SERVICE_ID", "define api SERVICE_ID") { |id| options[:service_id] = id }
|
36
|
-
opts.on("-d", "--daemonize", "run watcher in background process") { options[:daemonize] = true }
|
37
|
-
opts.on("-s", "--stop-daemon", "stop daemon watcher") { options[:stop_daemon] = true }
|
38
81
|
opts.separator ""
|
39
82
|
end
|
40
83
|
|
@@ -45,34 +88,54 @@ parsers[:version] = OptionParser.new do |opts|
|
|
45
88
|
end
|
46
89
|
|
47
90
|
options[:action] = ARGV[0] || "help"
|
91
|
+
options[:logger_mode] = options[:action] == 'watch' && ENV['ADMINIX_LOGGER'].nil? ? 'stdout' : nil
|
48
92
|
parsers[options[:action].to_sym].parse!(ARGV) rescue nil
|
49
93
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
config.service_id = options[:service_id]
|
56
|
-
config.daemon = options[:daemonize]
|
57
|
-
config.read_local_config
|
58
|
-
config.sync_remote_config
|
94
|
+
Adminix.config = Adminix::Config.new(options)
|
95
|
+
if Adminix.config.credentials_defined?
|
96
|
+
Adminix.config.read_remote_config
|
97
|
+
else
|
98
|
+
Adminix.logger.info 'Adminix is not connected to the cloud! Please go to https://adminix.io to create an account.'
|
59
99
|
end
|
100
|
+
app = Adminix::Services::AppService.new(
|
101
|
+
Adminix::Entities::Service.new(
|
102
|
+
id: Adminix.config.service_id
|
103
|
+
)
|
104
|
+
)
|
105
|
+
app.read_vars
|
60
106
|
|
61
107
|
case options[:action]
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
108
|
+
when 'env'
|
109
|
+
app.service.ensure_credentials_exists!
|
110
|
+
puts app.service.bash_variables(options[:env_file])
|
111
|
+
when 'download_source'
|
112
|
+
app.service.ensure_credentials_exists!
|
113
|
+
app.download_source
|
114
|
+
when 'process_start'
|
115
|
+
_success, output = app.start_process
|
116
|
+
puts output
|
117
|
+
when 'process_restart'
|
118
|
+
_success, output = app.restart_process
|
119
|
+
puts output
|
120
|
+
when 'process_stop'
|
121
|
+
_success, output = app.stop_process
|
122
|
+
puts output
|
123
|
+
when 'process_update'
|
124
|
+
_success, output = app.update_process
|
125
|
+
puts output
|
126
|
+
when 'upgrade'
|
127
|
+
_success, output = app.upgrade_watcher
|
128
|
+
puts output
|
129
|
+
when 'write_systemctl'
|
130
|
+
Adminix::Helpers::Systemctl.new.write
|
131
|
+
when 'define_credentials'
|
132
|
+
Adminix.config.input(:service_id) if options[:service_id].nil?
|
133
|
+
Adminix.config.input(:secret_key) if options[:secret_key].nil?
|
134
|
+
Adminix.config.export_credentials
|
135
|
+
when 'watch'
|
136
|
+
Adminix::Watcher.run!(app, options)
|
137
|
+
when 'version'
|
138
|
+
puts "adminix version #{Adminix::VERSION}"
|
139
|
+
else
|
140
|
+
puts parsers.map { |v| v[1].to_s }
|
77
141
|
end
|
78
|
-
|
data/lib/adminix.rb
CHANGED
@@ -1,15 +1,52 @@
|
|
1
|
+
require_relative 'event_machine'
|
1
2
|
require_relative 'adminix/version'
|
2
|
-
# require 'adminix/errors'
|
3
3
|
require_relative 'adminix/helpers'
|
4
4
|
require_relative 'adminix/config'
|
5
|
-
require_relative 'adminix/
|
6
|
-
require_relative 'adminix/
|
7
|
-
require_relative 'adminix/
|
5
|
+
require_relative 'adminix/entities'
|
6
|
+
require_relative 'adminix/services'
|
7
|
+
require_relative 'adminix/web'
|
8
8
|
require_relative 'adminix/watcher'
|
9
9
|
|
10
10
|
module Adminix
|
11
11
|
def self.root
|
12
12
|
File.dirname __dir__
|
13
13
|
end
|
14
|
-
end
|
15
14
|
|
15
|
+
def self.config=(config)
|
16
|
+
@config = config
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.config
|
20
|
+
@config
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.watcher=(watcher)
|
24
|
+
@watcher = watcher
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.watcher
|
28
|
+
@watcher
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.os
|
32
|
+
return @os if @os
|
33
|
+
@os = if RUBY_PLATFORM =~ /darwin/ then 'mac'
|
34
|
+
elsif RUBY_PLATFORM =~ /linux/ then 'linux'
|
35
|
+
elsif RUBY_PLATFORM =~ /mswin32/ then 'windows'
|
36
|
+
else 'unknown'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.logger
|
41
|
+
@logger
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.define_logger(source, lvl = nil)
|
45
|
+
@logger = Logger.new(source)
|
46
|
+
@logger.level = lvl if lvl
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.test?
|
50
|
+
ENV['ADMINIX_ENV'] == 'test'
|
51
|
+
end
|
52
|
+
end
|
data/lib/adminix/config.rb
CHANGED
@@ -1,138 +1,212 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'logger'
|
2
|
+
require 'erb'
|
3
3
|
|
4
4
|
module Adminix
|
5
5
|
class Config
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@
|
20
|
-
|
21
|
-
@
|
22
|
-
|
23
|
-
@
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
6
|
+
attr_reader :service_id, :secret_key, :image, :watcher_period, :api_host,
|
7
|
+
:server_port, :config_root_path, :log_files, :max_logs_storage,
|
8
|
+
:data_storage_limit, :systemctl, :scripts, :watch_system_load
|
9
|
+
|
10
|
+
MODE_CLASSIC = 'classic'.freeze
|
11
|
+
DEFAULT_API_HOST = 'https://api.adminix.io'.freeze
|
12
|
+
DEFAULT_SERVER_PORT = 8080
|
13
|
+
WATCHER_SYSTEMCTL_PATH = '/etc/systemd/system/adminix.service'.freeze
|
14
|
+
|
15
|
+
def initialize(props = {})
|
16
|
+
@api_host = ENV['ADMINIX_HOST'] || DEFAULT_API_HOST
|
17
|
+
@service_id = props[:service_id] || ENV['ADMINIX_SERVICE_ID']
|
18
|
+
@secret_key = props[:secret_key] || ENV['ADMINIX_SECRET_KEY']
|
19
|
+
@server_port = props[:server_port] || ENV['ADMINIX_SERVER_PORT'] ||
|
20
|
+
DEFAULT_SERVER_PORT
|
21
|
+
@config_root_path = props[:config_root_path] ||
|
22
|
+
"#{ENV['HOME']}/.config/adminix"
|
23
|
+
@watcher_period = {
|
24
|
+
sync_service: 5,
|
25
|
+
send_logs: 10,
|
26
|
+
send_system_load: 10,
|
27
|
+
execute_jobs: 5,
|
28
|
+
check_system_load: 5
|
29
|
+
}
|
29
30
|
@scripts = {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
restart_watcher: "#{@config_root_path}/scripts/restart_watcher",
|
32
|
+
upgrade_watcher: "#{@config_root_path}/scripts/upgrade_watcher",
|
33
|
+
update_process: "#{@config_root_path}/scripts/update_process",
|
34
|
+
start_process: "#{@config_root_path}/scripts/start_process",
|
35
|
+
stop_process: "#{@config_root_path}/scripts/stop_process",
|
36
|
+
run_script: "#{@config_root_path}/scripts/run_script"
|
37
|
+
}
|
38
|
+
@log_files = []
|
39
|
+
@data_storage_limit = {
|
40
|
+
logs: 1000 || ENV['ADMINIX_MAX_LOGS_IN_MEMORY'],
|
41
|
+
load_stamps: 100 || ENV['ADMINIX_MAX_LOAD_STAMPS_IN_MEMORY']
|
35
42
|
}
|
36
|
-
@
|
37
|
-
@
|
43
|
+
@watch_logs = true
|
44
|
+
@watch_system_load = true
|
45
|
+
@systemctl = {
|
46
|
+
watcher_service_path: ENV['ADMINIX_WATCHER_SYSTEMCTL_PATH'] || WATCHER_SYSTEMCTL_PATH
|
47
|
+
}
|
48
|
+
@logger_mode = props[:logger_mode] || ENV['ADMINIX_LOGGER'] || 'silent'
|
49
|
+
@logger_path = ENV['ADMINIX_LOGGER_PATH']
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
51
|
+
setup_logger
|
52
|
+
create_config_root_if_not_exists
|
53
|
+
read_credentials_file unless credentials_defined?
|
54
|
+
read_config_file
|
55
|
+
create_default_scripts
|
43
56
|
end
|
44
57
|
|
58
|
+
def setup_logger
|
59
|
+
case @logger_mode
|
60
|
+
when 'stdout'
|
61
|
+
Adminix.define_logger(STDOUT, Logger::INFO)
|
62
|
+
when 'debug'
|
63
|
+
Adminix.define_logger(STDOUT)
|
64
|
+
when 'silent'
|
65
|
+
Adminix.define_logger(STDOUT, Logger::FATAL)
|
66
|
+
when 'file'
|
67
|
+
Helpers::Files.touch(@logger_path) unless @logger_path.nil?
|
68
|
+
if File.exist?(@logger_path)
|
69
|
+
Adminix.define_logger(@logger_path)
|
70
|
+
else
|
71
|
+
Adminix.define_logger(STDOUT)
|
72
|
+
Adminix.logger.error(
|
73
|
+
"Logger can't create file #{@logger_path}, using STDOUT by default"
|
74
|
+
)
|
75
|
+
end
|
76
|
+
else
|
77
|
+
incorrect_mode = @logger_mode
|
78
|
+
@logger_mode = 'stdout'
|
79
|
+
Adminix.define_logger(STDOUT)
|
80
|
+
Adminix.logger.error(
|
81
|
+
"#{incorrect_mode} is incorrect mode for Logger, using STDOUT by default"
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
45
85
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
data = JSON.parse(content) rescue {}
|
86
|
+
def read_credentials_file
|
87
|
+
credentials_path = config_file('credentials')
|
88
|
+
return unless File.exist?(credentials_path)
|
50
89
|
|
51
|
-
|
52
|
-
@secret_key ||= data['secret_key']
|
53
|
-
end
|
90
|
+
data = Helpers::Files.read_json_file(credentials_path)
|
54
91
|
|
55
|
-
if
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
@working_dir = data['working_dir'] if data['working_dir']
|
61
|
-
|
62
|
-
scripts = data['scripts'] || {}
|
63
|
-
@scripts = {
|
64
|
-
watcher_start: scripts['watcher_start'],
|
65
|
-
watcher_stop: scripts['watcher_stop'],
|
66
|
-
process_start: scripts['process_start'],
|
67
|
-
process_stop: scripts['process_stop']
|
68
|
-
}
|
69
|
-
unless scripts['run_script'].nil?
|
70
|
-
@scripts[:run_script] = scripts['run_script']
|
71
|
-
end
|
92
|
+
if data['service_id'].nil? || data['secret_key'].nil?
|
93
|
+
Helpers::Output.display_error_and_exit(
|
94
|
+
'Credentials file is incorrect!'
|
95
|
+
)
|
96
|
+
end
|
72
97
|
|
73
|
-
|
98
|
+
@service_id ||= data['service_id']
|
99
|
+
@secret_key ||= data['secret_key']
|
100
|
+
end
|
74
101
|
|
75
|
-
|
102
|
+
def read_config_file
|
103
|
+
config_path = config_file('config')
|
104
|
+
unless File.exist?(config_path)
|
105
|
+
Helpers::Files.write_json_file(config_path, {})
|
106
|
+
return
|
76
107
|
end
|
108
|
+
|
109
|
+
data = Helpers::Files.read_json_file(config_path)
|
110
|
+
validate_config_file(data)
|
111
|
+
|
112
|
+
@mode = data['mode'] || MODE_CLASSIC
|
113
|
+
@image = data['image']
|
114
|
+
@web_debugger_enabled = data['enable_web_debugger'] || false
|
115
|
+
@working_dir = data['working_dir']
|
116
|
+
@log_files = data['watch_logs'] || []
|
117
|
+
@watch_logs = @log_files.any?
|
118
|
+
@watch_system_load = data['system_load_enabled'] || false
|
77
119
|
end
|
78
120
|
|
79
|
-
def
|
80
|
-
return
|
121
|
+
def read_remote_config
|
122
|
+
return unless credentials_defined?
|
123
|
+
Adminix.logger.info('Reading remote config...')
|
124
|
+
|
125
|
+
success, result = Helpers::NetHTTP.get("services/#{@service_id}/watcher_config")
|
126
|
+
return unless success
|
81
127
|
|
82
|
-
|
83
|
-
|
84
|
-
|
128
|
+
@watcher_period[:sync_service] = result['sync_period']
|
129
|
+
@watcher_period[:send_logs] = result['logs_sync_period']
|
130
|
+
@watcher_period[:send_system_load] = result['system_load_sync_period'] || 10
|
131
|
+
@watch_logs = result['logs_enabled']
|
132
|
+
@watch_system_load = result['system_load_enabled'] || false
|
133
|
+
end
|
85
134
|
|
86
|
-
|
87
|
-
|
88
|
-
|
135
|
+
def validate_config_file(data)
|
136
|
+
errors = []
|
137
|
+
if data['mode'] && !%w[classic docker].include?(data['mode'])
|
138
|
+
errors << 'incorrect mode type, can be "classic" or "docker"'
|
89
139
|
end
|
90
|
-
|
91
|
-
data = JSON.parse(response.body)
|
92
|
-
result = data['result'] || {}
|
93
140
|
|
94
|
-
|
95
|
-
|
96
|
-
puts 'Incorrect credentials'
|
141
|
+
if errors.count > 0
|
142
|
+
errors.each { |e| puts e }
|
97
143
|
exit
|
144
|
+
else
|
145
|
+
true
|
98
146
|
end
|
99
|
-
|
100
|
-
@watcher_sync_period = result['sync_period'] || DEFAULT_WATCHER_SYNC_PERIOD
|
101
|
-
@logs_sync_period = result['logs_sync_period'] || DEFAULT_LOGS_SYNC_PERIOD
|
102
|
-
@logs_enables = result.key?('logs_enabled') ? result['logs_enabled'] == true : DEFAULT_LOGS_ENABLED
|
103
147
|
end
|
104
148
|
|
105
149
|
def export_credentials
|
106
|
-
|
150
|
+
file = config_file('credentials')
|
151
|
+
content = { service_id: @service_id, secret_key: @secret_key }
|
152
|
+
|
153
|
+
Helpers::Files.mkdir_p(config_root_path)
|
154
|
+
Helpers::Files.write_json_file(file, content)
|
155
|
+
Helpers::Output.display_message("File #{file} created")
|
156
|
+
end
|
107
157
|
|
108
|
-
|
109
|
-
|
158
|
+
def input(key)
|
159
|
+
case key
|
160
|
+
when :service_id
|
161
|
+
Helpers::Output.display_message('Please enter your service ID')
|
162
|
+
@service_id = STDIN.gets.chomp
|
163
|
+
when :secret_key
|
164
|
+
Helpers::Output.display_message('Please enter your secret key')
|
165
|
+
@secret_key = STDIN.gets.chomp
|
166
|
+
else
|
167
|
+
Helpers::Output.display_error_and_exit("#{key} is wrong config key")
|
110
168
|
end
|
111
169
|
end
|
112
170
|
|
113
|
-
def
|
114
|
-
|
171
|
+
def create_default_scripts
|
172
|
+
unless Dir.exist?("#{config_root_path}/scripts")
|
173
|
+
Helpers::Files.mkdir_p("#{config_root_path}/scripts")
|
174
|
+
end
|
175
|
+
|
176
|
+
Dir["#{Adminix.root}/app/views/scripts/*"].each do |tpl_path|
|
177
|
+
script_name = tpl_path.split('/').last.split('.sh.erb').first
|
178
|
+
script_path = "#{config_root_path}/scripts/#{script_name}"
|
179
|
+
next if File.exist?(script_path)
|
180
|
+
tpl = File.open(tpl_path, 'rb', &:read)
|
181
|
+
content = ERB.new(tpl).result(binding)
|
182
|
+
Helpers::Files.write_plain_file(script_path, content)
|
183
|
+
File.chmod(0o755, script_path)
|
184
|
+
end
|
115
185
|
end
|
116
186
|
|
117
187
|
def credentials_defined?
|
118
|
-
|
188
|
+
!@service_id.nil? && !@secret_key.nil?
|
119
189
|
end
|
120
190
|
|
121
|
-
|
191
|
+
def watch_logs?
|
192
|
+
@watch_logs == true
|
193
|
+
end
|
194
|
+
|
195
|
+
def watch_system_load?
|
196
|
+
@watch_system_load == true
|
197
|
+
end
|
122
198
|
|
123
|
-
def
|
124
|
-
|
199
|
+
def web_debugger_enabled?
|
200
|
+
@web_debugger_enabled == true
|
125
201
|
end
|
126
202
|
|
127
203
|
def create_config_root_if_not_exists
|
128
|
-
|
129
|
-
|
130
|
-
|
204
|
+
return if Dir.exists?(config_root_path)
|
205
|
+
Helpers::Files.mkdir_p(config_root_path)
|
206
|
+
end
|
131
207
|
|
132
|
-
|
133
|
-
|
134
|
-
end
|
208
|
+
def config_file(file)
|
209
|
+
"#{config_root_path}/#{file}"
|
135
210
|
end
|
136
211
|
end
|
137
212
|
end
|
138
|
-
|