psadmin_plus 2.0.1 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/psa +156 -130
  3. data/lib/psadmin_plus.rb +636 -522
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8056966af1d96cab37eef2b3d1ce8443d591e7a20fd19241c2b7c341ca8138d
4
- data.tar.gz: 0e1328ef04150ffdfb075d4f03a8fdd79bf0d93adb7a4a9c6f00c1787c48fb8d
3
+ metadata.gz: 5811dc395997ea722f4b5c15f2d6552e9c0c351ade9c64346a9007ea3d600f6b
4
+ data.tar.gz: 6785104563ac2b0cef79dce06bfc5980947c32bec12649bad37327b858fba4fa
5
5
  SHA512:
6
- metadata.gz: a9e9faa7ccd27456f442d6be195b9a1e6e90653f57f4f6dfd65534a23ade6f9174cd6d0d32a2eb6e9579cf07e436e3a8ceb88d6de01b725f5cf2d9abdf93b5b4
7
- data.tar.gz: 5b36b16f29c20c79d52756c1bd2cda3f4207826345087097716a42ea5e6dd72229ed28939bfc7b54c2f6f4b6e1abcf613800189aa9e15ef583978b4f46eab971
6
+ metadata.gz: cb1dcae5cbbbd435802ddb7a546c892af6a68c6b172297ceec562db30762cc07079bbdb3833ad1c9eaa52f787fc853f79d1a9d4dc0dfdffb0c74267e2d02711b
7
+ data.tar.gz: 01cef0fd3725cf5801df399f310bfc2e7eb9d7a940522a701978e71398a71e336e07f3976e20407413384205d340f83bc7691889476dae34131b469c32bfbcc5
data/bin/psa CHANGED
@@ -1,130 +1,156 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'psadmin_plus'
4
- #require_relative '../lib/psadmin_plus.rb'
5
-
6
- # options
7
- opts_c = ARGV.shift || "help"
8
- opts_t = ARGV.shift || "all"
9
- opts_d = ARGV.shift || "all"
10
- opt_cfg = ARGV.shift
11
-
12
- commands = opts_c.split(',')
13
- types = opts_t.split(',')
14
- domains = opts_d.split(',')
15
-
16
- if types.include? "all" then types = ['app','prcs','web'] end
17
- if domains.include? "all" then all_domains = true end
18
-
19
-
20
-
21
- # setup environment
22
- PS_PSA_CONF = ENV['PS_PSA_CONF'] || "#{ENV['HOME']}/.psa.conf"
23
- if File.exists?(PS_PSA_CONF) then
24
- File.readlines(PS_PSA_CONF).each do |line|
25
- if line.start_with? "#" then
26
- next
27
- else
28
- key, value = line.split "="
29
- ENV[key] = value.strip
30
- end
31
- end
32
- end
33
-
34
- # constants
35
- OS_CONST = os
36
- PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2"
37
- PS_POOL_MGMT = ENV['PS_POOL_MGMT'] || "on"
38
- PS_HEALTH_FILE = ENV['PS_HEALTH_FILE'] || "health.html"
39
- PS_HEALTH_TIME = ENV['PS_HEALTH_TIME'] || "60"
40
- PS_HEALTH_TEXT = ENV['PS_HEALTH_TEXT'] || "true"
41
- PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on"
42
- PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "cmd /c #{env('PS_HOME')}/appserv"
43
- PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false"
44
- PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false"
45
- PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false"
46
- PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false"
47
- PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "false"
48
-
49
- # validation
50
- # check runtime user
51
- if "#{OS_CONST}" == "linux" then
52
- if !system("id #{PS_RUNTIME_USER} &> /dev/null") then
53
- puts "#{PS_RUNTIME_USER} is not valid. Please correct PS_RUNTIME_USER, then try again."
54
- exit
55
- end
56
- else
57
- # windows - TODO
58
- end
59
-
60
- # process
61
- commands.each do |c|
62
- case "#{c}"
63
- when "help"
64
- do_help
65
- when "admin"
66
- do_admin
67
- when "util"
68
- do_util
69
- when "list"
70
- do_list
71
- when "summary"
72
- do_summary
73
- else
74
- types.each do |t|
75
- if all_domains then
76
- case "#{t}"
77
- when "app"
78
- domains = find_apps
79
- when "prcs"
80
- domains = find_prcss
81
- when "web"
82
- domains = find_webs
83
- end
84
- end
85
- domains.each do |d|
86
- case "#{c}"
87
- when "status"
88
- do_cmd_banner(c,t,d)
89
- do_status(t,d)
90
- when "start"
91
- do_cmd_banner(c,t,d)
92
- do_start(t,d)
93
- when "stop"
94
- do_cmd_banner(c,t,d)
95
- do_stop(t,d)
96
- when "kill"
97
- do_cmd_banner(c,t,d)
98
- do_kill(t,d)
99
- when "configure"
100
- do_cmd_banner(c,t,d)
101
- do_configure(t,d)
102
- when "purge"
103
- do_cmd_banner(c,t,d)
104
- do_purge(t,d)
105
- when "flush"
106
- do_cmd_banner(c,t,d)
107
- do_flush(t,d)
108
- when "restart"
109
- do_cmd_banner(c,t,d)
110
- do_restart(t,d)
111
- when "bounce"
112
- do_cmd_banner(c,t,d)
113
- do_bounce(t,d)
114
- when "pooladd"
115
- if t == "web"
116
- do_cmd_banner(c,t,d)
117
- do_pooladd(t,d)
118
- end
119
- when "poolrm"
120
- if t == "web"
121
- do_cmd_banner(c,t,d)
122
- do_poolrm(t,d)
123
- end
124
- else
125
- puts "Not a valid command. See psa help"
126
- end
127
- end
128
- end
129
- end
130
- 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,522 +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 " bounce stop, flush, purge, configure and start the domain"
22
- puts " kill force stop the domain"
23
- puts " configure configure the domain"
24
- puts " flush clear domain IPC"
25
- puts " poolrm remove domain from load balanced pool "
26
- puts " pooladd add domain to load balanced pool "
27
- puts " "
28
- puts "Types:"
29
- puts " "
30
- puts " app act on application domains"
31
- puts " prcs act on process scheduler domains"
32
- puts " web act on web domains"
33
- puts " all,<blank> act on all types of 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
- end
101
-
102
- def do_cmd_banner(c,t,d)
103
- puts ""
104
- puts "### #{c} - #{t} - #{d} ###"
105
- end
106
-
107
- def find_apps_nix
108
- case "#{PS_MULTI_HOME}"
109
- when "false"
110
- apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx",false).split(/\n+/)
111
- else
112
- apps = do_cmd("find #{PS_MULTI_HOME}/*/appserv/*/psappsrv.ubx",false).split(/\n+/)
113
- end
114
- apps.map! {|app| app.split("/")[-2]}
115
- end
116
-
117
- def find_prcss_nix
118
- case "#{PS_MULTI_HOME}"
119
- when "false"
120
- prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx",false).split(/\n+/)
121
- else
122
- prcss = do_cmd("find #{PS_MULTI_HOME}/*/appserv/prcs/*/psprcsrv.ubx",false).split(/\n+/)
123
- end
124
- prcss.map! {|prcs| prcs.split("/")[-2]}
125
- end
126
-
127
- def find_webs_nix
128
- case "#{PS_MULTI_HOME}"
129
- when "false"
130
- webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/)
131
- else
132
- webs = do_cmd("find #{PS_MULTI_HOME}/*/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/)
133
- end
134
- webs.map! {|web| web.split("/")[-2]}
135
- end
136
-
137
- def find_apps_win
138
- case "#{PS_MULTI_HOME}"
139
- when "false"
140
- apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
141
- else
142
- apps = do_cmd("(get-childitem #{PS_MULTI_HOME}/*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
143
- end
144
- apps.map! {|app| app.split('\\')[-2]}
145
- end
146
-
147
- def find_prcss_win
148
- case "#{PS_MULTI_HOME}"
149
- when "false"
150
- prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
151
- else
152
- prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}/*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
153
- end
154
- prcss.map! {|prcs| prcs.split("\\")[-2]}
155
- end
156
-
157
- def find_webs_win
158
- case "#{PS_MULTI_HOME}"
159
- when "false"
160
- webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
161
- else
162
- webs = do_cmd("(get-childitem #{PS_MULTI_HOME}/*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/)
163
- end
164
- webs.map! {|web| web.split("\\")[-2]}
165
- end
166
-
167
- def find_apps
168
- apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win
169
- end
170
-
171
- def find_prcss
172
- prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win
173
- end
174
-
175
- def find_webs
176
- webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win
177
- end
178
-
179
- def do_util
180
- puts "TODO: util"
181
- end
182
-
183
- def do_admin
184
- do_cmd("#{PS_PSADMIN_PATH}/psadmin")
185
- end
186
-
187
- def do_list
188
- puts "---"
189
- print "hostname: " ; do_cmd('hostname')
190
- print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'))
191
- if PS_MULTI_HOME == "false"
192
- print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'))
193
- end
194
- puts ""
195
- puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}"
196
- puts "PS_PSA_SUDO: #{PS_PSA_SUDO}"
197
- puts "PS_POOL_MGMT: #{PS_POOL_MGMT}"
198
- puts "PS_HEALTH_FILE: #{PS_HEALTH_FILE}"
199
- puts "PS_HEALTH_TIME: #{PS_HEALTH_TIME}"
200
- puts "PS_HEALTH_TEXT: #{PS_HEALTH_TEXT}"
201
- puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}"
202
- puts "PS_MULT_HOME: #{PS_MULTI_HOME}"
203
- puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}"
204
- puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}"
205
- puts ""
206
- puts "app:"
207
- find_apps.each do |a|
208
- puts " - #{a}"
209
- end
210
- puts ""
211
- puts "prcs:"
212
- find_prcss.each do |p|
213
- puts " - #{p}"
214
- end
215
- puts ""
216
- puts "web:"
217
- find_webs.each do |w|
218
- puts " - #{w}"
219
- end
220
- puts ""
221
- end
222
-
223
- def do_summary
224
- if "#{PS_MULTI_HOME}" != "false"
225
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
226
- end
227
-
228
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary")
229
- #do_status("web","all")
230
- end
231
-
232
- def do_status(type, domain)
233
- if "#{PS_MULTI_HOME}" != "false"
234
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
235
- end
236
-
237
- case type
238
- when "app"
239
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}")
240
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}")
241
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}")
242
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}")
243
- when "prcs"
244
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}")
245
- when "web"
246
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}")
247
- else
248
- puts "Invalid type, see psa help"
249
- end
250
- end
251
-
252
- def do_start(type, domain)
253
- if "#{PS_MULTI_HOME}" != "false"
254
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
255
- end
256
-
257
- web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*"
258
- app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*"
259
- prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*"
260
-
261
- case "#{PS_PARALLEL_BOOT}"
262
- when "false"
263
- start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}"
264
- when "true"
265
- start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}"
266
- end
267
- start_app_service_cmd = "start-service #{app_service_name}"
268
- start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}"
269
- start_prcs_service_cmd = "start-service #{prcs_service_name}"
270
- start_web_cmd = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}"
271
- start_web_service_cmd = "start-service #{web_service_name}"
272
-
273
- case type
274
- when "app"
275
- case "#{PS_WIN_SERVICES}"
276
- when "tux", "app", "all"
277
- do_cmd(start_app_service_cmd)
278
- else
279
- do_cmd(start_app_cmd)
280
- case "#{PS_TRAIL_SERVICE}"
281
- when "true"
282
- do_cmd(start_app_service_cmd)
283
- end
284
- end
285
- when "prcs"
286
- case "#{PS_WIN_SERVICES}"
287
- when "tux", "prcs", "all"
288
- do_cmd(start_prcs_service_cmd)
289
- else
290
- do_cmd(start_prcs_cmd)
291
- case "#{PS_TRAIL_SERVICE}"
292
- when "true"
293
- do_cmd(start_prcs_service_cmd)
294
- end
295
- end
296
- when "web"
297
- case "#{OS_CONST}"
298
- when "linux"
299
- do_cmd(start_web_cmd)
300
- when "windows"
301
- case "#{PS_WIN_SERVICES}"
302
- when "web", "all"
303
- do_cmd(start_web_service_cmd)
304
- else
305
- # Run command outside of powershell with 'false' parameter
306
- do_cmd(start_web_cmd, true, false)
307
- case "#{PS_TRAIL_SERVICE}"
308
- when "true"
309
- do_cmd(start_web_service_cmd)
310
- end
311
- end
312
- end
313
- do_pooladd(type,domain)
314
- else
315
- puts "Invalid type, see psa help"
316
- end
317
- end
318
-
319
- def do_stop(type, domain)
320
- if "#{PS_MULTI_HOME}" != "false"
321
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
322
- end
323
-
324
- web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*"
325
- app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*"
326
- prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*"
327
-
328
- stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}"
329
- stop_app_service_cmd = "stop-service #{app_service_name}"
330
- stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}"
331
- stop_prcs_service_cmd = "stop-service #{prcs_service_name}"
332
- stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh"
333
- stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}"
334
- stop_web_service_cmd = "stop-service #{web_service_name}"
335
-
336
- case type
337
- when "app"
338
- case "#{PS_WIN_SERVICES}"
339
- when "true"
340
- do_cmd(stop_app_service_cmd)
341
- else
342
- do_cmd(stop_app_cmd)
343
- case "#{PS_TRAIL_SERVICE}"
344
- when "true"
345
- do_cmd(stop_app_service_cmd)
346
- end
347
- end
348
- when "prcs"
349
- case "#{PS_WIN_SERVICES}"
350
- when "true"
351
- do_cmd(stop_prcs_service_cmd)
352
- else
353
- do_cmd(stop_prcs_cmd)
354
- case "#{PS_TRAIL_SERVICE}"
355
- when "true"
356
- do_cmd(stop_prcs_service_cmd)
357
- end
358
- end
359
- when "web"
360
- do_poolrm(type,domain)
361
- case "#{OS_CONST}"
362
- when "linux"
363
- do_cmd(stop_web_cmd_lnx)
364
- when "windows"
365
- case "#{PS_WIN_SERVICES}"
366
- when "true"
367
- do_cmd(stop_web_service_cmd)
368
- else
369
- do_cmd(stop_web_cmd_win, true, false)
370
- case "#{PS_TRAIL_SERVICE}"
371
- when "true"
372
- do_cmd(stop_web_service_cmd)
373
- end
374
- end
375
- end
376
- else
377
- puts "Invalid type, see psa help"
378
- end
379
- end
380
-
381
- def do_kill(type, domain)
382
- if "#{PS_MULTI_HOME}" != "false"
383
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
384
- end
385
-
386
- case type
387
- when "app"
388
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}")
389
- when "prcs"
390
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}")
391
- when "web"
392
- case "#{OS_CONST}"
393
- when "windows"
394
- do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue")
395
- when "linux"
396
- return #kill n/a
397
- end
398
- else
399
- puts "Invalid type, see psa help"
400
- end
401
- end
402
-
403
- def do_configure(type, domain)
404
- if "#{PS_MULTI_HOME}" != "false"
405
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
406
- end
407
-
408
- case type
409
- when "app"
410
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}")
411
- when "prcs"
412
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}")
413
- when "web"
414
- return # web configure n/a
415
- else
416
- puts "Invalid type, see psa help"
417
- end
418
- end
419
-
420
- def do_purge(type, domain)
421
- if "#{PS_MULTI_HOME}" != "false"
422
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
423
- end
424
-
425
- case type
426
- when "app"
427
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}")
428
- when "prcs"
429
- do_cmd("echo purge todo")
430
- when "web"
431
- case "#{OS_CONST}"
432
- when "linux"
433
- do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/")
434
- puts "web cache purged"
435
- when "windows"
436
- do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\'))
437
- end
438
- else
439
- puts "Invalid type, see psa help"
440
- end
441
- end
442
-
443
- def do_flush(type, domain)
444
- if "#{PS_MULTI_HOME}" != "false"
445
- ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}/#{domain}"
446
- end
447
-
448
- case type
449
- when "app"
450
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}")
451
- when "prcs"
452
- do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}")
453
- when "web"
454
- return # web flush n/a
455
- else
456
- puts "Invalid type, see psa help"
457
- end
458
- end
459
-
460
- def do_restart(type, domain)
461
- do_stop(type, domain)
462
- do_start(type, domain)
463
- end
464
-
465
- def do_bounce(type, domain)
466
- do_stop(type, domain)
467
- do_purge(type, domain)
468
- do_flush(type, domain)
469
- do_configure(type, domain)
470
- do_start(type, domain)
471
- end
472
-
473
- def do_pooladd(type, domain)
474
- if PS_POOL_MGMT == "on" then
475
- # Change PS_HEALTH_TEXT and PS_HEALTH_FILE variables to match your system
476
- puts "Adding web domain to load balanced pool..."
477
- do_cmd("echo '#{PS_HEALTH_TEXT}' > #{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/#{PS_HEALTH_FILE}")
478
- sleep(PS_HEALTH_TIME.to_i)
479
- puts "...domain added to pool."
480
- puts ""
481
- else
482
- puts "Skipping pool managment. To enable, set PS_POOL_MGMT to 'on'."
483
- end
484
- end
485
-
486
- def do_poolrm(type,domain)
487
- if PS_POOL_MGMT == "on" then
488
- # Change PS_HEALTH_TEXT and PS_HEALTH_FILE variables to match your system
489
- puts "Removing domain from load balanced pool..."
490
- case "#{OS_CONST}"
491
- when "linux"
492
- do_cmd("rm -f #{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/#{PS_HEALTH_FILE}")
493
- when "windows"
494
- do_cmd("remove-item -force #{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/#{PS_HEALTH_FILE} -ErrorAction SilentlyContinue")
495
- else
496
- puts " badOS - #{OS_CONST}"
497
- end
498
- sleep(PS_HEALTH_TIME.to_i)
499
- puts "...domain removed from pool."
500
- puts ""
501
- else
502
- puts "Skipping pool managment. To enable, set PS_POOL_MGMT to 'on'."
503
- end
504
- end
505
-
506
- def os
507
- @os ||= (
508
- host_os = RbConfig::CONFIG['host_os']
509
- case host_os
510
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
511
- :windows
512
- when /darwin|mac os/
513
- :macosx
514
- when /linux/
515
- :linux
516
- when /solaris|bsd/
517
- :unix
518
- else
519
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
520
- end
521
- )
522
- 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