Sha256: 7d61d221efc5174b91b7672a19299ec0422e98f7fc5a59904b476389b4668ec5

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

#--
# Yast rake
#
# Copyright (C) 2020, SUSE LLC
#   This library is free software; you can redistribute it and/or modify
# it only under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
#
#   This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
#   You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#++

require "json"
require "webrick"

module Yast
  # a webrick servlet which lists all rake servers running on this machine
  class ServersServlet < WEBrick::HTTPServlet::AbstractServlet
    def do_GET(_request, response)
      response.status = 200
      response.content_type = "application/json"
      response.body = servers.to_json
    end

  private

    # find the locally running "rake server" processes
    def servers
      output = `pgrep -a -f "rake server \\([0-9]+,.*\\)"`
      output.lines.map do |l|
        l.match(/rake server \(([0-9]+),(.*)\)/)
        {
          port: Regexp.last_match[1],
          dir:  Regexp.last_match[2]
        }
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
yast-rake-0.2.51 lib/yast/servers_servlet.rb
yast-rake-0.2.50 lib/yast/servers_servlet.rb
yast-rake-0.2.49 lib/yast/servers_servlet.rb
yast-rake-0.2.48 lib/yast/servers_servlet.rb
yast-rake-0.2.47 lib/yast/servers_servlet.rb
yast-rake-0.2.46 lib/yast/servers_servlet.rb
yast-rake-0.2.45 lib/yast/servers_servlet.rb
yast-rake-0.2.44 lib/yast/servers_servlet.rb
yast-rake-0.2.43 lib/yast/servers_servlet.rb
yast-rake-0.2.42 lib/yast/servers_servlet.rb
yast-rake-0.2.41 lib/yast/servers_servlet.rb
yast-rake-0.2.40 lib/yast/servers_servlet.rb
yast-rake-0.2.39 lib/yast/servers_servlet.rb
yast-rake-0.2.38 lib/yast/servers_servlet.rb
yast-rake-0.2.37 lib/yast/servers_servlet.rb