Class: Nginxtra::Actions::Rails::Server
- Inherits:
-
Object
- Object
- Nginxtra::Actions::Rails::Server
- Includes:
- Nginxtra::Action
- Defined in:
- lib/nginxtra/actions/rails/server.rb
Instance Method Summary collapse
- #basedir ⇒ Object
- #config_path ⇒ Object
- #ensure_in_rails_app ⇒ Object
- #ensure_server_gem_installed ⇒ Object
- #in_rails_app? ⇒ Boolean
- #passenger_installed? ⇒ Boolean
- #server ⇒ Object
- #start_nginxtra ⇒ Object
- #start_verbose_output ⇒ Object
- #stop_nginxtra ⇒ Object
- #stop_verbose_output ⇒ Object
-
#verbose_thread ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
- #wait_till_finished ⇒ Object
- #workingdir ⇒ Object
Methods included from Nginxtra::Action
Instance Method Details
#basedir ⇒ Object
59 60 61 |
# File 'lib/nginxtra/actions/rails/server.rb', line 59 def basedir File.absolute_path "tmp/nginxtra" end |
#config_path ⇒ Object
63 64 65 |
# File 'lib/nginxtra/actions/rails/server.rb', line 63 def config_path File.absolute_path "tmp/nginxtra.conf.rb" end |
#ensure_in_rails_app ⇒ Object
21 22 23 |
# File 'lib/nginxtra/actions/rails/server.rb', line 21 def ensure_in_rails_app raise Nginxtra::Error::IllegalState, "You must be in a rails root directory to run nginxtra_rails." unless in_rails_app? end |
#ensure_server_gem_installed ⇒ Object
25 26 27 |
# File 'lib/nginxtra/actions/rails/server.rb', line 25 def ensure_server_gem_installed raise Nginxtra::Error::IllegalState, "Please 'gem install passenger' to continue." unless passenger_installed? end |
#in_rails_app? ⇒ Boolean
71 72 73 74 |
# File 'lib/nginxtra/actions/rails/server.rb', line 71 def in_rails_app? return true if File.exist? "script/rails" File.exist?("script/server") && File.exist?("app") end |
#passenger_installed? ⇒ Boolean
55 56 57 |
# File 'lib/nginxtra/actions/rails/server.rb', line 55 def passenger_installed? Gem::Specification.find_by_name("passenger") end |
#server ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/nginxtra/actions/rails/server.rb', line 7 def server ensure_in_rails_app ensure_server_gem_installed begin start_verbose_output start_nginxtra wait_till_finished ensure stop_verbose_output stop_nginxtra end end |
#start_nginxtra ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nginxtra/actions/rails/server.rb', line 29 def start_nginxtra port = @thor.["port"] environment = @thor.["environment"] @thor.empty_directory "tmp" unless File.directory? "tmp" @thor.empty_directory "tmp/nginxtra" unless File.directory? "tmp/nginxtra" @thor.create_file config_path, %(nginxtra.simple_config do rails port: #{port}, environment: "#{environment}" end ), force: true @thor.invoke Nginxtra::CLI, ["start"], :basedir => basedir, :config => config_path, :workingdir => workingdir, :"non-interactive" => true @thor.say "Listening on http://localhost:#{port}/" @thor.say "Environment: #{environment}" end |
#start_verbose_output ⇒ Object
76 77 78 79 80 |
# File 'lib/nginxtra/actions/rails/server.rb', line 76 def start_verbose_output return unless @thor.["verbose"] @verbose_run = true Thread.new { verbose_thread } end |
#stop_nginxtra ⇒ Object
51 52 53 |
# File 'lib/nginxtra/actions/rails/server.rb', line 51 def stop_nginxtra @thor.invoke Nginxtra::CLI, ["stop"], :basedir => basedir, :config => config_path, :workingdir => workingdir, :"non-interactive" => true end |
#stop_verbose_output ⇒ Object
82 83 84 85 |
# File 'lib/nginxtra/actions/rails/server.rb', line 82 def stop_verbose_output return unless @thor.["verbose"] @verbose_run = false end |
#verbose_thread ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/nginxtra/actions/rails/server.rb', line 88 def verbose_thread environment = @thor.["environment"] log_path = "log/#{environment}.log" if File.exist? log_path log = File.open log_path, "r" log.seek 0, IO::SEEK_END else while @verbose_run if File.exist? log_path log = File.open log_path, "r" break end sleep 0.1 end end while @verbose_run select [log] line = log.gets if line puts line puts line while (line = log.gets) end sleep 0.1 end ensure log.close if log end |
#wait_till_finished ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/nginxtra/actions/rails/server.rb', line 43 def wait_till_finished @thor.say "Ctrl-C or Ctrl-D to shutdown server" next until $stdin.getc.nil? @thor.say "Captured Ctrl-D..." rescue Interrupt @thor.say "Captured Ctrl-C..." end |
#workingdir ⇒ Object
67 68 69 |
# File 'lib/nginxtra/actions/rails/server.rb', line 67 def workingdir File.absolute_path "." end |