-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht_ports.rb
More file actions
executable file
·67 lines (52 loc) · 1.78 KB
/
t_ports.rb
File metadata and controls
executable file
·67 lines (52 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/ruby
=begin
--------------------------------------------------------------------------------
Change the port settings for the Tomcat of the current instance.
--------------------------------------------------------------------------------
Get the current port settings (how)? Offer options of 1-9. Modify server.xml (and setenv.sh) accordingly
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require 'common'
def show_current_ports()
puts "Current tomcat ports: main=#{$instance.tomcat.port}, jpda=#{$instance.tomcat.jpda_port}"
puts
end
def choose_port_range()
puts "Enter port range from 1 to 9: "
puts " (for port based on 1080, 2080, etc.)"
input = STDIN.gets.chomp
@choice = input.to_i
raise UserInputError.new("Invalid range: #{input}") unless (1..9).include?(@choice)
end
def save_choice()
modify_server_xml()
modify_setenv_sh()
end
def modify_server_xml()
replace_in_file($instance.tomcat.file("conf/server.xml"), /"\d(\d\d\d)"/, "\"#{@choice}\\1\"")
puts "modified ports in conf/server.xml"
end
def modify_setenv_sh()
return unless $instance.tomcat.jpda_port.to_i > 0
replace_in_file($instance.tomcat.file("bin/setenv.sh"), /JPDA_ADDRESS=\d(\d\d\d)/, "JPDA_ADDRESS=#{@choice}\\1")
puts "modified JPDA port in bin/setenv.sh"
end
def replace_in_file(filename, regexp, replacement)
raw_text = File.read(filename)
File.open(filename, "w") do |file|
file.puts(raw_text.gsub(regexp, replacement))
end
end
#
# ---------------------------------------------------------
# MAIN ROUTINE
# ---------------------------------------------------------
#
begin
show_current_ports()
choose_port_range()
save_choice()
rescue UserInputError
puts "ERROR: #{$!}"
end