psadmin_plus 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/psa +156 -132
  3. data/lib/psadmin_plus.rb +636 -537
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9e50fadeb47fc6959bfef534bb1fb031c85dc7051291ccbf914df38731351e6
4
- data.tar.gz: 54aefd4d1ed463119baf1450a9feec43dc46db9e11c83843d4d790b536ac7278
3
+ metadata.gz: 5811dc395997ea722f4b5c15f2d6552e9c0c351ade9c64346a9007ea3d600f6b
4
+ data.tar.gz: 6785104563ac2b0cef79dce06bfc5980947c32bec12649bad37327b858fba4fa
5
5
  SHA512:
6
- metadata.gz: a8255d51419c37a7cd16696202434131f4861d5a1f647dfc1558268801942cc72689e5ed6f4f492c10e64c941e732e42cc38c2af9c758d39b0dcf8e6194e5a45
7
- data.tar.gz: 76cd40f2fb74de8824add86573a2766feed4f269039b9095e176fc4e71c8a5182a7bc2d885c05b5cd1d1deb8fbcdd7c44fbce7f2444b4c9d4519e2b8886bafee
6
+ metadata.gz: cb1dcae5cbbbd435802ddb7a546c892af6a68c6b172297ceec562db30762cc07079bbdb3833ad1c9eaa52f787fc853f79d1a9d4dc0dfdffb0c74267e2d02711b
7
+ data.tar.gz: 01cef0fd3725cf5801df399f310bfc2e7eb9d7a940522a701978e71398a71e336e07f3976e20407413384205d340f83bc7691889476dae34131b469c32bfbcc5
data/bin/psa CHANGED
@@ -1,132 +1,156 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'psadmin_plus'
4
-
5
- # options
6
- opts_c = ARGV.shift || "help"
7
- opts_t = ARGV.shift || "all"
8
- opts_d = ARGV.shift || "all"
9
- opt_cfg = ARGV.shift
10
-
11
- commands = opts_c.split(',')
12
- types = opts_t.split(',')
13
- domains = opts_d.split(',')
14
-
15
- if types.include? "all" then types = ['app','prcs','web'] end
16
- if domains.include? "all" then all_domains = true end
17
-
18
-
19
-
20
- # setup environment
21
- PS_PSA_CONF = ENV['PS_PSA_CONF'] || "#{ENV['HOME']}/.psa.conf"
22
- if File.exists?(PS_PSA_CONF) then
23
- File.readlines(PS_PSA_CONF).each do |line|
24
- if line.start_with? "#" then
25
- next
26
- else
27
- key, value = line.split "="
28
- ENV[key] = value.strip
29
- end
30
- end
31
- end
32
-
33
- # constants
34
- OS_CONST = os
35
- PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2"
36
- PS_POOL_MGMT = ENV['PS_POOL_MGMT'] || "on"
37
- PS_HEALTH_FILE = ENV['PS_HEALTH_FILE'] || "health.html"
38
- PS_HEALTH_TIME = ENV['PS_HEALTH_TIME'] || "60"
39
- PS_HEALTH_TEXT = ENV['PS_HEALTH_TEXT'] || "true"
40
- PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on"
41
- PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "cmd /c #{env('PS_HOME')}/appserv"
42
- PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false"
43
- PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false"
44
- PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false"
45
- PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false"
46
- PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "false"
47
-
48
- # validation
49
- # check runtime user
50
- if "#{OS_CONST}" == "linux" then
51
- if !system("id #{PS_RUNTIME_USER} &> /dev/null") then
52
- puts "#{PS_RUNTIME_USER} is not valid. Please correct PS_RUNTIME_USER, then try again."
53
- exit
54
- end
55
- else
56
- # windows - TODO
57
- end
58
-
59
- # process
60
- commands.each do |c|
61
- case "#{c}"
62
- when "help"
63
- do_help
64
- when "admin"
65
- do_admin
66
- when "util"
67
- do_util
68
- when "list"
69
- do_list
70
- when "summary"
71
- do_summary
72
- else
73
- types.each do |t|
74
- if all_domains then
75
- case "#{t}"
76
- when "app"
77
- domains = find_apps
78
- when "prcs"
79
- domains = find_prcss
80
- when "web"
81
- domains = find_webs
82
- end
83
- end
84
- domains.each do |d|
85
- case "#{c}"
86
- when "status"
87
- do_cmd_banner(c,t,d)
88
- do_status(t,d)
89
- when "start"
90
- do_cmd_banner(c,t,d)
91
- do_start(t,d)
92
- when "stop"
93
- do_cmd_banner(c,t,d)
94
- do_stop(t,d)
95
- when "kill"
96
- do_cmd_banner(c,t,d)
97
- do_kill(t,d)
98
- when "configure"
99
- do_cmd_banner(c,t,d)
100
- do_configure(t,d)
101
- when "reconfigure"
102
- do_cmd_banner(c,t,d)
103
- do_reconfigure(t,d)
104
- when "purge"
105
- do_cmd_banner(c,t,d)
106
- do_purge(t,d)
107
- when "flush"
108
- do_cmd_banner(c,t,d)
109
- do_flush(t,d)
110
- when "restart"
111
- do_cmd_banner(c,t,d)
112
- do_restart(t,d)
113
- when "bounce"
114
- do_cmd_banner(c,t,d)
115
- do_bounce(t,d)
116
- when "pooladd"
117
- if t == "web"
118
- do_cmd_banner(c,t,d)
119
- do_pooladd(t,d)
120
- end
121
- when "poolrm"
122
- if t == "web"
123
- do_cmd_banner(c,t,d)
124
- do_poolrm(t,d)
125
- end
126
- else
127
- puts "Not a valid command. See psa help"
128
- end
129
- end
130
- end
131
- end
132
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'psadmin_plus'
5
+ rescue LoadError
6
+ # running directly, not through gem install
7
+ require_relative '../lib/psadmin_plus.rb'
8
+ end
9
+
10
+ # options
11
+ opts_c = ARGV.shift || "help"
12
+ opts_t = ARGV.shift || "all"
13
+ opts_d = ARGV.shift || "all"
14
+ # Set remaining arguments as environment variables
15
+ ARGV.each do |arg|
16
+ if arg.include? "="
17
+ var = arg.split('=')
18
+ ENV[var[0]]=var[1]
19
+ puts "Setting environment variable " + var[0] + "=" + var[1]
20
+ else
21
+ # puts "Skip argument, no valid environment variable found."
22
+ end
23
+ end
24
+
25
+ commands = opts_c.split(',')
26
+ types = opts_t.split(',')
27
+ domains = opts_d.split(',')
28
+
29
+ if types.include? "all" then types = ['app','prcs','web'] end
30
+ if domains.include? "all" then all_domains = true end
31
+
32
+ # setup environment
33
+ PS_PSA_CONF = ENV['PS_PSA_CONF'] || "#{ENV['HOME']}/.psa.conf"
34
+ if File.exists?(PS_PSA_CONF) then
35
+ File.readlines(PS_PSA_CONF).each do |line|
36
+ if line.start_with? "#" then
37
+ next
38
+ else
39
+ key, value = line.split "="
40
+ value.nil? ? next : ENV[key] = value.strip
41
+ end
42
+ end
43
+ end
44
+
45
+ # constants
46
+ OS_CONST = os
47
+ PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2"
48
+ PS_HOOK_INTERP = ENV['PS_HOOK_INTERP'] || "ruby"
49
+ PS_HOOK_PRE = ENV['PS_HOOK_PRE'] || "false"
50
+ PS_HOOK_POST = ENV['PS_HOOK_POST'] || "false"
51
+ PS_HOOK_START = ENV['PS_HOOK_START'] || "false"
52
+ PS_HOOK_STOP = ENV['PS_HOOK_STOP'] || "false"
53
+ PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on"
54
+ PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "cmd /c #{env('PS_HOME')}/appserv"
55
+ PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false"
56
+ PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false"
57
+ PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false"
58
+ PS_MULTI_DELIMIT = ENV['PS_MULTI_DELIMIT'] || "/"
59
+ PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0
60
+ PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false"
61
+ PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "false"
62
+
63
+ # validation
64
+ # check runtime user
65
+ if "#{OS_CONST}" == "linux" then
66
+ if !system("id #{PS_RUNTIME_USER} &> /dev/null") then
67
+ puts "#{PS_RUNTIME_USER} is not valid. Please correct PS_RUNTIME_USER, then try again."
68
+ exit
69
+ end
70
+ else
71
+ # windows - TODO
72
+ end
73
+
74
+ # process
75
+ commands.each do |c|
76
+ case "#{c}"
77
+ when "help"
78
+ do_help
79
+ when "admin"
80
+ do_admin
81
+ when "util"
82
+ do_util
83
+ when "list"
84
+ do_list
85
+ when "summary"
86
+ do_summary
87
+ else
88
+ types.each do |t|
89
+ # find valid domains for this type
90
+ case "#{t}"
91
+ when "app"
92
+ valid_domains = find_apps
93
+ when "pubsub"
94
+ valid_domains = find_apps # TODO - find only apps with PUBSUB enabled?
95
+ when "prcs"
96
+ valid_domains = find_prcss
97
+ when "web"
98
+ valid_domains = find_webs
99
+ end
100
+
101
+ if all_domains then
102
+ domains = valid_domains
103
+ end
104
+
105
+ domains.each do |d|
106
+ # validate domain for current type
107
+ if valid_domains.include? d
108
+ do_hookpre(c,t,d)
109
+ do_set_cfg_home(d)
110
+
111
+ case "#{c}"
112
+ when "status"
113
+ do_cmd_banner(c,t,d)
114
+ do_status(t,d)
115
+ when "start"
116
+ do_cmd_banner(c,t,d)
117
+ do_start(t,d)
118
+ when "stop"
119
+ do_cmd_banner(c,t,d)
120
+ do_stop(t,d)
121
+ when "kill"
122
+ do_cmd_banner(c,t,d)
123
+ do_kill(t,d)
124
+ when "configure"
125
+ do_cmd_banner(c,t,d)
126
+ do_configure(t,d)
127
+ when "reconfigure"
128
+ do_cmd_banner(c,t,d)
129
+ do_reconfigure(t,d)
130
+ when "purge"
131
+ do_cmd_banner(c,t,d)
132
+ do_purge(t,d)
133
+ when "flush"
134
+ do_cmd_banner(c,t,d)
135
+ do_flush(t,d)
136
+ when "restart"
137
+ do_cmd_banner(c,t,d)
138
+ do_restart(t,d)
139
+ when "bounce"
140
+ do_cmd_banner(c,t,d)
141
+ do_bounce(t,d)
142
+ else
143
+ puts "Not a valid command. See psa help"
144
+ end
145
+
146
+ do_hookpost(c,t,d)
147
+ else
148
+ if ENV['PS_PSA_DEBUG'] == "true"
149
+ do_cmd_banner(c,t,d)
150
+ puts "No valid domain found for this type."
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
data/lib/psadmin_plus.rb CHANGED
@@ -1,537 +1,636 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rbconfig'
4
- require 'etc'
5
- require 'open3'
6
-
7
- def do_help
8
- puts "Usage: psa [command] <type> <domain>"
9
- puts " "
10
- puts "Commands:"
11
- puts " "
12
- puts " help display this help message"
13
- puts " list list domains"
14
- #puts " admin launch psadmin"
15
- puts " summary PS_CFG_HOME summary, no type or domain needed"
16
- puts " status status of the domain"
17
- puts " start pooladd, if enabled, then start the domain"
18
- puts " stop poolrm, if enabled, stop the domain"
19
- puts " restart stop and start the domain"
20
- puts " purge clear domain cache"
21
- puts " reconfigure stop, configure, and start the domain"
22
- puts " bounce stop, flush, purge, configure and start the domain"
23
- puts " kill force stop the domain"
24
- puts " configure configure the domain"
25
- puts " flush clear domain IPC"
26
- puts " poolrm remove domain from load balanced pool "
27
- puts " pooladd add domain to load balanced pool "
28
- puts " "
29
- puts "Types:"
30
- puts " "
31
- puts " app act on application domains"
32
- puts " prcs act on process scheduler domains"
33
- puts " web act on web domains"
34
- puts " all,<blank> act on all types of domains"
35
- puts " "
36
- puts "Domains:"
37
- puts " "
38
- puts " dom act on specific domains"
39
- puts " all,<blank> act on all domains"
40
- puts " "
41
- puts "Each parameter type can be enter in a comma separated list "
42
- puts " "
43
- end
44
-
45
- def do_is_runtime_user_nix
46
- result = ENV['USER'] == PS_RUNTIME_USER ? true : false
47
- end
48
-
49
- def do_is_runtime_user_win
50
- result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false
51
- end
52
-
53
- def env(var)
54
- result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%"
55
- end
56
-
57
- def do_cmd(cmd, print = true, powershell = true)
58
- case "#{OS_CONST}"
59
- when "linux"
60
- if do_is_runtime_user_nix
61
- case "#{PS_PSA_DEBUG}"
62
- when "true"
63
- p "Command: #{cmd}"
64
- end
65
- out = `#{cmd}`
66
- else
67
- if "#{PS_PSA_SUDO}" == "on"
68
- case "#{PS_PSA_DEBUG}"
69
- when "true"
70
- p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'"
71
- end
72
- out = `sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'`
73
- else
74
- print "#{PS_RUNTIME_USER} "
75
- case "#{PS_PSA_DEBUG}"
76
- when "true"
77
- p "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'"
78
- end
79
- out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'`
80
- end
81
- end
82
- when "windows"
83
- case powershell
84
- when true
85
- case "#{PS_PSA_DEBUG}"
86
- when "true"
87
- p "Command: powershell -NoProfile -Command \"#{cmd}\""
88
- end
89
- out = `powershell -NoProfile -Command "#{cmd}"`
90
- else
91
- case "#{PS_PSA_DEBUG}"
92
- when "true"
93
- p "Command: #{cmd}"
94
- end
95
- out = `#{cmd}`
96
- end
97
- else
98
- out = "Invalid OS"
99
- end
100
- print ? (puts out) : result = out
101
- out
102
- end
103
-
104
- def do_cmd_banner(c,t,d)
105
- puts ""
106
- puts "### #{c} - #{t} - #{d} ###"
107
- end
108
-
109
- def find_apps_nix
110
- case "#{PS_MULTI_HOME}"
111
- when "false"
112
- apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx",false).split(/\n+/)
113
- else
114
- apps = do_cmd("find #{PS_MULTI_HOME}/*/appserv/*/psappsrv.ubx",false).split(/\n+/)
115
- end
116
- apps.map! {|app| app.split("/")[-2]}
117
- end
118
-
119
- def find_prcss_nix
120
- case "#{PS_MULTI_HOME}"
121
- when "false"
122
- prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx",false).split(/\n+/)
123
- else
124
- prcss = do_cmd("find #{PS_MULTI_HOME}/*/appserv/prcs/*/psprcsrv.ubx",false).split(/\n+/)
125
- end
126
- prcss.map! {|prcs| prcs.split("/")[-2]}
127
- end
128
-
129
- def find_webs_nix
130
- case "#{PS_MULTI_HOME}"
131
- when "false"
132
- webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/)
133
- else
134
- webs = do_cmd("find #{PS_MULTI_HOME}/*/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/)
135
- end
136
- webs.map! {|web| web.split("/")[-2]}
137
- end
138
-
139
- def find_apps_win
140
- case "#{PS_MULTI_HOME}"
141
- when "false"
142
- apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
143
- else
144
- apps = do_cmd("(get-childitem #{PS_MULTI_HOME}/*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
145
- end
146
- apps.map! {|app| app.split('\\')[-2]}
147
- end
148
-
149
- def find_prcss_win
150
- case "#{PS_MULTI_HOME}"
151
- when "false"
152
- prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
153
- else
154
- prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}/*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
155
- end
156
- prcss.map! {|prcs| prcs.split("\\")[-2]}
157
- end
158
-
159
- def find_webs_win
160
- case "#{PS_MULTI_HOME}"
161
- when "false"
162
- webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
163
- else
164
- webs = do_cmd("(get-childitem #{PS_MULTI_HOME}/*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
165
- end
166
- webs.map! {|web| web.split("\\")[-2]}
167
- end
168
-
169
- def find_apps
170
- apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win
171
- end
172
-
173
- def find_prcss
174
- prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win
175
- end
176
-
177
- def find_webs
178
- webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win
179
- end
180
-
181
- def do_util
182
- puts "TODO: util"
183
- end
184
-
185
- def do_admin
186
- do_cmd("#{PS_PSADMIN_PATH}/psadmin")
187
- end
188
-
189
- def do_list
190
- puts "---"
191
- print "hostname: " ; do_cmd('hostname')
192
- print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'))
193
- if PS_MULTI_HOME == "false"
194
- print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'))
195
- end
196
- puts ""
197
- puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}"
198
- puts "PS_PSA_SUDO: #{PS_PSA_SUDO}"
199
- puts "PS_POOL_MGMT: #{PS_POOL_MGMT}"
200
- puts "PS_HEALTH_FILE: #{PS_HEALTH_FILE}"
201
- puts "PS_HEALTH_TIME: #{PS_HEALTH_TIME}"
202
- puts "PS_HEALTH_TEXT: #{PS_HEALTH_TEXT}"
203
- puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}"
204
- puts "PS_MULT_HOME: #{PS_MULTI_HOME}"
205
- puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}"
206
- puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}"
207
- puts ""
208
- puts "app:"
209
- find_apps.each do |a|
210
- puts " - #{a}"
211
- end
212
- puts ""
213
- puts "prcs:"
214
- find_prcss.each do |p|
215
- puts " - #{p}"
216
- end
217
- puts ""
218
- puts "web:"
219
- find_webs.each do |w|
220
- puts " - #{w}"
221
- end
222
- puts ""
223
- end
224
-
225
- def do_summary
226
- if "#{PS_MULTI_HOME}" != "false"
227
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
228
- end
229
-
230
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary")
231
- #do_status("web","all")
232
- end
233
-
234
- def do_status(type, domain)
235
- if "#{PS_MULTI_HOME}" != "false"
236
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
237
- end
238
-
239
- case type
240
- when "app"
241
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}")
242
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}")
243
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}")
244
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}")
245
- when "prcs"
246
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}")
247
- when "web"
248
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}")
249
- else
250
- puts "Invalid type, see psa help"
251
- end
252
- end
253
-
254
- def do_start(type, domain)
255
- if "#{PS_MULTI_HOME}" != "false"
256
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
257
- end
258
-
259
- web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*"
260
- app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*"
261
- prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*"
262
-
263
- case "#{PS_PARALLEL_BOOT}"
264
- when "false"
265
- start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}"
266
- when "true"
267
- start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}"
268
- end
269
- start_app_service_cmd = "start-service #{app_service_name}"
270
- start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}"
271
- start_prcs_service_cmd = "start-service #{prcs_service_name}"
272
- start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh"
273
- start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}"
274
- start_web_service_cmd = "start-service #{web_service_name}"
275
-
276
- # 10-08-2020 Dale Haman: Changing the logic used on PS_WIN_SERVICES, it will never be tux, app or all.
277
- case type
278
- when "app"
279
- case "#{PS_WIN_SERVICES}"
280
- when "true", "tux", "app", "all"
281
- do_cmd(start_app_service_cmd)
282
- else
283
- do_cmd(start_app_cmd)
284
- case "#{PS_TRAIL_SERVICE}"
285
- when "true"
286
- do_cmd(start_app_service_cmd)
287
- end
288
- end
289
- when "prcs"
290
- case "#{PS_WIN_SERVICES}"
291
- when "true", "tux", "prcs", "all"
292
- do_cmd(start_prcs_service_cmd)
293
- else
294
- do_cmd(start_prcs_cmd)
295
- case "#{PS_TRAIL_SERVICE}"
296
- when "true"
297
- do_cmd(start_prcs_service_cmd)
298
- end
299
- end
300
- when "web"
301
- case "#{OS_CONST}"
302
- when "linux"
303
- if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok")
304
- puts "Domain #{domain} already started"
305
- else
306
- do_cmd(start_web_cmd_lnx)
307
- sleep 5.0
308
- end
309
- when "windows"
310
- case "#{PS_WIN_SERVICES}"
311
- when "true", "web", "all"
312
- do_cmd(start_web_service_cmd)
313
- else
314
- # Run command outside of powershell with 'false' parameter
315
- do_cmd(start_web_cmd_win, true, false)
316
- case "#{PS_TRAIL_SERVICE}"
317
- when "true", "web", "all"
318
- do_cmd(start_web_service_cmd)
319
- end
320
- end
321
- end
322
- do_pooladd(type,domain)
323
- else
324
- puts "Invalid type, see psa help"
325
- end
326
- end
327
-
328
- def do_stop(type, domain)
329
- if "#{PS_MULTI_HOME}" != "false"
330
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
331
- end
332
-
333
- web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*"
334
- app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*"
335
- prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*"
336
-
337
- stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}"
338
- stop_app_service_cmd = "stop-service #{app_service_name}"
339
- stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}"
340
- stop_prcs_service_cmd = "stop-service #{prcs_service_name}"
341
- stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh"
342
- stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}"
343
- stop_web_service_cmd = "stop-service #{web_service_name}"
344
-
345
- case type
346
- when "app"
347
- case "#{PS_WIN_SERVICES}"
348
- when "true"
349
- do_cmd(stop_app_service_cmd)
350
- else
351
- do_cmd(stop_app_cmd)
352
- case "#{PS_TRAIL_SERVICE}"
353
- when "true"
354
- do_cmd(stop_app_service_cmd)
355
- end
356
- end
357
- when "prcs"
358
- case "#{PS_WIN_SERVICES}"
359
- when "true"
360
- do_cmd(stop_prcs_service_cmd)
361
- else
362
- do_cmd(stop_prcs_cmd)
363
- case "#{PS_TRAIL_SERVICE}"
364
- when "true"
365
- do_cmd(stop_prcs_service_cmd)
366
- end
367
- end
368
- when "web"
369
- do_poolrm(type,domain)
370
- case "#{OS_CONST}"
371
- when "linux"
372
- do_cmd(stop_web_cmd_lnx)
373
- when "windows"
374
- case "#{PS_WIN_SERVICES}"
375
- when "true"
376
- do_cmd(stop_web_service_cmd)
377
- else
378
- do_cmd(stop_web_cmd_win, true, false)
379
- case "#{PS_TRAIL_SERVICE}"
380
- when "true"
381
- do_cmd(stop_web_service_cmd)
382
- end
383
- end
384
- end
385
- else
386
- puts "Invalid type, see psa help"
387
- end
388
- end
389
-
390
- def do_kill(type, domain)
391
- if "#{PS_MULTI_HOME}" != "false"
392
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
393
- end
394
-
395
- case type
396
- when "app"
397
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}")
398
- when "prcs"
399
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}")
400
- when "web"
401
- case "#{OS_CONST}"
402
- when "windows"
403
- do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue")
404
- when "linux"
405
- return #kill n/a
406
- end
407
- else
408
- puts "Invalid type, see psa help"
409
- end
410
- end
411
-
412
- def do_configure(type, domain)
413
- if "#{PS_MULTI_HOME}" != "false"
414
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
415
- end
416
-
417
- case type
418
- when "app"
419
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}")
420
- when "prcs"
421
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}")
422
- when "web"
423
- return # web configure n/a
424
- else
425
- puts "Invalid type, see psa help"
426
- end
427
- end
428
-
429
- def do_purge(type, domain)
430
- if "#{PS_MULTI_HOME}" != "false"
431
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
432
- end
433
-
434
- case type
435
- when "app"
436
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}")
437
- when "prcs"
438
- do_cmd("echo purge todo")
439
- when "web"
440
- case "#{OS_CONST}"
441
- when "linux"
442
- do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/")
443
- puts "web cache purged"
444
- when "windows"
445
- do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\'))
446
- end
447
- else
448
- puts "Invalid type, see psa help"
449
- end
450
- end
451
-
452
- def do_flush(type, domain)
453
- if "#{PS_MULTI_HOME}" != "false"
454
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
455
- end
456
-
457
- case type
458
- when "app"
459
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}")
460
- when "prcs"
461
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}")
462
- when "web"
463
- return # web flush n/a
464
- else
465
- puts "Invalid type, see psa help"
466
- end
467
- end
468
-
469
- def do_restart(type, domain)
470
- do_stop(type, domain)
471
- do_start(type, domain)
472
- end
473
-
474
- def do_reconfigure(type, domain)
475
- do_stop(type, domain)
476
- do_configure(type, domain)
477
- do_start(type, domain)
478
- end
479
-
480
- def do_bounce(type, domain)
481
- do_stop(type, domain)
482
- do_purge(type, domain)
483
- do_flush(type, domain)
484
- do_configure(type, domain)
485
- do_start(type, domain)
486
- end
487
-
488
- def do_pooladd(type, domain)
489
- if PS_POOL_MGMT == "on" then
490
- # Change PS_HEALTH_TEXT and PS_HEALTH_FILE variables to match your system
491
- puts "Adding web domain to load balanced pool..."
492
- do_cmd("echo '#{PS_HEALTH_TEXT}' > #{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/#{PS_HEALTH_FILE}")
493
- sleep(PS_HEALTH_TIME.to_i)
494
- puts "...domain added to pool."
495
- puts ""
496
- else
497
- puts "Skipping pool managment. To enable, set PS_POOL_MGMT to 'on'."
498
- end
499
- end
500
-
501
- def do_poolrm(type,domain)
502
- if PS_POOL_MGMT == "on" then
503
- # Change PS_HEALTH_TEXT and PS_HEALTH_FILE variables to match your system
504
- puts "Removing domain from load balanced pool..."
505
- case "#{OS_CONST}"
506
- when "linux"
507
- do_cmd("rm -f #{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/#{PS_HEALTH_FILE}")
508
- when "windows"
509
- do_cmd("remove-item -force #{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/#{PS_HEALTH_FILE} -ErrorAction SilentlyContinue")
510
- else
511
- puts " badOS - #{OS_CONST}"
512
- end
513
- sleep(PS_HEALTH_TIME.to_i)
514
- puts "...domain removed from pool."
515
- puts ""
516
- else
517
- puts "Skipping pool managment. To enable, set PS_POOL_MGMT to 'on'."
518
- end
519
- end
520
-
521
- def os
522
- @os ||= (
523
- host_os = RbConfig::CONFIG['host_os']
524
- case host_os
525
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
526
- :windows
527
- when /darwin|mac os/
528
- :macosx
529
- when /linux/
530
- :linux
531
- when /solaris|bsd/
532
- :unix
533
- else
534
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
535
- end
536
- )
537
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbconfig'
4
+ require 'etc'
5
+ require 'open3'
6
+
7
+ def do_help
8
+ puts "Usage: psa [command] <type> <domain>"
9
+ puts " "
10
+ puts "Commands:"
11
+ puts " "
12
+ puts " help display this help message"
13
+ puts " list list domains"
14
+ #puts " admin launch psadmin"
15
+ puts " summary PS_CFG_HOME summary, no type or domain needed"
16
+ puts " status status of the domain"
17
+ puts " start hookstart, if enabled, then start the domain"
18
+ puts " stop hookstop, if enabled, stop the domain"
19
+ puts " restart stop and start the domain"
20
+ puts " purge clear domain cache"
21
+ puts " reconfigure stop, configure, and start the domain"
22
+ puts " bounce stop, flush, purge, configure and start the domain"
23
+ puts " kill force stop the domain"
24
+ puts " configure configure the domain"
25
+ puts " flush clear domain IPC"
26
+ puts " "
27
+ puts "Types:"
28
+ puts " "
29
+ puts " app act on application domains"
30
+ #puts " pubsub act on PUBSUB group of application domains"
31
+ puts " prcs act on process scheduler domains"
32
+ puts " web act on web domains"
33
+ puts " all,<blank> act on web, app, and prcs domains"
34
+ puts " "
35
+ puts "Domains:"
36
+ puts " "
37
+ puts " dom act on specific domains"
38
+ puts " all,<blank> act on all domains"
39
+ puts " "
40
+ puts "Each parameter type can be enter in a comma separated list "
41
+ puts " "
42
+ end
43
+
44
+ def do_is_runtime_user_nix
45
+ result = ENV['USER'] == PS_RUNTIME_USER ? true : false
46
+ end
47
+
48
+ def do_is_runtime_user_win
49
+ result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false
50
+ end
51
+
52
+ def env(var)
53
+ result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%"
54
+ end
55
+
56
+ def do_cmd(cmd, print = true, powershell = true)
57
+ case "#{OS_CONST}"
58
+ when "linux"
59
+ if do_is_runtime_user_nix
60
+ case "#{PS_PSA_DEBUG}"
61
+ when "true"
62
+ p "Command: #{cmd}"
63
+ end
64
+ out = `#{cmd}`
65
+ else
66
+ if "#{PS_PSA_SUDO}" == "on"
67
+ case "#{PS_PSA_DEBUG}"
68
+ when "true"
69
+ p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'"
70
+ end
71
+ out = `sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'`
72
+ else
73
+ print "#{PS_RUNTIME_USER} "
74
+ case "#{PS_PSA_DEBUG}"
75
+ when "true"
76
+ p "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'"
77
+ end
78
+ out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'`
79
+ end
80
+ end
81
+ when "windows"
82
+ case powershell
83
+ when true
84
+ case "#{PS_PSA_DEBUG}"
85
+ when "true"
86
+ p "Command: powershell -NoProfile -Command \"#{cmd}\""
87
+ end
88
+ out = `powershell -NoProfile -Command "#{cmd}"`
89
+ else
90
+ case "#{PS_PSA_DEBUG}"
91
+ when "true"
92
+ p "Command: #{cmd}"
93
+ end
94
+ out = `#{cmd}`
95
+ end
96
+ else
97
+ out = "Invalid OS"
98
+ end
99
+ print ? (puts out) : result = out
100
+ out
101
+ end
102
+
103
+ def do_cmd_banner(c,t,d)
104
+ puts ""
105
+ puts "===[ #{c} . #{t} . #{d} ]==="
106
+ puts ""
107
+ end
108
+
109
+ def do_set_cfg_home(d)
110
+ if "#{PS_MULTI_HOME}" != "false"
111
+ if PS_MULTI_PREFIX > 0
112
+ h = d.slice(0..PS_MULTI_PREFIX)
113
+ else
114
+ h = d
115
+ end
116
+ ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{h}"
117
+ end
118
+ end
119
+
120
+ def find_apps_nix
121
+ case "#{PS_MULTI_HOME}"
122
+ when "false"
123
+ apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false).split(/\n+/)
124
+ else
125
+ apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false).split(/\n+/)
126
+ end
127
+ apps.map! {|app| app.split("/")[-2]}
128
+ end
129
+
130
+ def find_prcss_nix
131
+ case "#{PS_MULTI_HOME}"
132
+ when "false"
133
+ prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false).split(/\n+/)
134
+ else
135
+ prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false).split(/\n+/)
136
+ end
137
+ prcss.map! {|prcs| prcs.split("/")[-2]}
138
+ end
139
+
140
+ def find_webs_nix
141
+ case "#{PS_MULTI_HOME}"
142
+ when "false"
143
+ webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/)
144
+ else
145
+ webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/)
146
+ end
147
+ webs.map! {|web| web.split("/")[-2]}
148
+ end
149
+
150
+ def find_sites_nix(domain)
151
+ webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false).split(/\n+/)
152
+ webs.map! {|site| site.split("/")[-1]}
153
+ end
154
+
155
+ def find_apps_win
156
+ case "#{PS_MULTI_HOME}"
157
+ when "false"
158
+ apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
159
+ else
160
+ apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
161
+ end
162
+ apps.map! {|app| app.split('\\')[-2]}
163
+ end
164
+
165
+ def find_prcss_win
166
+ case "#{PS_MULTI_HOME}"
167
+ when "false"
168
+ prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
169
+ else
170
+ prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
171
+ end
172
+ prcss.map! {|prcs| prcs.split("\\")[-2]}
173
+ end
174
+
175
+ def find_webs_win
176
+ case "#{PS_MULTI_HOME}"
177
+ when "false"
178
+ webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
179
+ else
180
+ webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
181
+ end
182
+ webs.map! {|web| web.split("\\")[-2]}
183
+ end
184
+
185
+ def find_sites_win(domain)
186
+ #TODO
187
+ #sites = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
188
+ #sites.map! {|site| site.split("\\")[-2]}
189
+ end
190
+
191
+ def find_apps
192
+ apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win
193
+ end
194
+
195
+ def find_prcss
196
+ prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win
197
+ end
198
+
199
+ def find_webs
200
+ webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win
201
+ end
202
+
203
+ def find_sites(domain)
204
+ sites = "#{OS_CONST}" == "linux" ? find_sites_nix(domain) : find_sites_win(domain)
205
+ end
206
+
207
+ def do_util
208
+ puts "TODO: util"
209
+ end
210
+
211
+ def do_admin
212
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin")
213
+ end
214
+
215
+ def do_list
216
+ puts "---"
217
+ print "hostname: " ; do_cmd('hostname')
218
+ print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'))
219
+ if PS_MULTI_HOME == "false"
220
+ print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'))
221
+ else
222
+ puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*"
223
+ end
224
+ puts ""
225
+ puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}"
226
+ puts "PS_PSA_SUDO: #{PS_PSA_SUDO}"
227
+ puts "PS_HOOK_INTERP: #{PS_HOOK_INTERP}"
228
+ puts "PS_HOOK_PRE: #{PS_HOOK_PRE}"
229
+ puts "PS_HOOK_POST: #{PS_HOOK_POST}"
230
+ puts "PS_HOOK_START: #{PS_HOOK_START}"
231
+ puts "PS_HOOK_STOP: #{PS_HOOK_STOP}"
232
+ puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}"
233
+ puts "PS_MULTI_HOME: #{PS_MULTI_HOME}"
234
+ puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}"
235
+ puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}"
236
+ puts ""
237
+ puts "app:"
238
+ find_apps.each do |a|
239
+ puts " - #{a}"
240
+ end
241
+ puts ""
242
+ puts "prcs:"
243
+ find_prcss.each do |p|
244
+ puts " - #{p}"
245
+ end
246
+ puts ""
247
+ puts "web:"
248
+ find_webs.each do |w|
249
+ puts " - #{w}"
250
+ end
251
+ puts ""
252
+ end
253
+
254
+ def do_psadmin_check
255
+ # Check to see if psadmin loads correctly
256
+ # This will help when used on web servers that don't have Tuxedo
257
+ case "#{PS_PSA_DEBUG}"
258
+ when "true"
259
+ puts "Checking psadmin version to validate configuration:"
260
+ check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true)
261
+ else
262
+ check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",false)
263
+ end
264
+ if check.include? "error"
265
+ # psadmin config is NOT valid
266
+ puts "ERROR: psadmin is not configured correctly for this environment!"
267
+ puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured"
268
+ false
269
+ else
270
+ # psadmin config is valid
271
+ true
272
+ end
273
+ end
274
+
275
+ def do_summary
276
+ if "#{PS_MULTI_HOME}" != "false"
277
+ ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{domain}"
278
+ end
279
+
280
+ do_psadmin_check ? nil : exit
281
+
282
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary")
283
+ #do_status("web","all")
284
+ end
285
+
286
+ def do_status(type, domain)
287
+ case type
288
+ when "app"
289
+ do_psadmin_check ? nil : return
290
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}")
291
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}")
292
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}")
293
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}")
294
+ when "pubsub"
295
+ ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG"
296
+ do_cmd("echo 'printserver -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin")
297
+ when "prcs"
298
+ do_psadmin_check ? nil : return
299
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}")
300
+ when "web"
301
+ # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service
302
+ #do_psadmin_check ? nil : return
303
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}")
304
+ #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh")
305
+ #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok")
306
+ else
307
+ puts "Invalid type, see psa help"
308
+ end
309
+ end
310
+
311
+ def do_start(type, domain)
312
+ web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*"
313
+ app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*"
314
+ prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*"
315
+
316
+ case "#{PS_PARALLEL_BOOT}"
317
+ when "false"
318
+ start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}"
319
+ when "true"
320
+ start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}"
321
+ end
322
+ start_app_service_cmd = "start-service #{app_service_name}"
323
+ start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}"
324
+ start_prcs_service_cmd = "start-service #{prcs_service_name}"
325
+ start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh"
326
+ start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}"
327
+ start_web_service_cmd = "start-service #{web_service_name}"
328
+
329
+ case type
330
+ when "app"
331
+ case "#{PS_WIN_SERVICES}"
332
+ when "true", "tux", "app", "all"
333
+ do_cmd(start_app_service_cmd)
334
+ else
335
+ do_cmd(start_app_cmd)
336
+ case "#{PS_TRAIL_SERVICE}"
337
+ when "true"
338
+ do_cmd(start_app_service_cmd)
339
+ end
340
+ end
341
+ do_hookstart("start",type,domain)
342
+ when "pubsub"
343
+ ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG"
344
+ do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin")
345
+ # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB?
346
+ when "prcs"
347
+ case "#{PS_WIN_SERVICES}"
348
+ when "true", "tux", "prcs", "all"
349
+ do_cmd(start_prcs_service_cmd)
350
+ else
351
+ do_cmd(start_prcs_cmd)
352
+ case "#{PS_TRAIL_SERVICE}"
353
+ when "true"
354
+ do_cmd(start_prcs_service_cmd)
355
+ end
356
+ end
357
+ do_hookstart("start",type,domain)
358
+ when "web"
359
+ case "#{OS_CONST}"
360
+ when "linux"
361
+ if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok")
362
+ puts "Domain #{domain} already started"
363
+ else
364
+ do_cmd(start_web_cmd_lnx)
365
+ sleep 5.0
366
+ end
367
+ when "windows"
368
+ case "#{PS_WIN_SERVICES}"
369
+ when "true", "web", "all"
370
+ do_cmd(start_web_service_cmd)
371
+ else
372
+ # Run command outside of powershell with 'false' parameter
373
+ do_cmd(start_web_cmd_win, true, false)
374
+ case "#{PS_TRAIL_SERVICE}"
375
+ when "true", "web", "all"
376
+ do_cmd(start_web_service_cmd)
377
+ end
378
+ end
379
+ end
380
+ do_hookstart("start",type,domain)
381
+ else
382
+ puts "Invalid type, see psa help"
383
+ end
384
+ end
385
+
386
+ def do_stop(type, domain)
387
+ web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*"
388
+ app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*"
389
+ prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*"
390
+
391
+ stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}"
392
+ stop_app_service_cmd = "stop-service #{app_service_name}"
393
+ stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}"
394
+ stop_prcs_service_cmd = "stop-service #{prcs_service_name}"
395
+ stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh"
396
+ stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}"
397
+ stop_web_service_cmd = "stop-service #{web_service_name}"
398
+
399
+ case type
400
+ when "app"
401
+ do_hookstop("stop",type,domain)
402
+ case "#{PS_WIN_SERVICES}"
403
+ when "true"
404
+ do_cmd(stop_app_service_cmd)
405
+ else
406
+ do_cmd(stop_app_cmd)
407
+ case "#{PS_TRAIL_SERVICE}"
408
+ when "true"
409
+ do_cmd(stop_app_service_cmd)
410
+ end
411
+ end
412
+ when "pubsub"
413
+ # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB?
414
+ ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG"
415
+ do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin")
416
+ when "prcs"
417
+ do_hookstop("stop",type,domain)
418
+ case "#{PS_WIN_SERVICES}"
419
+ when "true"
420
+ do_cmd(stop_prcs_service_cmd)
421
+ else
422
+ do_cmd(stop_prcs_cmd)
423
+ case "#{PS_TRAIL_SERVICE}"
424
+ when "true"
425
+ do_cmd(stop_prcs_service_cmd)
426
+ end
427
+ end
428
+ when "web"
429
+ do_hookstop("stop",type,domain)
430
+ case "#{OS_CONST}"
431
+ when "linux"
432
+ do_cmd(stop_web_cmd_lnx)
433
+ when "windows"
434
+ case "#{PS_WIN_SERVICES}"
435
+ when "true"
436
+ do_cmd(stop_web_service_cmd)
437
+ else
438
+ do_cmd(stop_web_cmd_win, true, false)
439
+ case "#{PS_TRAIL_SERVICE}"
440
+ when "true"
441
+ do_cmd(stop_web_service_cmd)
442
+ end
443
+ end
444
+ end
445
+ else
446
+ puts "Invalid type, see psa help"
447
+ end
448
+ end
449
+
450
+ def do_kill(type, domain)
451
+ case type
452
+ when "app"
453
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}")
454
+ when "prcs"
455
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}")
456
+ when "web"
457
+ case "#{OS_CONST}"
458
+ when "windows"
459
+ do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue")
460
+ when "linux"
461
+ do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')")
462
+ end
463
+ else
464
+ puts "Invalid type, see psa help"
465
+ end
466
+ end
467
+
468
+ def do_configure(type, domain)
469
+ case type
470
+ when "app"
471
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}")
472
+ when "prcs"
473
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}")
474
+ when "web"
475
+ do_webprof_reload("#{domain}")
476
+ else
477
+ puts "Invalid type, see psa help"
478
+ end
479
+ end
480
+
481
+ def do_purge(type, domain)
482
+ case type
483
+ when "app"
484
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}")
485
+ when "prcs"
486
+ do_cmd("echo Purge currently does nothing for prcs")
487
+ when "web"
488
+ case "#{OS_CONST}"
489
+ when "linux"
490
+ do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/")
491
+ puts "web cache purged"
492
+ when "windows"
493
+ do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\'))
494
+ end
495
+ else
496
+ puts "Invalid type, see psa help"
497
+ end
498
+ end
499
+
500
+ def do_flush(type, domain)
501
+ case type
502
+ when "app"
503
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}")
504
+ when "prcs"
505
+ do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}")
506
+ when "web"
507
+ return # web flush n/a
508
+ else
509
+ puts "Invalid type, see psa help"
510
+ end
511
+ end
512
+
513
+ def do_restart(type, domain)
514
+ do_stop(type, domain)
515
+ do_start(type, domain)
516
+ end
517
+
518
+ def do_reconfigure(type, domain)
519
+ do_stop(type, domain)
520
+ do_configure(type, domain)
521
+ do_start(type, domain)
522
+ end
523
+
524
+ def do_bounce(type, domain)
525
+ do_stop(type, domain)
526
+ do_purge(type, domain)
527
+ do_flush(type, domain)
528
+ do_configure(type, domain)
529
+ do_start(type, domain)
530
+ end
531
+
532
+ def do_hook(command, type, domain, script)
533
+ ENV['PSA_CMD'] = command
534
+ ENV['PSA_TYPE'] = type
535
+ ENV['PSA_DOMAIN'] = domain
536
+ out = `#{PS_HOOK_INTERP} #{script}`
537
+ puts out
538
+ end
539
+
540
+ def do_hookpre(command, type, domain)
541
+ if "#{PS_HOOK_PRE}" != "false"
542
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain pre command hook...\n\n") : nil
543
+ do_hook(command, type, domain, PS_HOOK_PRE)
544
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil
545
+ end
546
+ end
547
+
548
+ def do_hookpost(command, type, domain)
549
+ if "#{PS_HOOK_POST}" != "false"
550
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain post command hook...\n\n") : nil
551
+ do_hook(command, type, domain, PS_HOOK_POST)
552
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil
553
+ end
554
+ end
555
+
556
+ def do_hookstart(command, type, domain)
557
+ if "#{PS_HOOK_START}" != "false"
558
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain start hook...\n\n") : nil
559
+ do_hook(command, type, domain, PS_HOOK_START)
560
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil
561
+ end
562
+ end
563
+
564
+ def do_hookstop(command, type, domain)
565
+ if "#{PS_HOOK_STOP}" != "false"
566
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain stop hook...\n\n") : nil
567
+ do_hook(command, type, domain, PS_HOOK_STOP)
568
+ "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil
569
+ end
570
+ end
571
+
572
+ def do_webprof_reload(domain)
573
+ puts "Reloading Web Profiles"
574
+
575
+ case "#{OS_CONST}"
576
+ when "linux"
577
+ "#{PS_PSA_DEBUG}" == "true" ? show_debug = true : show_debug = false
578
+
579
+ find_sites(domain).each do |s|
580
+ # set vars
581
+ url = "${ADMINSERVER_PROTOCOL?}://${ADMINSERVER_HOSTNAME?}:${ADMINSERVER_PORT?}/psp/#{s}/?cmd=login&"
582
+ src_env = ". ${PS_CFG_HOME?}/webserv/#{domain}/bin/setEnv.sh"
583
+ prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties"
584
+
585
+ # set reload in config.props
586
+ do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug)
587
+
588
+ # source setEnv and ping site
589
+ show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug)
590
+
591
+ # unset reload in config.props
592
+ do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug)
593
+
594
+ # done
595
+ puts " - #{s}"
596
+ end
597
+ when "windows"
598
+ puts "Windows support coming soon."
599
+ #do_cmd(". #{env('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh")
600
+
601
+ #find_sites.each do |s|
602
+ # # set vars
603
+ # prop_file = "#{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties"
604
+ # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&"
605
+ # # set reload in config.props
606
+ # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}")
607
+ # # ping site
608
+ # do_cmd("curl -s -o /dev/null '#{url}'")
609
+ # # unset reload in config.props
610
+ # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}")
611
+ # # done
612
+ # puts " - #{s}"
613
+ #end
614
+ else
615
+ puts " badOS - #{OS_CONST}"
616
+ end
617
+ puts ""
618
+ end
619
+
620
+ def os
621
+ @os ||= (
622
+ host_os = RbConfig::CONFIG['host_os']
623
+ case host_os
624
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
625
+ :windows
626
+ when /darwin|mac os/
627
+ :macosx
628
+ when /linux/
629
+ :linux
630
+ when /solaris|bsd/
631
+ :unix
632
+ else
633
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
634
+ end
635
+ )
636
+ end