Class: RunitMan
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- RunitMan
- Defined in:
- lib/runit-man/app.rb
Class Method Summary collapse
- .add_user(name, password) ⇒ Object
- .allowed_users ⇒ Object
- .enable_view_of(file_location) ⇒ Object
- .files_to_view ⇒ Object
- .prepare_to_run ⇒ Object
- .register_as_runit_service ⇒ Object
Instance Method Summary collapse
- #data_of_file_view(request) ⇒ Object
- #log_action(name, text) ⇒ Object
- #log_of_service(name, count) ⇒ Object
Class Method Details
.add_user(name, password) ⇒ Object
164 165 166 |
# File 'lib/runit-man/app.rb', line 164 def add_user(name, password) allowed_users[name] = password end |
.allowed_users ⇒ Object
172 173 174 |
# File 'lib/runit-man/app.rb', line 172 def allowed_users @allowed_users ||= {} end |
.enable_view_of(file_location) ⇒ Object
160 161 162 |
# File 'lib/runit-man/app.rb', line 160 def enable_view_of(file_location) files_to_view << File.(file_location, '/') end |
.files_to_view ⇒ Object
168 169 170 |
# File 'lib/runit-man/app.rb', line 168 def files_to_view @files_to_view ||= [] end |
.prepare_to_run ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/runit-man/app.rb', line 176 def prepare_to_run unless allowed_users.empty? use Rack::Auth::Basic, 'runit-man' do |username, password| allowed_users.include?(username) && allowed_users[username] == password end end end |
.register_as_runit_service ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/runit-man/app.rb', line 142 def register_as_runit_service all_r_dir = File.join(RunitMan.all_services_directory, 'runit-man') active_r_dir = File.join(RunitMan.active_services_directory, 'runit-man') my_dir = File.join(GEM_FOLDER, 'sv') log_dir = File.join(all_r_dir, 'log') if File.symlink?(all_r_dir) File.unlink(all_r_dir) end unless File.directory?(all_r_dir) File.makedirs(log_dir) File.copy(File.join(my_dir, 'log', 'run'), File.join(log_dir, 'run')) end create_run_script(all_r_dir) unless File.symlink?(active_r_dir) File.symlink(all_r_dir, active_r_dir) end end |
Instance Method Details
#data_of_file_view(request) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/runit-man/app.rb', line 86 def data_of_file_view(request) if !request.GET.has_key?('file') return nil end file_path = request.GET['file'] return nil unless all_files_to_view.include?(file_path) { :name => file_path, :text => IO.read(file_path) } end |
#log_action(name, text) ⇒ Object
118 119 120 121 122 |
# File 'lib/runit-man/app.rb', line 118 def log_action(name, text) env = request.env addr = env.include?('X_REAL_IP') ? env['X_REAL_IP'] : env['REMOTE_ADDR'] puts "#{addr} - - [#{Time.now}] \"Do #{text} on #{name}\"" end |
#log_of_service(name, count) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/runit-man/app.rb', line 58 def log_of_service(name, count) count = count.to_i count = MIN_TAIL if count < MIN_TAIL count = MAX_TAIL if count > MAX_TAIL srv = ServiceInfo[name] return nil if srv.nil? || !srv.logged? { :name => name, :count => count, :log_location => srv.log_file_location, :text => `tail -n #{count} #{srv.log_file_location}` } end |