Sha256: 336747c3c6c510de12b15e3491717564ef3b04995776b75088bc11e9879535c6

Contents?: true

Size: 1.57 KB

Versions: 22

Compression:

Stored size: 1.57 KB

Contents

module Padrino
  module Cli
    module Adapter
      class << self
        # Start for the given options a rackup handler
        def start(options)

          puts "=> Padrino/#{Padrino.version} has taken the stage #{options.environment} on port #{options.port}"

          if options.daemonize?

            stop # Need to stop a process if it exists

            fork do
              Process.setsid
              return if fork
              File.umask 0000
              puts "=> Padrino server has been daemonized with pid #{Process.pid}"
              STDIN.reopen "/dev/null"
              STDOUT.reopen "/dev/null", "a"
              STDERR.reopen STDOUT

              FileUtils.mkdir_p("tmp/pids") unless File.exist?("tmp/pids")
              pid = "tmp/pids/server.pid"

              if pid
                File.open(pid, 'w'){ |f| f.write("#{Process.pid}") }
                at_return { File.delete(pid) if File.exist?(pid) }
              end

              Padrino.run!(options.host, options.port, options.adapter)

            end
          else
            Padrino.run!(options.host, options.port, options.adapter)
          end
        end

        # Method that stop (if exist) a running Padrino.application
        def stop
          if File.exist?("tmp/pids/server.pid")
            pid = File.read("tmp/pids/server.pid").to_i
            print "=> Sending SIGTERM to process with pid #{pid} wait "
            Process.kill(15, pid) rescue nil
            1.step(5) { |i| sleep i; print "."; $stdout.flush }
            puts " done."
          end
        end

      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
padrino-core-0.9.1 lib/padrino-core/cli/adapter.rb
padrino-core-0.9.0 lib/padrino-core/cli/adapter.rb
padrino-core-0.8.5 lib/padrino-core/cli/adapter.rb
padrino-core-0.8.4 lib/padrino-core/cli/adapter.rb
padrino-core-0.8.3 lib/padrino-core/cli/adapter.rb
padrino-core-0.8.2 lib/padrino-core/cli/adapter.rb
padrino-core-0.8.1 lib/padrino-core/cli/adapter.rb
padrino-core-0.8.0 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.9 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.8 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.7 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.6 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.5 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.4 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.3 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.2 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.1 lib/padrino-core/cli/adapter.rb
padrino-core-0.7.0 lib/padrino-core/cli/adapter.rb
padrino-core-0.6.7 lib/padrino-core/cli/adapter.rb
padrino-core-0.6.3 lib/padrino-core/cli/adapter.rb