adminix 0.1.49 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/adminix.gemspec +1 -4
  4. data/app/assets/images/logo.png +0 -0
  5. data/app/assets/javascripts/application.js +50 -0
  6. data/app/assets/javascripts/bootstrap.min.js +7 -0
  7. data/app/assets/javascripts/dataTables.bootstrap4.js +184 -0
  8. data/app/assets/javascripts/jquery.dataTables.js +15243 -0
  9. data/app/assets/javascripts/jquery.min.js +2 -0
  10. data/app/assets/javascripts/sb-admin-2.min.js +6 -0
  11. data/app/assets/stylesheets/bootstrap.min.css +6 -0
  12. data/app/assets/stylesheets/dataTables.bootstrap.css +314 -0
  13. data/app/assets/stylesheets/dataTables.responsive.css +106 -0
  14. data/app/assets/stylesheets/font-awesome.min.css +4 -0
  15. data/app/assets/stylesheets/sb-admin-2.min.css +5 -0
  16. data/app/views/scripts/restart_watcher.sh.erb +9 -0
  17. data/app/views/scripts/run_script.sh.erb +12 -0
  18. data/app/views/scripts/start_process.sh.erb +7 -0
  19. data/app/views/scripts/stop_process.sh.erb +7 -0
  20. data/app/views/scripts/update_process.sh.erb +24 -0
  21. data/app/views/scripts/update_watcher.sh.erb +3 -0
  22. data/app/views/web/dashboard.html.erb +90 -0
  23. data/app/views/web/job.html.erb +46 -0
  24. data/app/views/web/link.html.erb +12 -0
  25. data/app/views/web/loadstamp.html.erb +57 -0
  26. data/app/views/web/log.html.erb +49 -0
  27. data/app/views/web/partials/footer.html.erb +11 -0
  28. data/app/views/web/partials/header.html.erb +50 -0
  29. data/bin/install_adminix +40 -0
  30. data/bin/push +13 -0
  31. data/development.log +0 -0
  32. data/exe/adminix +91 -28
  33. data/lib/adminix.rb +42 -5
  34. data/lib/adminix/config.rb +170 -96
  35. data/lib/adminix/entities.rb +5 -0
  36. data/lib/adminix/entities/job.rb +54 -0
  37. data/lib/adminix/entities/log.rb +21 -0
  38. data/lib/adminix/entities/service.rb +211 -0
  39. data/lib/adminix/entities/sysload_stamp.rb +37 -0
  40. data/lib/adminix/entities/variable.rb +32 -0
  41. data/lib/adminix/helpers.rb +7 -2
  42. data/lib/adminix/helpers/command.rb +73 -0
  43. data/lib/adminix/helpers/files.rb +82 -0
  44. data/lib/adminix/helpers/log_reader.rb +16 -0
  45. data/lib/adminix/helpers/net_http.rb +63 -0
  46. data/lib/adminix/helpers/output.rb +28 -0
  47. data/lib/adminix/helpers/systemctl.rb +54 -0
  48. data/lib/adminix/services.rb +3 -0
  49. data/lib/adminix/services/app_service.rb +143 -0
  50. data/lib/adminix/services/logs_service.rb +13 -0
  51. data/lib/adminix/services/system_load_service.rb +16 -0
  52. data/lib/adminix/version.rb +1 -1
  53. data/lib/adminix/watcher.rb +76 -144
  54. data/lib/adminix/web.rb +4 -0
  55. data/lib/adminix/web/router.rb +98 -0
  56. data/lib/adminix/web/server.rb +60 -0
  57. data/lib/adminix/web/view_helper.rb +14 -0
  58. data/lib/event_machine.rb +2 -0
  59. data/lib/event_machine/http_server.rb +2 -0
  60. data/lib/event_machine/http_server/response.rb +314 -0
  61. data/lib/event_machine/http_server/server.rb +107 -0
  62. data/lib/event_machine/tail.rb +2 -0
  63. data/lib/event_machine/tail/filetail.rb +470 -0
  64. data/lib/event_machine/tail/globwatcher.rb +294 -0
  65. metadata +60 -45
  66. data/lib/adminix/errors.rb +0 -7
  67. data/lib/adminix/helpers/file.rb +0 -13
  68. data/lib/adminix/helpers/http.rb +0 -19
  69. data/lib/adminix/log_watch_handler.rb +0 -23
  70. data/lib/adminix/server_setup.rb +0 -76
  71. data/lib/adminix/service.rb +0 -179
  72. data/lib/adminix/setup.rb +0 -3
  73. data/lib/adminix/setup/routes.rb +0 -113
  74. data/lib/adminix/setup/services.rb +0 -139
  75. data/lib/adminix/setup/views.rb +0 -183
  76. data/lib/adminix/system.rb +0 -106
  77. data/views/daemon_scripts/upstart.conf.erb +0 -23
File without changes
@@ -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: "help",
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
- unless options[:action] == "help"
51
- require_relative '../lib/adminix'
52
- config = Adminix::Config.instance
53
-
54
- config.secret_key = options[:secret_key]
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
- when "env"
63
- puts Adminix::Service.instance.options_to_envs
64
- when "download_source"
65
- puts Adminix::Service.instance.download_source
66
- when "watch"
67
- if config.credentials_defined?
68
- puts Adminix::Watcher.run!(options)
69
- else
70
- puts 'Credentials are not defined, running setup server'
71
- require_relative '../lib/adminix/server_setup'
72
- end
73
- when "version"
74
- puts "adminix version #{Adminix::VERSION}"
75
- else
76
- puts parsers.map { |v| v[1].to_s }
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
-
@@ -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/service'
6
- require_relative 'adminix/system'
7
- require_relative 'adminix/log_watch_handler'
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
@@ -1,138 +1,212 @@
1
- require 'singleton'
2
- require 'json'
1
+ require 'logger'
2
+ require 'erb'
3
3
 
4
4
  module Adminix
5
5
  class Config
6
- include Singleton
7
-
8
- DEFAULT_HOST = 'https://api.adminix.io'.freeze
9
- DEFAULT_WEBSOCKET_HOST = 'wss://websocket.adminix.io/cable'.freeze
10
- DEFAULT_SETUP_SERVER_PORT = (ENV['ADMINIX_SETUP_SERVER_PORT'] || '8080').freeze
11
- DEFAULT_WATCHER_SYNC_PERIOD = 10.freeze
12
- DEFAULT_LOGS_SYNC_PERIOD = 3.freeze
13
- DEFAULT_LOGS_ENABLED = true
14
-
15
- attr_accessor :service_id, :secret_key, :host, :commands, :daemon, :setup_server_port, :scripts, :watch_log_files, :watcher_sync_period, :logs_sync_period, :logs_enabled, :websocket_path, :mode, :working_dir, :iv, :password
16
- attr_reader :image_sname, :error_notifier_enabled
17
-
18
- def initialize
19
- @host = ENV['ADMINIX_HOST'] || DEFAULT_HOST
20
- @setup_server_port = ENV['ADMINIX_SETUP_SERVER_PORT'] || DEFAULT_SETUP_SERVER_PORT
21
- @commands = []
22
- @watcher_sync_period = DEFAULT_WATCHER_SYNC_PERIOD
23
- @logs_sync_period = DEFAULT_LOGS_SYNC_PERIOD
24
- @logs_enabled = DEFAULT_LOGS_ENABLED
25
- @websocket_path = ENV['ADMINIX_WEBSOCKET_HOST'] || DEFAULT_WEBSOCKET_HOST
26
- @mode = 'classic'
27
- @working_dir = `pwd`.split("\n").first
28
- @iv = ENV['DECIPHER_IV'] || 'U7yfLthY77Yjtp9z'
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
- watcher_start: 'sudo systemctl start adminix.service',
31
- watcher_stop: 'sudo systemctl stop adminix.service',
32
- process_start: 'sudo systemctl start adminix_process.service',
33
- process_stop: 'sudo systemctl stop adminix_process.service',
34
- run_script: '~/.config/adminix/scripts/run_script'
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
- @watch_log_files = []
37
- @error_notifier_enabled = ENV['ADMINIX_ERROR_NOTIFIER'].nil? ? true : ENV['ADMINIX_ERROR_NOTIFIER'] == 'true'
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
- @config_store_path = "#{ENV['HOME']}/.config"
40
- @root_path = "#{@config_store_path}/adminix"
41
- @creds_path = "#{@root_path}/credentials"
42
- @config_path = "#{@root_path}/config"
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 read_local_config
47
- if File.exists?(@creds_path)
48
- content = IO.read(@creds_path)
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
- @service_id ||= data['service_id']
52
- @secret_key ||= data['secret_key']
53
- end
90
+ data = Helpers::Files.read_json_file(credentials_path)
54
91
 
55
- if File.exists?(@config_path)
56
- content = IO.read(@config_path)
57
- data = JSON.parse(content) rescue {}
58
-
59
- @mode = data['mode'] || 'classic'
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
- @watch_log_files = data['watch_logs'] || []
98
+ @service_id ||= data['service_id']
99
+ @secret_key ||= data['secret_key']
100
+ end
74
101
 
75
- @image_sname = data['image']
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 sync_remote_config
80
- return if service_id.nil? || secret_key.nil?
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
- uri = URI.parse("#{@host}/v1/services/#{@service_id}/watcher_config")
83
- request = Net::HTTP::Get.new(uri)
84
- request["Authorization"] = "Bearer #{@secret_key}"
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
- opts = { use_ssl: uri.scheme == 'https' }
87
- response = Net::HTTP.start(uri.hostname, uri.port, opts) do |http|
88
- http.request(request)
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
- case response.code
95
- when '401'
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
- create_config_root_if_not_exists
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
- open(@creds_path, 'w') do |f|
109
- f.puts(credentials.to_json)
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 creds_file_exists?
114
- File.exists?(@creds_path)
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
- !service_id.nil? && !secret_key.nil?
188
+ !@service_id.nil? && !@secret_key.nil?
119
189
  end
120
190
 
121
- private
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 credentials
124
- { service_id: @service_id, secret_key: @secret_key }
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
- unless Dir.exists?(@config_store_path)
129
- Dir.mkdir(@config_store_path)
130
- end
204
+ return if Dir.exists?(config_root_path)
205
+ Helpers::Files.mkdir_p(config_root_path)
206
+ end
131
207
 
132
- unless Dir.exists?(@root_path)
133
- Dir.mkdir(@root_path)
134
- end
208
+ def config_file(file)
209
+ "#{config_root_path}/#{file}"
135
210
  end
136
211
  end
137
212
  end
138
-