lib/smartcloud/grids/buildpacker.rb in smartcloud-0.1.0.rc2 vs lib/smartcloud/grids/buildpacker.rb in smartcloud-0.1.0.rc3

- old
+ new

@@ -15,15 +15,24 @@ logger.formatter = nil exit 1 end def pack_rails - return unless bundle_install? - return unless precompile_assets? - return unless start_web_server? + if File.exist? "tmp/smartcloud/packed" + begin + pid = File.read('tmp/smartcloud/packed').to_i + Process.kill('QUIT', pid) + rescue Errno::ESRCH # No such process + end + exec "bundle", "exec", "puma", "--config", "config/puma.rb" + else + return unless bundle_install? + return unless precompile_assets? + return unless test_web_server? - exit 0 + exit 0 + end end # Perform bundle install def bundle_install? logger.info "Performing bundle install ..." @@ -62,14 +71,18 @@ logger.error "Could not install Javascript dependencies or pre-compile assets." return false end end - # Perform starting of web server - def start_web_server? - logger.debug "Starting Web Server ..." + # Perform testing of web server + def test_web_server? + logger.info "Setting up Web Server ..." + # tmp folder + FileUtils.mkdir_p("tmp/smartcloud") + FileUtils.rm_f("tmp/smartcloud/packed") + # Spawn Process pid = Process.spawn("bundle", "exec", "puma", "--config", "config/puma.rb") Process.detach(pid) # Sleep @@ -77,13 +90,13 @@ # Check PID running status = nil begin Process.kill(0, pid) - puts "Web Server started successfully." + system("#{pid}" > "tmp/smartcloud/packed") status = true rescue Errno::ESRCH # No such process - puts "Web Server cound not start" + logger.info "Web Server could not start" status = false end # Return status return status