Class: KPM::TomcatManager

Inherits:
Object
  • Object
show all
Defined in:
lib/kpm/tomcat_manager.rb

Constant Summary collapse

DOWNLOAD_URL =
'https://s3.amazonaws.com/kb-binaries/apache-tomcat-7.0.42.tar.gz'

Instance Method Summary collapse

Constructor Details

#initialize(tomcat_dir, logger) ⇒ TomcatManager

Returns a new instance of TomcatManager.



9
10
11
12
# File 'lib/kpm/tomcat_manager.rb', line 9

def initialize(tomcat_dir, logger)
  @tomcat_dir = Pathname.new(tomcat_dir)
  @logger = logger
end

Instance Method Details

#downloadObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kpm/tomcat_manager.rb', line 14

def download
  uri = URI.parse(DOWNLOAD_URL)

  path = nil
  Dir.mktmpdir do |dir|
    file = Pathname.new(dir).join('tomcat.tar.gz')

    @logger.info "Starting download of #{DOWNLOAD_URL} to #{file}"
    Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
      File.open(file, 'wb+') do |file|
        http.get(uri.path) do |body|
          file.write(body)
        end
      end
    end

    path = Utils.unpack_tgz(file.to_s, @tomcat_dir, true)
  end

  @logger.info "Successful installation of #{DOWNLOAD_URL} to #{path}"
  path
end

#helpObject



56
57
58
59
60
61
# File 'lib/kpm/tomcat_manager.rb', line 56

def help
  "Tomcat installed at #{@tomcat_dir}
Start script: #{@tomcat_dir.join('bin').join('startup.sh').to_s}
Stop script: #{@tomcat_dir.join('bin').join('shutdown.sh').to_s}
Logs: #{@tomcat_dir.join('logs').to_s}"
end

#setupObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kpm/tomcat_manager.rb', line 37

def setup
  # Remove default webapps
  %w(ROOT docs examples host-manager manager).each do |webapp|
    FileUtils.rm_rf(@tomcat_dir.join('webapps').join(webapp))
  end

  # Update Root.xml
  root_xml_dir = @tomcat_dir.join('conf').join('Catalina').join('localhost')
  FileUtils.mkdir_p(root_xml_dir)
  File.write(root_xml_dir.join('ROOT.xml'), '<Context></Context>')

  # Setup default properties
  setenv_sh_path = @tomcat_dir.join('bin').join('setenv.sh')

  File.write(setenv_sh_path, "export CATALINA_OPTS=\"$CATALINA_OPTS #{default_java_properties}\"")

  @tomcat_dir.join('webapps').join('ROOT.war').to_s
end