From 41933f50a81cc6041c6fbae711a43657e93663ac Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 7 Jun 2023 17:08:41 -0500 Subject: [PATCH 001/168] drafting psc/pq tux options --- bin/psa | 7 ++++++- lib/psadmin_plus.rb | 11 +++++++++-- psadmin_plus.gemspec | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bin/psa b/bin/psa index d594182..d87f8d7 100755 --- a/bin/psa +++ b/bin/psa @@ -11,6 +11,7 @@ end opts_c = ARGV.shift || "help" opts_t = ARGV.shift || "all" opts_d = ARGV.shift || "all" +opts_s = ARGV.shift || "all" # Set remaining arguments as environment variables ARGV.each do |arg| if arg.include? "=" @@ -25,9 +26,11 @@ end commands = opts_c.split(',') types = opts_t.split(',') domains = opts_d.split(',') +statuses = opts_s.split(',') if types.include? "all" then types = ['app','prcs','web'] end if domains.include? "all" then all_domains = true end +if statuses.include? "all" then tuxcmd = ['psr', 'pq'] end # setup environment PS_PSA_CONF = ENV['PS_PSA_CONF'] || "#{ENV['HOME']}/.psa.conf" @@ -90,6 +93,8 @@ commands.each do |c| case "#{t}" when "app" valid_domains = find_apps + when "tux" + valid_domains = find_apps when "pubsub" valid_domains = find_apps # TODO - find only apps with PUBSUB enabled? when "prcs" @@ -111,7 +116,7 @@ commands.each do |c| case "#{c}" when "status" do_cmd_banner(c,t,d) - do_status(t,d) + do_status(t,d, tuxcmd) when "start" do_cmd_banner(c,t,d) do_start(t,d) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 75aee26..7cc6f8c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -28,6 +28,7 @@ def do_help puts " " puts " app act on application domains" #puts " pubsub act on PUBSUB group of application domains" + puts " tux act on tuxedo domain (status only: psr, pq)" puts " prcs act on process scheduler domains" puts " web act on web domains" puts " all, act on web, app, and prcs domains" @@ -283,7 +284,7 @@ def do_summary #do_status("web","all") end -def do_status(type, domain) +def do_status(type, domain, tuxcmd) case type when "app" do_psadmin_check ? nil : return @@ -291,9 +292,15 @@ def do_status(type, domain) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") + when "tux" + ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + tuxcmd.each do |cmd| + do_cmd("echo #{cmd} | #{ENV['TUXDIR']}/bin/tmadmin -r | grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"$(date '+%Y-%m-%d %H:%M:%S')\" \"$line\"; done") + end when "pubsub" + do_psadmin_check ? nil : return ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'printserver -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + do_cmd("echo printserver -g PUBSUB | #{ENV['TUXDIR']}/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") diff --git a/psadmin_plus.gemspec b/psadmin_plus.gemspec index ee61fab..223ab9f 100644 --- a/psadmin_plus.gemspec +++ b/psadmin_plus.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'psadmin_plus' - s.version = '2.0.5' - s.date = '2021-04-26' + s.version = '2.0.7' + s.date = '2023-06-07' s.summary = "psadmin plus" s.description = "A psadmin helper tool" s.authors = ["Kyle Benson", "Dan Iverson"] From e705887edba86a8cfd4382843b0f924518628836 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 8 Jun 2023 00:14:30 -0500 Subject: [PATCH 002/168] Testing different command options --- lib/psadmin_plus.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 7cc6f8c..6558f63 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -27,17 +27,22 @@ def do_help puts "Types:" puts " " puts " app act on application domains" - #puts " pubsub act on PUBSUB group of application domains" - puts " tux act on tuxedo domain (status only: psr, pq)" puts " prcs act on process scheduler domains" puts " web act on web domains" puts " all, act on web, app, and prcs domains" + puts " pubsub act on PUBSUB group of application domains (status only)" + puts " tux act on tuxedo domain (status only)" puts " " puts "Domains:" puts " " puts " dom act on specific domains" puts " all, act on all domains" puts " " + puts "Tux Status Options" + puts " " + puts " psr print server status" + puts " pq print queue status" + puts " " puts "Each parameter type can be enter in a comma separated list " puts " " end @@ -293,14 +298,14 @@ def do_status(type, domain, tuxcmd) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" tuxcmd.each do |cmd| - do_cmd("echo #{cmd} | #{ENV['TUXDIR']}/bin/tmadmin -r | grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"$(date '+%Y-%m-%d %H:%M:%S')\" \"$line\"; done") + do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r | grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"$(date '+%Y-%m-%d %H:%M:%S')\" \"$line\"; done") end when "pubsub" do_psadmin_check ? nil : return - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo printserver -g PUBSUB | #{ENV['TUXDIR']}/bin/tmadmin -r") + ENV['TUXCONFIG'] = env'PS_CFG_HOME') + " /appserv/#{domain}/PSTUXCFG" + do_cmd("echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") From fa96104f2f0d75dba272608df202db15e0cd7353 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 8 Jun 2023 00:15:53 -0500 Subject: [PATCH 003/168] Fix typo --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 6558f63..7b328fd 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -304,7 +304,7 @@ def do_status(type, domain, tuxcmd) end when "pubsub" do_psadmin_check ? nil : return - ENV['TUXCONFIG'] = env'PS_CFG_HOME') + " /appserv/#{domain}/PSTUXCFG" + ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" do_cmd("echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return From bc18efe3069501a94a2ecb682da993460f19343f Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 8 Jun 2023 00:17:03 -0500 Subject: [PATCH 004/168] Fix typo --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 7b328fd..33e384b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -300,7 +300,7 @@ def do_status(type, domain, tuxcmd) when "tux" ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" tuxcmd.each do |cmd| - do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r | grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"$(date '+%Y-%m-%d %H:%M:%S')\" \"$line\"; done") + do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r | grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") end when "pubsub" do_psadmin_check ? nil : return From bf6aa23c69e78f3d3ae748d56594a81afbeca3f0 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 09:59:00 -0500 Subject: [PATCH 005/168] Capture output for processing in ruby --- lib/psadmin_plus.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 33e384b..c9e1155 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -300,7 +300,8 @@ def do_status(type, domain, tuxcmd) when "tux" ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" tuxcmd.each do |cmd| - do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r | grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") + output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") + p output end when "pubsub" do_psadmin_check ? nil : return From cf74566a10dbf2fc7e79155283991e95b3b43b16 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 10:10:07 -0500 Subject: [PATCH 006/168] Setting TUXCONFIG inline --- lib/psadmin_plus.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index c9e1155..4eb48e1 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -298,15 +298,16 @@ def do_status(type, domain, tuxcmd) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" - ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" tuxcmd.each do |cmd| - output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") + # output = do_cmd(ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" + # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") + output = do_cmd("#{env('TUXCONFIG')} = #{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") p output end when "pubsub" do_psadmin_check ? nil : return - ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" - do_cmd("echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + # ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" + do_cmd("#{env('TUXCONFIG')} = #{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") From a37cebe1de78232ec367ac31143f6d4dba8d4d09 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 10:14:45 -0500 Subject: [PATCH 007/168] exporting PSTUXCONFIG --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4eb48e1..7f6d251 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -301,13 +301,13 @@ def do_status(type, domain, tuxcmd) tuxcmd.each do |cmd| # output = do_cmd(ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") - output = do_cmd("#{env('TUXCONFIG')} = #{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") + output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") p output end when "pubsub" do_psadmin_check ? nil : return # ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" - do_cmd("#{env('TUXCONFIG')} = #{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") From 0c3c9516084bc7bc527561ca842e734a5e65fc6b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:06:25 -0500 Subject: [PATCH 008/168] Prefix tux output with timestamp --- lib/psadmin_plus.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 7f6d251..4bec7be 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -302,7 +302,9 @@ def do_status(type, domain, tuxcmd) # output = do_cmd(ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") - p output + output.each do | line | + p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line + end end when "pubsub" do_psadmin_check ? nil : return From df28e664ee859e675c4ce091aeccddb496e6d5e4 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:07:54 -0500 Subject: [PATCH 009/168] Split newlines --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4bec7be..0653c0b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -302,7 +302,7 @@ def do_status(type, domain, tuxcmd) # output = do_cmd(ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") - output.each do | line | + output.split ('\n').each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line end end From 2f54afc87cfda74593ad55fed92be61e5b7bc596 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:11:24 -0500 Subject: [PATCH 010/168] Create array from string --- lib/psadmin_plus.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0653c0b..fc3b16f 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -302,7 +302,9 @@ def do_status(type, domain, tuxcmd) # output = do_cmd(ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") - output.split ('\n').each do | line | + # output.split ('\n').each do | line | + copyright, rights, license, trademark, *lines = ex.split('\n') + lines.each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line end end From 5fab0f5b9b543c7865865f8888e9d814cb4358e4 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:11:58 -0500 Subject: [PATCH 011/168] Fix typo --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index fc3b16f..8f0bb0e 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -303,7 +303,7 @@ def do_status(type, domain, tuxcmd) # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") # output.split ('\n').each do | line | - copyright, rights, license, trademark, *lines = ex.split('\n') + copyright, rights, license, trademark, *lines = output.split('\n') lines.each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line end From fcc3453b1f4b9543b9d480fe415514eac63ef3c4 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:13:01 -0500 Subject: [PATCH 012/168] Testing line array --- lib/psadmin_plus.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 8f0bb0e..53b357c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -304,6 +304,7 @@ def do_status(type, domain, tuxcmd) output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") # output.split ('\n').each do | line | copyright, rights, license, trademark, *lines = output.split('\n') + p "Lines: " + lines.to_s lines.each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line end From 8d81348503333c8e1e2363fccb588db414fc9bd5 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:15:02 -0500 Subject: [PATCH 013/168] Capture only first line --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 53b357c..ad1c3cc 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -303,7 +303,7 @@ def do_status(type, domain, tuxcmd) # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") # output.split ('\n').each do | line | - copyright, rights, license, trademark, *lines = output.split('\n') + *lines = output.split('\n') p "Lines: " + lines.to_s lines.each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line From d5500d9940da2af55e4940aac64753762406d6c7 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:16:19 -0500 Subject: [PATCH 014/168] Test line object --- lib/psadmin_plus.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index ad1c3cc..613685e 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -305,6 +305,7 @@ def do_status(type, domain, tuxcmd) # output.split ('\n').each do | line | *lines = output.split('\n') p "Lines: " + lines.to_s + p "Lines object " + lines.type lines.each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line end From 3d8a12ccd0897900c95812fa4eb68d3b170eb9aa Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:37:49 -0500 Subject: [PATCH 015/168] Correctly splitting new lines --- lib/psadmin_plus.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 613685e..e4c43ba 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -303,9 +303,8 @@ def do_status(type, domain, tuxcmd) # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") # output.split ('\n').each do | line | - *lines = output.split('\n') + *lines = output.split(/\n/) p "Lines: " + lines.to_s - p "Lines object " + lines.type lines.each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line end From 823e5e8c339dfd6dcbc6d7bc5a62b8804d54072c Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:48:32 -0500 Subject: [PATCH 016/168] Breaking things by trying Open3.capture3 for timestamps --- bin/psa | 1 + lib/psadmin_plus.rb | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bin/psa b/bin/psa index d87f8d7..c8a508a 100755 --- a/bin/psa +++ b/bin/psa @@ -62,6 +62,7 @@ PS_MULTI_DELIMIT = ENV['PS_MULTI_DELIMIT'] || "/" PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0 PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "false" +PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" # validation # check runtime user diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index e4c43ba..45167b5 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -74,7 +74,7 @@ def do_cmd(cmd, print = true, powershell = true) when "true" p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" end - out = `sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'` + stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") else print "#{PS_RUNTIME_USER} " case "#{PS_PSA_DEBUG}" @@ -102,8 +102,16 @@ def do_cmd(cmd, print = true, powershell = true) else out = "Invalid OS" end - print ? (puts out) : result = out - out + case "#{PS_PSA_TIMESTAMP}" + when "false" + print ? (puts stdout) : result = stdout + stdout + when "true" + *lines = stdout.split(/\n/) + lines[0...-2].each do | line | + p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line + end + end end def do_cmd_banner(c,t,d) @@ -299,15 +307,11 @@ def do_status(type, domain, tuxcmd) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" tuxcmd.each do |cmd| - # output = do_cmd(ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" - # output = do_cmd("echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") #| grep PS | while IFS= read -r line; do printf '[%s] %s\n' \"\$\(date '+%Y-%m-%d %H:%M:%S'\)\" \"\$line\"; done") output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") - # output.split ('\n').each do | line | - *lines = output.split(/\n/) - p "Lines: " + lines.to_s - lines.each do | line | - p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line - end + # space, header, divider, *lines = output.split(/\n/) + # lines[0...-2].each do | line | + # p Time.now.strftime("[%Y-%m-%d %H:%M:%S]") + " #{cmd} " + line + # end end when "pubsub" do_psadmin_check ? nil : return From f6483ee178f40b959b5df02573bac6f3f0380182 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:56:22 -0500 Subject: [PATCH 017/168] Hiding timestamps for internal calls --- lib/psadmin_plus.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 45167b5..eea02b7 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -59,7 +59,7 @@ def env(var) result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" end -def do_cmd(cmd, print = true, powershell = true) +def do_cmd(cmd, print = true, powershell = true, timestamp = "no") case "#{OS_CONST}" when "linux" if do_is_runtime_user_nix @@ -102,16 +102,25 @@ def do_cmd(cmd, print = true, powershell = true) else out = "Invalid OS" end + + # Handle Output - Check if timestamps are requested - override if parameter is "off" case "#{PS_PSA_TIMESTAMP}" - when "false" + when "true" + if timestamp != "off" + timestamp = "on" + end + end + + if timestamp == "off" || timestamp == "no" print ? (puts stdout) : result = stdout stdout - when "true" + else *lines = stdout.split(/\n/) lines[0...-2].each do | line | p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line end end + end def do_cmd_banner(c,t,d) @@ -134,7 +143,7 @@ def do_set_cfg_home(d) def find_apps_nix case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false).split(/\n+/) + apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) else apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false).split(/\n+/) end From 499eee42f536a086b74c7726f32b1fb7d5e867d6 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 11:57:56 -0500 Subject: [PATCH 018/168] Remove quotes --- lib/psadmin_plus.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index eea02b7..0758d20 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -117,7 +117,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") else *lines = stdout.split(/\n/) lines[0...-2].each do | line | - p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line + p (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).delete_prefix('"').delete_suffix('"') end end @@ -145,7 +145,7 @@ def find_apps_nix when "false" apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) else - apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false).split(/\n+/) + apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) end apps.map! {|app| app.split("/")[-2]} end @@ -153,9 +153,9 @@ def find_apps_nix def find_prcss_nix case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false).split(/\n+/) + prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) else - prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false).split(/\n+/) + prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) end prcss.map! {|prcs| prcs.split("/")[-2]} end @@ -163,24 +163,24 @@ def find_prcss_nix def find_webs_nix case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/) + webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"off").split(/\n+/) else - webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false).split(/\n+/) + webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"off").split(/\n+/) end webs.map! {|web| web.split("/")[-2]} end def find_sites_nix(domain) - webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false).split(/\n+/) + webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"off").split(/\n+/) webs.map! {|site| site.split("/")[-1]} end def find_apps_win case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/) + apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) else - 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+/) + apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) end apps.map! {|app| app.split('\\')[-2]} end @@ -188,9 +188,9 @@ def find_apps_win def find_prcss_win case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/) + prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) else - 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+/) + prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) end prcss.map! {|prcs| prcs.split("\\")[-2]} end @@ -198,9 +198,9 @@ def find_prcss_win def find_webs_win case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/) + webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) else - webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false).split(/\n+/) + webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) end webs.map! {|web| web.split("\\")[-2]} end From a80e3d2d1dbb593ae3bd6a555048cb79e2905fb5 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:02:41 -0500 Subject: [PATCH 019/168] Checking for empty lines --- lib/psadmin_plus.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0758d20..4c493fb 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -117,7 +117,9 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") else *lines = stdout.split(/\n/) lines[0...-2].each do | line | - p (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).delete_prefix('"').delete_suffix('"') + if !line.empty? + (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).delete_prefix('"').delete_suffix('"') + end end end From e785cf4f6b3d6039518b599e579bdd05f1abe302 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:04:38 -0500 Subject: [PATCH 020/168] Add timestamp to banner --- lib/psadmin_plus.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4c493fb..91256f6 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -126,9 +126,13 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") end def do_cmd_banner(c,t,d) - puts "" - puts "===[ #{c} . #{t} . #{d} ]===" - puts "" + if "#{PS_PSA_TIMESTAMP}" == "true" + puts "Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + ===[ #{c} . #{t} . #{d} ]===" + else + puts "" + puts "===[ #{c} . #{t} . #{d} ]===" + puts "" + end end def do_set_cfg_home(d) From cfd5f492d72cac756ef531912159b48cf75d9087 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:05:21 -0500 Subject: [PATCH 021/168] Fix banner timestamp --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 91256f6..0651bb2 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -127,7 +127,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") def do_cmd_banner(c,t,d) if "#{PS_PSA_TIMESTAMP}" == "true" - puts "Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + ===[ #{c} . #{t} . #{d} ]===" + puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" else puts "" puts "===[ #{c} . #{t} . #{d} ]===" From fe4390e72ce32b35d04c123eefbf18251c48b822 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:06:46 -0500 Subject: [PATCH 022/168] Remove > lines --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0651bb2..4055bd7 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -117,7 +117,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") else *lines = stdout.split(/\n/) lines[0...-2].each do | line | - if !line.empty? + if !line.empty? || line != '> ' (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).delete_prefix('"').delete_suffix('"') end end From d2cb0231451d0de26440f49891e446b40854f720 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:07:34 -0500 Subject: [PATCH 023/168] Remove > lines --- lib/psadmin_plus.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4055bd7..1300d53 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -117,8 +117,10 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") else *lines = stdout.split(/\n/) lines[0...-2].each do | line | - if !line.empty? || line != '> ' - (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).delete_prefix('"').delete_suffix('"') + if !line.empty? + if line != '> ' + (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).delete_prefix('"').delete_suffix('"') + end end end end From e2b01ae1054ccedcc7e2e49e190303b4556c2f97 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:08:31 -0500 Subject: [PATCH 024/168] Using chomp to remove quotes --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 1300d53..33d3d62 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -119,7 +119,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") lines[0...-2].each do | line | if !line.empty? if line != '> ' - (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).delete_prefix('"').delete_suffix('"') + (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).rchomp('"').chomp('"') end end end From d3482263c246ab787be4a34b3f26831a475dbcc7 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:10:06 -0500 Subject: [PATCH 025/168] Using tr to remove quotes --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 33d3d62..bea5f8b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -119,7 +119,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") lines[0...-2].each do | line | if !line.empty? if line != '> ' - (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).rchomp('"').chomp('"') + (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).tr('"', '') end end end From 28ea60b355ecb7888ba2486896b488d08affd99a Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:12:27 -0500 Subject: [PATCH 026/168] Using tr to remove quotes --- lib/psadmin_plus.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index bea5f8b..8d20b50 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -119,7 +119,8 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") lines[0...-2].each do | line | if !line.empty? if line != '> ' - (p Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).tr('"', '') + output = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line + p output.tr('"', '') end end end From 4845661bee115d7a37a9d0d4f4b5b8b557c8154e Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:13:40 -0500 Subject: [PATCH 027/168] Using gsub to remove quotes --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 8d20b50..f2ada10 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -120,7 +120,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") if !line.empty? if line != '> ' output = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line - p output.tr('"', '') + p output.to_s.gsub('"', '') end end end From 4a67cdd39c6e643b69a4ca5e4c5c80c41cd41870 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:48:54 -0500 Subject: [PATCH 028/168] Moving output handling to it's own method --- lib/psadmin_plus.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f2ada10..1a2d3bc 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -103,7 +103,8 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") out = "Invalid OS" end - # Handle Output - Check if timestamps are requested - override if parameter is "off" + # Handle Output - Check if timestamps are requested + # - override if parameter is "off" for internal calls case "#{PS_PSA_TIMESTAMP}" when "true" if timestamp != "off" @@ -117,17 +118,20 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") else *lines = stdout.split(/\n/) lines[0...-2].each do | line | - if !line.empty? - if line != '> ' - output = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line - p output.to_s.gsub('"', '') - end - end + do_output(line) end end end +def do_output(line) + if !line.empty? + if line != '> ' + puts (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).gsub('"', '') + end + end +end + def do_cmd_banner(c,t,d) if "#{PS_PSA_TIMESTAMP}" == "true" puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" From 9cd638b381d32444331d5fe39ca1e62473145f26 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:51:45 -0500 Subject: [PATCH 029/168] Trying merged stdout/sterr --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 1a2d3bc..d8a546b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -74,7 +74,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") when "true" p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" end - stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + stdout, status = Open3.capture2e("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") else print "#{PS_RUNTIME_USER} " case "#{PS_PSA_DEBUG}" From fce2a873df9ebdd4b103750d4ad849231375bd19 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:53:29 -0500 Subject: [PATCH 030/168] Testing additional logging for each line --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index d8a546b..016e3b7 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -127,7 +127,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") def do_output(line) if !line.empty? if line != '> ' - puts (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).gsub('"', '') + puts (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "#{c} . #{t} . #{d} " + line).gsub('"', '') end end end From a8fd1c44a9cacddd7162677baa564b87e6d6e527 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 12:55:13 -0500 Subject: [PATCH 031/168] Removing test logging --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 016e3b7..001df6a 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -127,7 +127,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") def do_output(line) if !line.empty? if line != '> ' - puts (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "#{c} . #{t} . #{d} " + line).gsub('"', '') + puts (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).gsub('"', '') end end end From 83e1fc91f45186f6f91412744bb2a1bab26d14e2 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 22:59:44 -0500 Subject: [PATCH 032/168] Simplify timestamp code --- lib/psadmin_plus.rb | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 001df6a..3d31739 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -59,7 +59,7 @@ def env(var) result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" end -def do_cmd(cmd, print = true, powershell = true, timestamp = "no") +def do_cmd(cmd, print = true, powershell = true, timestamp = nil) case "#{OS_CONST}" when "linux" if do_is_runtime_user_nix @@ -74,7 +74,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") when "true" p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" end - stdout, status = Open3.capture2e("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") else print "#{PS_RUNTIME_USER} " case "#{PS_PSA_DEBUG}" @@ -103,31 +103,28 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = "no") out = "Invalid OS" end + *lines = stdout.split(/\n/) + lines[0...-2].each do | line | + do_output(line, timestamp) + end + +end + +def do_output(line, timestamp = nil) + + utctime = "" # Handle Output - Check if timestamps are requested # - override if parameter is "off" for internal calls case "#{PS_PSA_TIMESTAMP}" when "true" if timestamp != "off" - timestamp = "on" - end - end - - if timestamp == "off" || timestamp == "no" - print ? (puts stdout) : result = stdout - stdout - else - *lines = stdout.split(/\n/) - lines[0...-2].each do | line | - do_output(line) + utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") end end - -end - -def do_output(line) + if !line.empty? if line != '> ' - puts (Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + line).gsub('"', '') + puts (utctime + line).gsub('"', '') end end end From 8a523d5563855b63cd9937df214b3e3f66db6369 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 23:03:06 -0500 Subject: [PATCH 033/168] Don't process internal call stdout --- lib/psadmin_plus.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 3d31739..bfc8ecf 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -103,9 +103,14 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) out = "Invalid OS" end - *lines = stdout.split(/\n/) - lines[0...-2].each do | line | - do_output(line, timestamp) + if timestamp == "off" + stdout + else + *lines = stdout.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp) + end end end From dc902877d19b475b281fe66d4a14e1c91af4ff63 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 23:09:11 -0500 Subject: [PATCH 034/168] Forcing tux opts to an array --- bin/psa | 8 ++++---- lib/psadmin_plus.rb | 12 ++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bin/psa b/bin/psa index c8a508a..1c5f962 100755 --- a/bin/psa +++ b/bin/psa @@ -11,7 +11,7 @@ end opts_c = ARGV.shift || "help" opts_t = ARGV.shift || "all" opts_d = ARGV.shift || "all" -opts_s = ARGV.shift || "all" +*opts_s = ARGV.shift || "all" # Set remaining arguments as environment variables ARGV.each do |arg| if arg.include? "=" @@ -26,11 +26,11 @@ end commands = opts_c.split(',') types = opts_t.split(',') domains = opts_d.split(',') -statuses = opts_s.split(',') +*statuses = opts_s.split(',') if types.include? "all" then types = ['app','prcs','web'] end if domains.include? "all" then all_domains = true end -if statuses.include? "all" then tuxcmd = ['psr', 'pq'] end +if statuses.include? "all" then opts = ['psr', 'pq'] end # setup environment PS_PSA_CONF = ENV['PS_PSA_CONF'] || "#{ENV['HOME']}/.psa.conf" @@ -117,7 +117,7 @@ commands.each do |c| case "#{c}" when "status" do_cmd_banner(c,t,d) - do_status(t,d, tuxcmd) + do_status(t,d, opts) when "start" do_cmd_banner(c,t,d) do_start(t,d) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index bfc8ecf..518e3ef 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -321,7 +321,7 @@ def do_summary #do_status("web","all") end -def do_status(type, domain, tuxcmd) +def do_status(type, domain, opts) case type when "app" do_psadmin_check ? nil : return @@ -330,16 +330,12 @@ def do_status(type, domain, tuxcmd) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" - tuxcmd.each do |cmd| - output = do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") - # space, header, divider, *lines = output.split(/\n/) - # lines[0...-2].each do | line | - # p Time.now.strftime("[%Y-%m-%d %H:%M:%S]") + " #{cmd} " + line - # end + opts.each do |cmd| + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") end when "pubsub" do_psadmin_check ? nil : return - # ENV['TUXCONFIG'] = env('PS_CFG_HOME') + "/appserv/#{domain}/PSTUXCFG" do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return From e9c72dd6ea09a5e31ef9b0d510a2359f37c52053 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 23:11:14 -0500 Subject: [PATCH 035/168] Forcing tux opts to an array --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index 1c5f962..f2063f7 100755 --- a/bin/psa +++ b/bin/psa @@ -26,7 +26,7 @@ end commands = opts_c.split(',') types = opts_t.split(',') domains = opts_d.split(',') -*statuses = opts_s.split(',') +*statuses = opts_s[0].split(',') if types.include? "all" then types = ['app','prcs','web'] end if domains.include? "all" then all_domains = true end From 9efec8b3366c392991902a9b184031f3a7740e0f Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 23:12:56 -0500 Subject: [PATCH 036/168] Only using pq for tux status --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index f2063f7..8ce1a89 100755 --- a/bin/psa +++ b/bin/psa @@ -30,7 +30,7 @@ domains = opts_d.split(',') if types.include? "all" then types = ['app','prcs','web'] end if domains.include? "all" then all_domains = true end -if statuses.include? "all" then opts = ['psr', 'pq'] end +if statuses.include? "all" then opts = ['pq'] end # setup environment PS_PSA_CONF = ENV['PS_PSA_CONF'] || "#{ENV['HOME']}/.psa.conf" From 3ffacd2c9e744e673ac733416ce65f52ffbb1140 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 23:14:42 -0500 Subject: [PATCH 037/168] Only using pq for tux status --- bin/psa | 5 +---- lib/psadmin_plus.rb | 8 +++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/bin/psa b/bin/psa index 8ce1a89..65b577f 100755 --- a/bin/psa +++ b/bin/psa @@ -11,7 +11,6 @@ end opts_c = ARGV.shift || "help" opts_t = ARGV.shift || "all" opts_d = ARGV.shift || "all" -*opts_s = ARGV.shift || "all" # Set remaining arguments as environment variables ARGV.each do |arg| if arg.include? "=" @@ -26,11 +25,9 @@ end commands = opts_c.split(',') types = opts_t.split(',') domains = opts_d.split(',') -*statuses = opts_s[0].split(',') if types.include? "all" then types = ['app','prcs','web'] end if domains.include? "all" then all_domains = true end -if statuses.include? "all" then opts = ['pq'] end # setup environment PS_PSA_CONF = ENV['PS_PSA_CONF'] || "#{ENV['HOME']}/.psa.conf" @@ -117,7 +114,7 @@ commands.each do |c| case "#{c}" when "status" do_cmd_banner(c,t,d) - do_status(t,d, opts) + do_status(t,d) when "start" do_cmd_banner(c,t,d) do_start(t,d) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 518e3ef..b211785 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -321,7 +321,7 @@ def do_summary #do_status("web","all") end -def do_status(type, domain, opts) +def do_status(type, domain) case type when "app" do_psadmin_check ? nil : return @@ -330,10 +330,8 @@ def do_status(type, domain, opts) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" - opts.each do |cmd| - do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo #{cmd} | " + env('TUXDIR') + "/bin/tmadmin -r ") - end + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "pubsub" do_psadmin_check ? nil : return do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") From 1e773f4420c3bdc51684e47b01b268bc5a3bc118 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 23:21:43 -0500 Subject: [PATCH 038/168] Trying colors for stderr --- lib/psadmin_plus.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index b211785..945fade 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -47,6 +47,13 @@ def do_help puts " " end +def colorize(text, color_code) + "\e[#{color_code}m#{text}\e[0m" +end + +def red(text); colorize(text, 31); end +def green(text); colorize(text, 32); end + def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false end @@ -106,16 +113,24 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) if timestamp == "off" stdout else + # Standard Output *lines = stdout.split(/\n/) # lines[0...-2].each do | line | # Remove two trailing extra lines lines.each do | line | do_output(line, timestamp) end + + # Standard Error + *lines = stdout.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp, true) + end end end -def do_output(line, timestamp = nil) +def do_output(line, timestamp = nil, err = false) utctime = "" # Handle Output - Check if timestamps are requested @@ -129,7 +144,11 @@ def do_output(line, timestamp = nil) if !line.empty? if line != '> ' - puts (utctime + line).gsub('"', '') + if !err + puts (utctime + line).gsub('"', '') + else + puts (utctime + red(line)).gsub('"', '') + end end end end From 72cb97a5a941d0baeacc3114e9892d8a81aaa50c Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Tue, 13 Jun 2023 23:33:08 -0500 Subject: [PATCH 039/168] Send stderr --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 945fade..a78019c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -121,7 +121,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) end # Standard Error - *lines = stdout.split(/\n/) + *lines = stderr.split(/\n/) # lines[0...-2].each do | line | # Remove two trailing extra lines lines.each do | line | do_output(line, timestamp, true) From b7a3e4559e6dda474cb4a66399f6b19f7878fa57 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 08:40:35 -0500 Subject: [PATCH 040/168] Testing a runner class to stream stdout --- lib/psadmin_plus.rb | 5 ++- lib/runner.rb | 88 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 lib/runner.rb diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index a78019c..ac73004 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -3,6 +3,7 @@ require 'rbconfig' require 'etc' require 'open3' +require 'runner' def do_help puts "Usage: psa [command] " @@ -81,7 +82,9 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) when "true" p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" end - stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + runner.run else print "#{PS_RUNTIME_USER} " case "#{PS_PSA_DEBUG}" diff --git a/lib/runner.rb b/lib/runner.rb new file mode 100644 index 0000000..3a4931e --- /dev/null +++ b/lib/runner.rb @@ -0,0 +1,88 @@ +require 'open3' + +class Runner + attr_reader :cmd, :exit_status, :stdout, :stderr + + # Run a command, return runner instance + # @param cmd [String,Array] command to execute + def self.run(*cmd) + Runner.new(*cmd).run + end + + # Run a command, raise Runner::Error if it fails + # @param cmd [String,Array] command to execute + # @raise [Runner::Error] + def self.run!(*cmd) + Runner.new(*cmd).run! + end + + # Run a command, return true if it succeeds, false if not + # @param cmd [String,Array] command to execute + # @return [Boolean] + def self.run?(*cmd) + Runner.new(*cmd).run? + end + + Error = Class.new(StandardError) + + # @param cmd [String,Array] command to execute + def initialize(cmd) + @cmd = cmd.is_a?(Array) ? cmd.join(' ') : cmd + @stdout = +'' + @stderr = +'' + @exit_status = nil + end + + # @return [Boolean] success or failure? + def success? + exit_status.zero? + end + + # Run the command, return self + # @return [Runner] + def run + Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| + until [stdout, stderr].all?(&:eof?) + readable = IO.select([stdout, stderr]) + next unless readable&.first + + readable.first.each do |stream| + data = +'' + # rubocop:disable Lint/HandleExceptions + begin + stream.read_nonblock(1024, data) + rescue EOFError + # ignore, it's expected for read_nonblock to raise EOFError + # when all is read + end + + if stream == stdout + @stdout << data + $stdout.write(data) + else + @stderr << data + $stderr.write(data) + end + end + end + @exit_status = wait_thr.value.exitstatus + end + + self + end + + # Run the command and return stdout, raise if fails + # @return stdout [String] + # @raise [Runner::Error] + def run! + return run.stdout if run.success? + + raise(Error, "command failed, exit: %d - stdout: %s / stderr: %s" % [exit_status, stdout, stderr]) + end + + # Run the command and return true if success, false if failure + # @return success [Boolean] + def run? + run.success? + end +end \ No newline at end of file From 21a886a5003c34180a03037f02ae1d937c576d18 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 08:41:32 -0500 Subject: [PATCH 041/168] Use require_relative --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index ac73004..ae6a2e4 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -3,7 +3,7 @@ require 'rbconfig' require 'etc' require 'open3' -require 'runner' +require_relative 'runner' def do_help puts "Usage: psa [command] " From 95043453eab96e1f4efaf314d4bbb563f82ac2e7 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 08:43:03 -0500 Subject: [PATCH 042/168] Use runner.stdout --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index ae6a2e4..2c192ad 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -114,17 +114,17 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) end if timestamp == "off" - stdout + runner.stdout else # Standard Output - *lines = stdout.split(/\n/) + *lines = runner.stdout.split(/\n/) # lines[0...-2].each do | line | # Remove two trailing extra lines lines.each do | line | do_output(line, timestamp) end # Standard Error - *lines = stderr.split(/\n/) + *lines = runner.stderr.split(/\n/) # lines[0...-2].each do | line | # Remove two trailing extra lines lines.each do | line | do_output(line, timestamp, true) From 7723f4980d7861096bd3ec277ae728c6d1a604d9 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 08:59:52 -0500 Subject: [PATCH 043/168] Starting output processing --- lib/psadmin_plus.rb | 60 ++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 2c192ad..27dc022 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -85,6 +85,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") runner.run + runner.stdout else print "#{PS_RUNTIME_USER} " case "#{PS_PSA_DEBUG}" @@ -113,34 +114,37 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) out = "Invalid OS" end - if timestamp == "off" + if timestamp == "internal" runner.stdout else - # Standard Output - *lines = runner.stdout.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp) - end + process_output(runnder.stdout, runner.stderr, runner.success, timestamp) + end +end - # Standard Error - *lines = runner.stderr.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp, true) - end +def process_output(stdout, stderr, exitcode, timestamp = nil) + # Standard Output + *lines = runner.stdout.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp) end + # Standard Error + *lines = runner.stderr.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp, true) + end end def do_output(line, timestamp = nil, err = false) utctime = "" # Handle Output - Check if timestamps are requested - # - override if parameter is "off" for internal calls + # - override if parameter is "internal" for internal calls case "#{PS_PSA_TIMESTAMP}" when "true" - if timestamp != "off" + if timestamp != "internal" utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") end end @@ -180,9 +184,9 @@ def do_set_cfg_home(d) def find_apps_nix case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) + apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) else - apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) + apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) end apps.map! {|app| app.split("/")[-2]} end @@ -190,9 +194,9 @@ def find_apps_nix def find_prcss_nix case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) + prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) else - prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"off").split(/\n+/) + prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) end prcss.map! {|prcs| prcs.split("/")[-2]} end @@ -200,24 +204,24 @@ def find_prcss_nix def find_webs_nix case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"off").split(/\n+/) + webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) else - webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"off").split(/\n+/) + webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) end webs.map! {|web| web.split("/")[-2]} end def find_sites_nix(domain) - webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"off").split(/\n+/) + webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) webs.map! {|site| site.split("/")[-1]} end def find_apps_win case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) + apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else - apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) + apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end apps.map! {|app| app.split('\\')[-2]} end @@ -225,9 +229,9 @@ def find_apps_win def find_prcss_win case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) + prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else - prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) + prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end prcss.map! {|prcs| prcs.split("\\")[-2]} end @@ -235,9 +239,9 @@ def find_prcss_win def find_webs_win case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) + webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else - webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"off").split(/\n+/) + webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end webs.map! {|web| web.split("\\")[-2]} end From 71111db134045a4447f8e11f35490f4f6c851ecf Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:00:22 -0500 Subject: [PATCH 044/168] Fix typo --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 27dc022..672c9ba 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -117,7 +117,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) if timestamp == "internal" runner.stdout else - process_output(runnder.stdout, runner.stderr, runner.success, timestamp) + process_output(runner.stdout, runner.stderr, runner.success, timestamp) end end From 03ba509af402c5c0b5fd32d9e69b7e68ca79e793 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:00:40 -0500 Subject: [PATCH 045/168] Fix typo --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 672c9ba..497af15 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -117,7 +117,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) if timestamp == "internal" runner.stdout else - process_output(runner.stdout, runner.stderr, runner.success, timestamp) + process_output(runner.stdout, runner.stderr, runner.success?, timestamp) end end From eb6eac30de3b6e623b97dca19077c098ea6848c3 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:01:10 -0500 Subject: [PATCH 046/168] Fix typo --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 497af15..d10d1f2 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -123,14 +123,14 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) def process_output(stdout, stderr, exitcode, timestamp = nil) # Standard Output - *lines = runner.stdout.split(/\n/) + *lines = stdout.split(/\n/) # lines[0...-2].each do | line | # Remove two trailing extra lines lines.each do | line | do_output(line, timestamp) end # Standard Error - *lines = runner.stderr.split(/\n/) + *lines = stderr.split(/\n/) # lines[0...-2].each do | line | # Remove two trailing extra lines lines.each do | line | do_output(line, timestamp, true) From bbe3e0215ad8a4bf1d86133a2771bd943f9a7871 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:27:09 -0500 Subject: [PATCH 047/168] Testing a realtime flag for streaming stdout --- lib/psadmin_plus.rb | 10 +++++++++- lib/runner.rb | 47 ++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index d10d1f2..73e0f8d 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -84,8 +84,9 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) end # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + runner.realtime = true runner.run - runner.stdout + # runner.stdout else print "#{PS_RUNTIME_USER} " case "#{PS_PSA_DEBUG}" @@ -135,6 +136,13 @@ def process_output(stdout, stderr, exitcode, timestamp = nil) lines.each do | line | do_output(line, timestamp, true) end + + case "exitcode" + when 1 + do_output("psadmin returned an error", timestamp, true) + exit 1 + end + end def do_output(line, timestamp = nil, err = false) diff --git a/lib/runner.rb b/lib/runner.rb index 3a4931e..99225d7 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -1,7 +1,7 @@ require 'open3' class Runner - attr_reader :cmd, :exit_status, :stdout, :stderr + attr_reader :cmd, :exit_status, :stdout, :stderr, :realtime # Run a command, return runner instance # @param cmd [String,Array] command to execute @@ -42,27 +42,34 @@ def success? # @return [Runner] def run Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| - until [stdout, stderr].all?(&:eof?) - readable = IO.select([stdout, stderr]) - next unless readable&.first + # DJI + # until [stdout, stderr].all?(&:eof?) + # readable = IO.select([stdout, stderr]) + # next unless readable&.first - readable.first.each do |stream| - data = +'' - # rubocop:disable Lint/HandleExceptions - begin - stream.read_nonblock(1024, data) - rescue EOFError - # ignore, it's expected for read_nonblock to raise EOFError - # when all is read - end + # readable.first.each do |stream| + # data = +'' + # # rubocop:disable Lint/HandleExceptions + # begin + # stream.read_nonblock(1024, data) + # rescue EOFError + # # ignore, it's expected for read_nonblock to raise EOFError + # # when all is read + # end - if stream == stdout - @stdout << data - $stdout.write(data) - else - @stderr << data - $stderr.write(data) - end + # if stream == stdout + # @stdout << data + # $stdout.write(data) + # else + # @stderr << data + # $stderr.write(data) + # end + # end + # end + if @realtime == true + Thread.new do + stdout.each {|l| puts l } + stderr.each {|l| puts l } end end @exit_status = wait_thr.value.exitstatus From 5fd825f651e9b2417856180036954a6eaa9078bc Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:28:06 -0500 Subject: [PATCH 048/168] Initialize realtime --- lib/runner.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/runner.rb b/lib/runner.rb index 99225d7..53288d1 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -30,6 +30,7 @@ def initialize(cmd) @cmd = cmd.is_a?(Array) ? cmd.join(' ') : cmd @stdout = +'' @stderr = +'' + @realtime = false @exit_status = nil end From 2357144bb56269a4cfcd08ff2c54037afe522b83 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:30:08 -0500 Subject: [PATCH 049/168] Setting realtime when instantiating --- lib/psadmin_plus.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 73e0f8d..b6139fc 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -83,8 +83,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" end # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") - runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") - runner.realtime = true + runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) runner.run # runner.stdout else From a667bbc3dffac7f4f379cccd69a4c045dbd9057f Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:30:55 -0500 Subject: [PATCH 050/168] Support realtime in init --- lib/runner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runner.rb b/lib/runner.rb index 53288d1..f3eca68 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -26,11 +26,11 @@ def self.run?(*cmd) Error = Class.new(StandardError) # @param cmd [String,Array] command to execute - def initialize(cmd) + def initialize(cmd, realtime = false) @cmd = cmd.is_a?(Array) ? cmd.join(' ') : cmd @stdout = +'' @stderr = +'' - @realtime = false + @realtime = realtime @exit_status = nil end From ac5affafd9597862023f3431027f96de5e8c37b9 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:56:03 -0500 Subject: [PATCH 051/168] Testing new debugger --- bin/psa | 2 +- lib/psadmin_plus.rb | 71 +++++++++++++++++++++------------------------ lib/runner.rb | 1 + 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/bin/psa b/bin/psa index 65b577f..163de4e 100755 --- a/bin/psa +++ b/bin/psa @@ -58,7 +58,7 @@ PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" PS_MULTI_DELIMIT = ENV['PS_MULTI_DELIMIT'] || "/" PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0 PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" -PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "false" +PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" # validation diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index b6139fc..da3ed11 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -55,6 +55,21 @@ def colorize(text, color_code) def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end +def logger + @logger ||= Logger.new(STDOUT).tap do |logger| + log_level_from_env = ENV['PS_PSA_DEBUG'] + logger.level = Logger.const_get(log_level_from_env) + logger.formatter = proc do |severity, datetime, progname, msg| + date_format = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "#{cmd} (#{severity}): #{msg}\n" + end + end +end + +def info(msg); logger.info msg; end +def warn(msg); logger.warn msg; end +def debug(msg); logger.debug msg; end + def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false end @@ -64,50 +79,35 @@ def do_is_runtime_user_win end def env(var) - result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" + result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" end def do_cmd(cmd, print = true, powershell = true, timestamp = nil) case "#{OS_CONST}" when "linux" if do_is_runtime_user_nix - case "#{PS_PSA_DEBUG}" - when "true" - p "Command: #{cmd}" - end + debug "Command: #{cmd}" out = `#{cmd}` else if "#{PS_PSA_SUDO}" == "on" - case "#{PS_PSA_DEBUG}" - when "true" - p "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" - end + debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) runner.run # runner.stdout else print "#{PS_RUNTIME_USER} " - case "#{PS_PSA_DEBUG}" - when "true" - p "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" - end + debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` end end when "windows" case powershell when true - case "#{PS_PSA_DEBUG}" - when "true" - p "Command: powershell -NoProfile -Command \"#{cmd}\"" - end + debug "Command: powershell -NoProfile -Command \"#{cmd}\"" out = `powershell -NoProfile -Command "#{cmd}"` else - case "#{PS_PSA_DEBUG}" - when "true" - p "Command: #{cmd}" - end + debug "Command: #{cmd}" out = `#{cmd}` end else @@ -325,13 +325,8 @@ def do_list def do_psadmin_check # Check to see if psadmin loads correctly # This will help when used on web servers that don't have Tuxedo - case "#{PS_PSA_DEBUG}" - when "true" - puts "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) - else - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",false) - end + debug "Checking psadmin version to validate configuration:" + check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) if check.include? "error" # psadmin config is NOT valid puts "ERROR: psadmin is not configured correctly for this environment!" @@ -619,33 +614,33 @@ def do_hook(command, type, domain, script) def do_hookpre(command, type, domain) if "#{PS_HOOK_PRE}" != "false" - "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain pre command hook...\n\n") : nil + debug "Executing domain pre command hook...\n\n" do_hook(command, type, domain, PS_HOOK_PRE) - "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil + debug "\n...hook done" end end def do_hookpost(command, type, domain) if "#{PS_HOOK_POST}" != "false" - "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain post command hook...\n\n") : nil + debug "Executing domain post command hook...\n\n" do_hook(command, type, domain, PS_HOOK_POST) - "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil + debug "\n...hook done" end end def do_hookstart(command, type, domain) if "#{PS_HOOK_START}" != "false" - "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain start hook...\n\n") : nil + debug "Executing domain start hook...\n\n" do_hook(command, type, domain, PS_HOOK_START) - "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil + debug "\n...hook done" end end def do_hookstop(command, type, domain) if "#{PS_HOOK_STOP}" != "false" - "#{PS_PSA_DEBUG}" == "true" ? (puts "Executing domain stop hook...\n\n") : nil + debug "Executing domain stop hook...\n\n" do_hook(command, type, domain, PS_HOOK_STOP) - "#{PS_PSA_DEBUG}" == "true" ? (puts "\n...hook done") : nil + debug "\n...hook done" end end @@ -654,7 +649,7 @@ def do_webprof_reload(domain) case "#{OS_CONST}" when "linux" - "#{PS_PSA_DEBUG}" == "true" ? show_debug = true : show_debug = false + "#{PS_PSA_DEBUG}" == "DEBUG" ? show_debug = true : show_debug = false find_sites(domain).each do |s| # set vars @@ -712,5 +707,5 @@ def os else raise Error::WebDriverError, "unknown os: #{host_os.inspect}" end - ) + ) end diff --git a/lib/runner.rb b/lib/runner.rb index f3eca68..bc30d3c 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -72,6 +72,7 @@ def run stdout.each {|l| puts l } stderr.each {|l| puts l } end + wait_thread.value end @exit_status = wait_thr.value.exitstatus end From ac8a862460f8ba46e83eb55c64e07c4680f0b775 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 09:56:24 -0500 Subject: [PATCH 052/168] Reverting runner code --- lib/runner.rb | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/runner.rb b/lib/runner.rb index bc30d3c..7753e69 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -43,37 +43,37 @@ def success? # @return [Runner] def run Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| - # DJI - # until [stdout, stderr].all?(&:eof?) - # readable = IO.select([stdout, stderr]) - # next unless readable&.first + until [stdout, stderr].all?(&:eof?) + readable = IO.select([stdout, stderr]) + next unless readable&.first - # readable.first.each do |stream| - # data = +'' - # # rubocop:disable Lint/HandleExceptions - # begin - # stream.read_nonblock(1024, data) - # rescue EOFError - # # ignore, it's expected for read_nonblock to raise EOFError - # # when all is read - # end + readable.first.each do |stream| + data = +'' + # rubocop:disable Lint/HandleExceptions + begin + stream.read_nonblock(1024, data) + rescue EOFError + # ignore, it's expected for read_nonblock to raise EOFError + # when all is read + end - # if stream == stdout - # @stdout << data - # $stdout.write(data) - # else - # @stderr << data - # $stderr.write(data) - # end - # end - # end - if @realtime == true - Thread.new do - stdout.each {|l| puts l } - stderr.each {|l| puts l } + if stream == stdout + @stdout << data + $stdout.write(data) + else + @stderr << data + $stderr.write(data) + end end - wait_thread.value end + # DJI + # if @realtime == true + # Thread.new do + # stdout.each {|l| puts l } + # stderr.each {|l| puts l } + # end + # wait_thread.value + # end @exit_status = wait_thr.value.exitstatus end From cd42afcd55bbeb8a5b0cf1ce30615724645ea4af Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 10:09:28 -0500 Subject: [PATCH 053/168] Try logger module --- lib/logger.rb | 25 +++++++++++++++++++++++++ lib/psadmin_plus.rb | 16 +--------------- 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 lib/logger.rb diff --git a/lib/logger.rb b/lib/logger.rb new file mode 100644 index 0000000..1d4d4b3 --- /dev/null +++ b/lib/logger.rb @@ -0,0 +1,25 @@ +module Logging + protected + + def info(msg) + logger.info msg + end + + def warn(msg) + logger.warn msg + end + + def debug(msg) + logger.debug msg + end + + def logger + @logger ||= Logger.new(STDOUT).tap do |logger| + log_level_from_env = ENV['PS_PSA_DEBUG'] + logger.level = Logger.const_get(log_level_from_env) + logger.formatter = proc do |severity, datetime, progname, msg| + date_format = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "#{cmd} (#{severity}): #{msg}\n" + end + end +end \ No newline at end of file diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index da3ed11..f03ac38 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -4,6 +4,7 @@ require 'etc' require 'open3' require_relative 'runner' +require_relative 'logger' def do_help puts "Usage: psa [command] " @@ -55,21 +56,6 @@ def colorize(text, color_code) def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end -def logger - @logger ||= Logger.new(STDOUT).tap do |logger| - log_level_from_env = ENV['PS_PSA_DEBUG'] - logger.level = Logger.const_get(log_level_from_env) - logger.formatter = proc do |severity, datetime, progname, msg| - date_format = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") - "#{cmd} (#{severity}): #{msg}\n" - end - end -end - -def info(msg); logger.info msg; end -def warn(msg); logger.warn msg; end -def debug(msg); logger.debug msg; end - def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false end From 36a100f7d029b5b60c34f044e1466a64ae5eb51e Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 10:10:00 -0500 Subject: [PATCH 054/168] Add missing end --- lib/logger.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/logger.rb b/lib/logger.rb index 1d4d4b3..19a3160 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -20,6 +20,7 @@ def logger logger.formatter = proc do |severity, datetime, progname, msg| date_format = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") "#{cmd} (#{severity}): #{msg}\n" + end end end end \ No newline at end of file From 94576a91679442355f89250f44b35dd0a009f981 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 10:12:42 -0500 Subject: [PATCH 055/168] Include logging module --- lib/logger.rb | 12 ++++++++++++ lib/psadmin_plus.rb | 9 ++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/logger.rb b/lib/logger.rb index 19a3160..a55ea1b 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -1,5 +1,17 @@ module Logging protected + + def colorize(text, color_code) + "\e[#{color_code}m#{text}\e[0m" + end + + def red(text) + colorize(text, 31) + end + + def green(text) + colorize(text, 32) + end def info(msg) logger.info msg diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f03ac38..0289ae8 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -6,6 +6,8 @@ require_relative 'runner' require_relative 'logger' +include Logging + def do_help puts "Usage: psa [command] " puts " " @@ -49,13 +51,6 @@ def do_help puts " " end -def colorize(text, color_code) - "\e[#{color_code}m#{text}\e[0m" -end - -def red(text); colorize(text, 31); end -def green(text); colorize(text, 32); end - def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false end From e95c9dacd51a255f54206315e0a2e7c51e2b035d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:09:11 -0500 Subject: [PATCH 056/168] Testing instance references --- lib/logger.rb | 8 ++++---- lib/psadmin_plus.rb | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/logger.rb b/lib/logger.rb index a55ea1b..a7b7ebb 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -1,6 +1,6 @@ module Logging protected - + def colorize(text, color_code) "\e[#{color_code}m#{text}\e[0m" end @@ -14,15 +14,15 @@ def green(text) end def info(msg) - logger.info msg + @logger.info msg end def warn(msg) - logger.warn msg + @logger.warn msg end def debug(msg) - logger.debug msg + @logger.debug msg end def logger diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0289ae8..8fbadbe 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -5,7 +5,6 @@ require 'open3' require_relative 'runner' require_relative 'logger' - include Logging def do_help From 9f47dc1920c56a1a437902a1114e6122cb988250 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:09:46 -0500 Subject: [PATCH 057/168] Testing module reference --- lib/logger.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/logger.rb b/lib/logger.rb index a7b7ebb..0277650 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -14,15 +14,15 @@ def green(text) end def info(msg) - @logger.info msg + Logging::logger.info msg end def warn(msg) - @logger.warn msg + Logging::logger.warn msg end def debug(msg) - @logger.debug msg + Logging::logger.debug msg end def logger From 7d042e1816d5a2b766d42a29738c3c9896022d8f Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:11:37 -0500 Subject: [PATCH 058/168] Moving method defs to main file --- lib/logger.rb | 24 ------------------------ lib/psadmin_plus.rb | 7 +++++++ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/lib/logger.rb b/lib/logger.rb index 0277650..c53809e 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -1,30 +1,6 @@ module Logging protected - def colorize(text, color_code) - "\e[#{color_code}m#{text}\e[0m" - end - - def red(text) - colorize(text, 31) - end - - def green(text) - colorize(text, 32) - end - - def info(msg) - Logging::logger.info msg - end - - def warn(msg) - Logging::logger.warn msg - end - - def debug(msg) - Logging::logger.debug msg - end - def logger @logger ||= Logger.new(STDOUT).tap do |logger| log_level_from_env = ENV['PS_PSA_DEBUG'] diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 8fbadbe..bb83ba6 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -50,6 +50,13 @@ def do_help puts " " end +def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end +def red(text); colorize(text, 31); end +def green(text); colorize(text, 32); end +def info(msg); logger.info msg; end +def warn(msg); logger.warn msg; end +def debug(msg); logger.debug msg; end + def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false end From 0e8b900a1d4bdf371e0cf85da945d25aecbf594c Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:30:27 -0500 Subject: [PATCH 059/168] Testing simpler logger --- lib/logger.rb | 14 -------------- lib/psadmin_plus.rb | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 lib/logger.rb diff --git a/lib/logger.rb b/lib/logger.rb deleted file mode 100644 index c53809e..0000000 --- a/lib/logger.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Logging - protected - - def logger - @logger ||= Logger.new(STDOUT).tap do |logger| - log_level_from_env = ENV['PS_PSA_DEBUG'] - logger.level = Logger.const_get(log_level_from_env) - logger.formatter = proc do |severity, datetime, progname, msg| - date_format = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") - "#{cmd} (#{severity}): #{msg}\n" - end - end - end -end \ No newline at end of file diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index bb83ba6..3b4c1c4 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -3,9 +3,8 @@ require 'rbconfig' require 'etc' require 'open3' +require 'logger' require_relative 'runner' -require_relative 'logger' -include Logging def do_help puts "Usage: psa [command] " @@ -50,11 +49,21 @@ def do_help puts " " end +logger = Logger.new(STDOUT) +logger.formatter = proc do |severity, datetime, progname, msg| + date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") + case severity + when "INFO" + "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" + when "DEBUG" + "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" + end +end + def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end def info(msg); logger.info msg; end -def warn(msg); logger.warn msg; end def debug(msg); logger.debug msg; end def do_is_runtime_user_nix From d6c01d691fded2c35c7ab120f93f600d6c77138c Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:31:33 -0500 Subject: [PATCH 060/168] Use method call --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 3b4c1c4..6358a75 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -63,8 +63,8 @@ def do_help def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end -def info(msg); logger.info msg; end -def debug(msg); logger.debug msg; end +def info(msg); logger.info(msg); end +def debug(msg); logger.debug(msg); end def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false From 34e67891f081ad92ccd8c48157cf00a56d8bd197 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:50:01 -0500 Subject: [PATCH 061/168] Simple names for logging --- lib/psadmin_plus.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 6358a75..5561acb 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -49,8 +49,8 @@ def do_help puts " " end -logger = Logger.new(STDOUT) -logger.formatter = proc do |severity, datetime, progname, msg| +log = Logger.new(STDOUT) +log.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity when "INFO" @@ -63,8 +63,8 @@ def do_help def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end -def info(msg); logger.info(msg); end -def debug(msg); logger.debug(msg); end +def info(msg); log.info(msg); end +def debug(msg); log.debug(msg); end def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false From 0fb2cc8daf392dafc3b18203e1ecf25da78504a3 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:52:53 -0500 Subject: [PATCH 062/168] Move logger init to psa --- bin/psa | 32 ++++++++++++++++++++++---------- lib/psadmin_plus.rb | 15 ++------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/bin/psa b/bin/psa index 163de4e..746040f 100755 --- a/bin/psa +++ b/bin/psa @@ -1,25 +1,37 @@ #!/usr/bin/env ruby begin - require 'psadmin_plus' + require 'psadmin_plus' rescue LoadError - # running directly, not through gem install - require_relative '../lib/psadmin_plus.rb' + # running directly, not through gem install + require_relative '../lib/psadmin_plus.rb' end +logger = Logger.new($stdout) +logger.formatter = proc do |severity, datetime, progname, msg| + date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") + case severity + when "INFO" + "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" + when "DEBUG" + "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" + end +end + + # options opts_c = ARGV.shift || "help" opts_t = ARGV.shift || "all" opts_d = ARGV.shift || "all" # Set remaining arguments as environment variables ARGV.each do |arg| - if arg.include? "=" - var = arg.split('=') - ENV[var[0]]=var[1] - puts "Setting environment variable " + var[0] + "=" + var[1] - else - # puts "Skip argument, no valid environment variable found." - end + if arg.include? "=" + var = arg.split('=') + ENV[var[0]]=var[1] + puts "Setting environment variable " + var[0] + "=" + var[1] + else + # puts "Skip argument, no valid environment variable found." + end end commands = opts_c.split(',') diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 5561acb..64ae9d8 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -49,22 +49,11 @@ def do_help puts " " end -log = Logger.new(STDOUT) -log.formatter = proc do |severity, datetime, progname, msg| - date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") - case severity - when "INFO" - "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" - when "DEBUG" - "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" - end -end - def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end -def info(msg); log.info(msg); end -def debug(msg); log.debug(msg); end +def info(msg); logger.info(msg); end +def debug(msg); logger.debug(msg); end def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false From c3f74409953752609b5905c037c0c3d25d7a7ddf Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:55:56 -0500 Subject: [PATCH 063/168] Testing with module for psadmin_plus --- bin/psa | 12 - lib/psadmin_plus.rb | 1276 ++++++++++++++++++++++--------------------- 2 files changed, 645 insertions(+), 643 deletions(-) diff --git a/bin/psa b/bin/psa index 746040f..af8ed86 100755 --- a/bin/psa +++ b/bin/psa @@ -7,18 +7,6 @@ rescue LoadError require_relative '../lib/psadmin_plus.rb' end -logger = Logger.new($stdout) -logger.formatter = proc do |severity, datetime, progname, msg| - date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") - case severity - when "INFO" - "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" - when "DEBUG" - "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" - end -end - - # options opts_c = ARGV.shift || "help" opts_t = ARGV.shift || "all" diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 64ae9d8..e2c67a1 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -6,691 +6,705 @@ require 'logger' require_relative 'runner' -def do_help - puts "Usage: psa [command] " - puts " " - puts "Commands:" - puts " " - puts " help display this help message" - puts " list list domains" - #puts " admin launch psadmin" - puts " summary PS_CFG_HOME summary, no type or domain needed" - puts " status status of the domain" - puts " start hookstart, if enabled, then start the domain" - puts " stop hookstop, if enabled, stop the domain" - puts " restart stop and start the domain" - puts " purge clear domain cache" - puts " reconfigure stop, configure, and start the domain" - puts " bounce stop, flush, purge, configure and start the domain" - puts " kill force stop the domain" - puts " configure configure the domain" - puts " flush clear domain IPC" - puts " " - puts "Types:" - puts " " - puts " app act on application domains" - puts " prcs act on process scheduler domains" - puts " web act on web domains" - puts " all, act on web, app, and prcs domains" - puts " pubsub act on PUBSUB group of application domains (status only)" - puts " tux act on tuxedo domain (status only)" - puts " " - puts "Domains:" - puts " " - puts " dom act on specific domains" - puts " all, act on all domains" - puts " " - puts "Tux Status Options" - puts " " - puts " psr print server status" - puts " pq print queue status" - puts " " - puts "Each parameter type can be enter in a comma separated list " - puts " " -end - -def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end -def red(text); colorize(text, 31); end -def green(text); colorize(text, 32); end -def info(msg); logger.info(msg); end -def debug(msg); logger.debug(msg); end - -def do_is_runtime_user_nix - result = ENV['USER'] == PS_RUNTIME_USER ? true : false -end - -def do_is_runtime_user_win - result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false -end - -def env(var) - result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" -end - -def do_cmd(cmd, print = true, powershell = true, timestamp = nil) - case "#{OS_CONST}" - when "linux" - if do_is_runtime_user_nix - debug "Command: #{cmd}" - out = `#{cmd}` - else - if "#{PS_PSA_SUDO}" == "on" - debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" - # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") - runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) - runner.run - # runner.stdout +module psadmin_plus + + logger = Logger.new($stdout) + logger.formatter = proc do |severity, datetime, progname, msg| + date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") + case severity + when "INFO" + "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" + when "DEBUG" + "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" + end + end + + def do_help + puts "Usage: psa [command] " + puts " " + puts "Commands:" + puts " " + puts " help display this help message" + puts " list list domains" + #puts " admin launch psadmin" + puts " summary PS_CFG_HOME summary, no type or domain needed" + puts " status status of the domain" + puts " start hookstart, if enabled, then start the domain" + puts " stop hookstop, if enabled, stop the domain" + puts " restart stop and start the domain" + puts " purge clear domain cache" + puts " reconfigure stop, configure, and start the domain" + puts " bounce stop, flush, purge, configure and start the domain" + puts " kill force stop the domain" + puts " configure configure the domain" + puts " flush clear domain IPC" + puts " " + puts "Types:" + puts " " + puts " app act on application domains" + puts " prcs act on process scheduler domains" + puts " web act on web domains" + puts " all, act on web, app, and prcs domains" + puts " pubsub act on PUBSUB group of application domains (status only)" + puts " tux act on tuxedo domain (status only)" + puts " " + puts "Domains:" + puts " " + puts " dom act on specific domains" + puts " all, act on all domains" + puts " " + puts "Tux Status Options" + puts " " + puts " psr print server status" + puts " pq print queue status" + puts " " + puts "Each parameter type can be enter in a comma separated list " + puts " " + end + + def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end + def red(text); colorize(text, 31); end + def green(text); colorize(text, 32); end + def info(msg); logger.info(msg); end + def debug(msg); logger.debug(msg); end + + def do_is_runtime_user_nix + result = ENV['USER'] == PS_RUNTIME_USER ? true : false + end + + def do_is_runtime_user_win + result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false + end + + def env(var) + result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" + end + + def do_cmd(cmd, print = true, powershell = true, timestamp = nil) + case "#{OS_CONST}" + when "linux" + if do_is_runtime_user_nix + debug "Command: #{cmd}" + out = `#{cmd}` else - print "#{PS_RUNTIME_USER} " - debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" - out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` + if "#{PS_PSA_SUDO}" == "on" + debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" + # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) + runner.run + # runner.stdout + else + print "#{PS_RUNTIME_USER} " + debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" + out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` + end + end + when "windows" + case powershell + when true + debug "Command: powershell -NoProfile -Command \"#{cmd}\"" + out = `powershell -NoProfile -Command "#{cmd}"` + else + debug "Command: #{cmd}" + out = `#{cmd}` end + else + out = "Invalid OS" end - when "windows" - case powershell - when true - debug "Command: powershell -NoProfile -Command \"#{cmd}\"" - out = `powershell -NoProfile -Command "#{cmd}"` + + if timestamp == "internal" + runner.stdout else - debug "Command: #{cmd}" - out = `#{cmd}` + process_output(runner.stdout, runner.stderr, runner.success?, timestamp) end - else - out = "Invalid OS" end - if timestamp == "internal" - runner.stdout - else - process_output(runner.stdout, runner.stderr, runner.success?, timestamp) + def process_output(stdout, stderr, exitcode, timestamp = nil) + # Standard Output + *lines = stdout.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp) + end + + # Standard Error + *lines = stderr.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp, true) + end + + case "exitcode" + when 1 + do_output("psadmin returned an error", timestamp, true) + exit 1 + end + end -end -def process_output(stdout, stderr, exitcode, timestamp = nil) - # Standard Output - *lines = stdout.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp) + def do_output(line, timestamp = nil, err = false) + + utctime = "" + # Handle Output - Check if timestamps are requested + # - override if parameter is "internal" for internal calls + case "#{PS_PSA_TIMESTAMP}" + when "true" + if timestamp != "internal" + utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + end + end + + if !line.empty? + if line != '> ' + if !err + puts (utctime + line).gsub('"', '') + else + puts (utctime + red(line)).gsub('"', '') + end + end + end end - # Standard Error - *lines = stderr.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp, true) + def do_cmd_banner(c,t,d) + if "#{PS_PSA_TIMESTAMP}" == "true" + puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" + else + puts "" + puts "===[ #{c} . #{t} . #{d} ]===" + puts "" + end end - case "exitcode" - when 1 - do_output("psadmin returned an error", timestamp, true) - exit 1 + def do_set_cfg_home(d) + if "#{PS_MULTI_HOME}" != "false" + if PS_MULTI_PREFIX > 0 + h = d.slice(0..PS_MULTI_PREFIX) + else + h = d + end + ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{h}" + end end -end + def find_apps_nix + case "#{PS_MULTI_HOME}" + when "false" + apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + else + apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + end + apps.map! {|app| app.split("/")[-2]} + end -def do_output(line, timestamp = nil, err = false) + def find_prcss_nix + case "#{PS_MULTI_HOME}" + when "false" + prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + else + prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + end + prcss.map! {|prcs| prcs.split("/")[-2]} + end - utctime = "" - # Handle Output - Check if timestamps are requested - # - override if parameter is "internal" for internal calls - case "#{PS_PSA_TIMESTAMP}" - when "true" - if timestamp != "internal" - utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + def find_webs_nix + case "#{PS_MULTI_HOME}" + when "false" + webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + else + webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) end + webs.map! {|web| web.split("/")[-2]} end - - if !line.empty? - if line != '> ' - if !err - puts (utctime + line).gsub('"', '') - else - puts (utctime + red(line)).gsub('"', '') - end + + def find_sites_nix(domain) + webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) + webs.map! {|site| site.split("/")[-1]} + end + + def find_apps_win + case "#{PS_MULTI_HOME}" + when "false" + apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + end + apps.map! {|app| app.split('\\')[-2]} + end + + def find_prcss_win + case "#{PS_MULTI_HOME}" + when "false" + prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + end + prcss.map! {|prcs| prcs.split("\\")[-2]} + end + + def find_webs_win + case "#{PS_MULTI_HOME}" + when "false" + webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end + webs.map! {|web| web.split("\\")[-2]} + end + + def find_sites_win(domain) + #TODO + #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+/) + #sites.map! {|site| site.split("\\")[-2]} + end + + def find_apps + apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win + end + + def find_prcss + prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win + end + + def find_webs + webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win + end + + def find_sites(domain) + sites = "#{OS_CONST}" == "linux" ? find_sites_nix(domain) : find_sites_win(domain) + end + + def do_util + puts "TODO: util" end -end -def do_cmd_banner(c,t,d) - if "#{PS_PSA_TIMESTAMP}" == "true" - puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" - else + def do_admin + do_cmd("#{PS_PSADMIN_PATH}/psadmin") + end + + def do_list + puts "---" + print "hostname: " ; do_cmd('hostname') + print "ps-home: " ; do_cmd('echo ' + env('PS_HOME')) + if PS_MULTI_HOME == "false" + print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME')) + else + puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" + end + puts "" + puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}" + puts "PS_PSA_SUDO: #{PS_PSA_SUDO}" + puts "PS_HOOK_INTERP: #{PS_HOOK_INTERP}" + puts "PS_HOOK_PRE: #{PS_HOOK_PRE}" + puts "PS_HOOK_POST: #{PS_HOOK_POST}" + puts "PS_HOOK_START: #{PS_HOOK_START}" + puts "PS_HOOK_STOP: #{PS_HOOK_STOP}" + puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}" + puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" + puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" + puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" + puts "" + puts "app:" + find_apps.each do |a| + puts " - #{a}" + end puts "" - puts "===[ #{c} . #{t} . #{d} ]===" + puts "prcs:" + find_prcss.each do |p| + puts " - #{p}" + end + puts "" + puts "web:" + find_webs.each do |w| + puts " - #{w}" + end puts "" end -end -def do_set_cfg_home(d) - if "#{PS_MULTI_HOME}" != "false" - if PS_MULTI_PREFIX > 0 - h = d.slice(0..PS_MULTI_PREFIX) + def do_psadmin_check + # Check to see if psadmin loads correctly + # This will help when used on web servers that don't have Tuxedo + debug "Checking psadmin version to validate configuration:" + check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) + if check.include? "error" + # psadmin config is NOT valid + puts "ERROR: psadmin is not configured correctly for this environment!" + puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured" + false else - h = d - end - ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{h}" - end -end - -def find_apps_nix - case "#{PS_MULTI_HOME}" - when "false" - apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - else - apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - end - apps.map! {|app| app.split("/")[-2]} -end - -def find_prcss_nix - case "#{PS_MULTI_HOME}" - when "false" - prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - else - prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - end - prcss.map! {|prcs| prcs.split("/")[-2]} -end - -def find_webs_nix - case "#{PS_MULTI_HOME}" - when "false" - webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) - else - webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) - end - webs.map! {|web| web.split("/")[-2]} -end - -def find_sites_nix(domain) - webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) - webs.map! {|site| site.split("/")[-1]} -end - -def find_apps_win - case "#{PS_MULTI_HOME}" - when "false" - apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - apps.map! {|app| app.split('\\')[-2]} -end - -def find_prcss_win - case "#{PS_MULTI_HOME}" - when "false" - prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - prcss.map! {|prcs| prcs.split("\\")[-2]} -end - -def find_webs_win - case "#{PS_MULTI_HOME}" - when "false" - webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - webs.map! {|web| web.split("\\")[-2]} -end - -def find_sites_win(domain) - #TODO - #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+/) - #sites.map! {|site| site.split("\\")[-2]} -end - -def find_apps - apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win -end - -def find_prcss - prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win -end - -def find_webs - webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win -end - -def find_sites(domain) - sites = "#{OS_CONST}" == "linux" ? find_sites_nix(domain) : find_sites_win(domain) -end - -def do_util - puts "TODO: util" -end - -def do_admin - do_cmd("#{PS_PSADMIN_PATH}/psadmin") -end - -def do_list - puts "---" - print "hostname: " ; do_cmd('hostname') - print "ps-home: " ; do_cmd('echo ' + env('PS_HOME')) - if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME')) - else - puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" - end - puts "" - puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}" - puts "PS_PSA_SUDO: #{PS_PSA_SUDO}" - puts "PS_HOOK_INTERP: #{PS_HOOK_INTERP}" - puts "PS_HOOK_PRE: #{PS_HOOK_PRE}" - puts "PS_HOOK_POST: #{PS_HOOK_POST}" - puts "PS_HOOK_START: #{PS_HOOK_START}" - puts "PS_HOOK_STOP: #{PS_HOOK_STOP}" - puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}" - puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" - puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" - puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" - puts "" - puts "app:" - find_apps.each do |a| - puts " - #{a}" - end - puts "" - puts "prcs:" - find_prcss.each do |p| - puts " - #{p}" - end - puts "" - puts "web:" - find_webs.each do |w| - puts " - #{w}" - end - puts "" -end - -def do_psadmin_check - # Check to see if psadmin loads correctly - # This will help when used on web servers that don't have Tuxedo - debug "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) - if check.include? "error" - # psadmin config is NOT valid - puts "ERROR: psadmin is not configured correctly for this environment!" - puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured" - false - else - # psadmin config is valid - true - end -end - -def do_summary - if "#{PS_MULTI_HOME}" != "false" - ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{domain}" - end - - do_psadmin_check ? nil : exit - - do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary") - #do_status("web","all") -end - -def do_status(type, domain) - case type - when "app" - do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") - when "tux" - do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") - when "pubsub" - do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") - when "prcs" - do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") - when "web" - # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service - #do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") - #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") - #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") - else - puts "Invalid type, see psa help" - end -end - -def do_start(type, domain) - web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" - app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" - prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" - - case "#{PS_PARALLEL_BOOT}" - when "false" - start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}" - when "true" - start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}" - end - start_app_service_cmd = "start-service #{app_service_name}" - start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}" - start_prcs_service_cmd = "start-service #{prcs_service_name}" - start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh" - start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}" - start_web_service_cmd = "start-service #{web_service_name}" - - case type - when "app" - case "#{PS_WIN_SERVICES}" - when "true", "tux", "app", "all" - do_cmd(start_app_service_cmd) - else - do_cmd(start_app_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(start_app_service_cmd) - end + # psadmin config is valid + true + end + end + + def do_summary + if "#{PS_MULTI_HOME}" != "false" + ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{domain}" end - do_hookstart("start",type,domain) - when "pubsub" - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") - # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? - when "prcs" - case "#{PS_WIN_SERVICES}" - when "true", "tux", "prcs", "all" - do_cmd(start_prcs_service_cmd) + + do_psadmin_check ? nil : exit + + do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary") + #do_status("web","all") + end + + def do_status(type, domain) + case type + when "app" + do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") + when "tux" + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + when "pubsub" + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + when "prcs" + do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") + when "web" + # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service + #do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") + #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") + #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") else - do_cmd(start_prcs_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(start_prcs_service_cmd) - end + puts "Invalid type, see psa help" end - do_hookstart("start",type,domain) - when "web" - case "#{OS_CONST}" - when "linux" - if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") - puts "Domain #{domain} already started" + end + + def do_start(type, domain) + web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" + app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" + prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" + + case "#{PS_PARALLEL_BOOT}" + when "false" + start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}" + when "true" + start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}" + end + start_app_service_cmd = "start-service #{app_service_name}" + start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}" + start_prcs_service_cmd = "start-service #{prcs_service_name}" + start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh" + start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}" + start_web_service_cmd = "start-service #{web_service_name}" + + case type + when "app" + case "#{PS_WIN_SERVICES}" + when "true", "tux", "app", "all" + do_cmd(start_app_service_cmd) else - do_cmd(start_web_cmd_lnx) - sleep 5.0 + do_cmd(start_app_cmd) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(start_app_service_cmd) + end end - when "windows" + do_hookstart("start",type,domain) + when "pubsub" + ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? + when "prcs" case "#{PS_WIN_SERVICES}" - when "true", "web", "all" - do_cmd(start_web_service_cmd) + when "true", "tux", "prcs", "all" + do_cmd(start_prcs_service_cmd) else - # Run command outside of powershell with 'false' parameter - do_cmd(start_web_cmd_win, true, false) + do_cmd(start_prcs_cmd) case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(start_prcs_service_cmd) + end + end + do_hookstart("start",type,domain) + when "web" + case "#{OS_CONST}" + when "linux" + if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") + puts "Domain #{domain} already started" + else + do_cmd(start_web_cmd_lnx) + sleep 5.0 + end + when "windows" + case "#{PS_WIN_SERVICES}" when "true", "web", "all" do_cmd(start_web_service_cmd) + else + # Run command outside of powershell with 'false' parameter + do_cmd(start_web_cmd_win, true, false) + case "#{PS_TRAIL_SERVICE}" + when "true", "web", "all" + do_cmd(start_web_service_cmd) + end end end - end - do_hookstart("start",type,domain) - else - puts "Invalid type, see psa help" - end -end - -def do_stop(type, domain) - web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" - app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" - prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" - - stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}" - stop_app_service_cmd = "stop-service #{app_service_name}" - stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}" - stop_prcs_service_cmd = "stop-service #{prcs_service_name}" - stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh" - stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}" - stop_web_service_cmd = "stop-service #{web_service_name}" - - case type - when "app" - do_hookstop("stop",type,domain) - case "#{PS_WIN_SERVICES}" - when "true" - do_cmd(stop_app_service_cmd) + do_hookstart("start",type,domain) else - do_cmd(stop_app_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(stop_app_service_cmd) - end + puts "Invalid type, see psa help" end - when "pubsub" - # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") - when "prcs" - do_hookstop("stop",type,domain) - case "#{PS_WIN_SERVICES}" - when "true" - do_cmd(stop_prcs_service_cmd) - else - do_cmd(stop_prcs_cmd) - case "#{PS_TRAIL_SERVICE}" + end + + def do_stop(type, domain) + web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" + app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" + prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" + + stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}" + stop_app_service_cmd = "stop-service #{app_service_name}" + stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}" + stop_prcs_service_cmd = "stop-service #{prcs_service_name}" + stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh" + stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}" + stop_web_service_cmd = "stop-service #{web_service_name}" + + case type + when "app" + do_hookstop("stop",type,domain) + case "#{PS_WIN_SERVICES}" when "true" - do_cmd(stop_prcs_service_cmd) + do_cmd(stop_app_service_cmd) + else + do_cmd(stop_app_cmd) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(stop_app_service_cmd) + end end - end - when "web" - do_hookstop("stop",type,domain) - case "#{OS_CONST}" - when "linux" - do_cmd(stop_web_cmd_lnx) - when "windows" + when "pubsub" + # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? + ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + when "prcs" + do_hookstop("stop",type,domain) case "#{PS_WIN_SERVICES}" when "true" - do_cmd(stop_web_service_cmd) + do_cmd(stop_prcs_service_cmd) else - do_cmd(stop_web_cmd_win, true, false) + do_cmd(stop_prcs_cmd) case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(stop_prcs_service_cmd) + end + end + when "web" + do_hookstop("stop",type,domain) + case "#{OS_CONST}" + when "linux" + do_cmd(stop_web_cmd_lnx) + when "windows" + case "#{PS_WIN_SERVICES}" when "true" do_cmd(stop_web_service_cmd) + else + do_cmd(stop_web_cmd_win, true, false) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(stop_web_service_cmd) + end end end + else + puts "Invalid type, see psa help" end - else - puts "Invalid type, see psa help" end -end -def do_kill(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") - when "web" - case "#{OS_CONST}" - when "windows" - do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") - when "linux" - do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") - end - else - puts "Invalid type, see psa help" - end -end - -def do_configure(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") - when "web" - do_webprof_reload("#{domain}") - else - puts "Invalid type, see psa help" - end -end - -def do_purge(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") - when "prcs" - case "#{OS_CONST}" - when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") - when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + def do_kill(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") + when "web" + case "#{OS_CONST}" + when "windows" + do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") + when "linux" + do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") + end + else + puts "Invalid type, see psa help" + end + end + + def do_configure(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") + when "web" + do_webprof_reload("#{domain}") + else + puts "Invalid type, see psa help" + end + end + + def do_purge(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") + when "prcs" + case "#{OS_CONST}" + when "linux" + do_cmd("rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") + when "windows" + do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + end + puts "prcs cache purged" + when "web" + case "#{OS_CONST}" + when "linux" + do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") + puts "web cache purged" + when "windows" + do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + end + else + puts "Invalid type, see psa help" + end + end + + def do_flush(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") + when "web" + return # web flush n/a + else + puts "Invalid type, see psa help" + end + end + + def do_restart(type, domain) + do_stop(type, domain) + do_start(type, domain) + end + + def do_reconfigure(type, domain) + do_stop(type, domain) + do_configure(type, domain) + do_start(type, domain) + end + + def do_bounce(type, domain) + do_stop(type, domain) + do_purge(type, domain) + do_flush(type, domain) + do_configure(type, domain) + do_start(type, domain) + end + + def do_hook(command, type, domain, script) + ENV['PSA_CMD'] = command + ENV['PSA_TYPE'] = type + ENV['PSA_DOMAIN'] = domain + out = `#{PS_HOOK_INTERP} #{script}` + puts out + end + + def do_hookpre(command, type, domain) + if "#{PS_HOOK_PRE}" != "false" + debug "Executing domain pre command hook...\n\n" + do_hook(command, type, domain, PS_HOOK_PRE) + debug "\n...hook done" + end + end + + def do_hookpost(command, type, domain) + if "#{PS_HOOK_POST}" != "false" + debug "Executing domain post command hook...\n\n" + do_hook(command, type, domain, PS_HOOK_POST) + debug "\n...hook done" end - puts "prcs cache purged" - when "web" + end + + def do_hookstart(command, type, domain) + if "#{PS_HOOK_START}" != "false" + debug "Executing domain start hook...\n\n" + do_hook(command, type, domain, PS_HOOK_START) + debug "\n...hook done" + end + end + + def do_hookstop(command, type, domain) + if "#{PS_HOOK_STOP}" != "false" + debug "Executing domain stop hook...\n\n" + do_hook(command, type, domain, PS_HOOK_STOP) + debug "\n...hook done" + end + end + + def do_webprof_reload(domain) + puts "Reloading Web Profiles" + case "#{OS_CONST}" - when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") - puts "web cache purged" - when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) - end - else - puts "Invalid type, see psa help" - end -end - -def do_flush(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") - when "web" - return # web flush n/a - else - puts "Invalid type, see psa help" - end -end - -def do_restart(type, domain) - do_stop(type, domain) - do_start(type, domain) -end - -def do_reconfigure(type, domain) - do_stop(type, domain) - do_configure(type, domain) - do_start(type, domain) -end - -def do_bounce(type, domain) - do_stop(type, domain) - do_purge(type, domain) - do_flush(type, domain) - do_configure(type, domain) - do_start(type, domain) -end - -def do_hook(command, type, domain, script) - ENV['PSA_CMD'] = command - ENV['PSA_TYPE'] = type - ENV['PSA_DOMAIN'] = domain - out = `#{PS_HOOK_INTERP} #{script}` - puts out -end - -def do_hookpre(command, type, domain) - if "#{PS_HOOK_PRE}" != "false" - debug "Executing domain pre command hook...\n\n" - do_hook(command, type, domain, PS_HOOK_PRE) - debug "\n...hook done" - end -end - -def do_hookpost(command, type, domain) - if "#{PS_HOOK_POST}" != "false" - debug "Executing domain post command hook...\n\n" - do_hook(command, type, domain, PS_HOOK_POST) - debug "\n...hook done" - end -end - -def do_hookstart(command, type, domain) - if "#{PS_HOOK_START}" != "false" - debug "Executing domain start hook...\n\n" - do_hook(command, type, domain, PS_HOOK_START) - debug "\n...hook done" - end -end - -def do_hookstop(command, type, domain) - if "#{PS_HOOK_STOP}" != "false" - debug "Executing domain stop hook...\n\n" - do_hook(command, type, domain, PS_HOOK_STOP) - debug "\n...hook done" - end -end - -def do_webprof_reload(domain) - puts "Reloading Web Profiles" - - case "#{OS_CONST}" - when "linux" - "#{PS_PSA_DEBUG}" == "DEBUG" ? show_debug = true : show_debug = false - - find_sites(domain).each do |s| - # set vars - url = "${ADMINSERVER_PROTOCOL?}://${ADMINSERVER_HOSTNAME?}:${ADMINSERVER_PORT?}/psp/#{s}/?cmd=login&" - src_env = ". ${PS_CFG_HOME?}/webserv/#{domain}/bin/setEnv.sh" - prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" - - # set reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) - - # source setEnv and ping site - show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug) - - # unset reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) - - # done - puts " - #{s}" - end - when "windows" - puts "Windows support coming soon." - #do_cmd(". #{env('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") - - #find_sites.each do |s| - # # set vars - # prop_file = "#{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" - # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" - # # set reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") - # # ping site - # do_cmd("curl -s -o /dev/null '#{url}'") - # # unset reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") - # # done - # puts " - #{s}" - #end - else - puts " badOS - #{OS_CONST}" - end - puts "" -end - -def os - @os ||= ( - host_os = RbConfig::CONFIG['host_os'] - case host_os - when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - :windows - when /darwin|mac os/ - :macosx - when /linux/ - :linux - when /solaris|bsd/ - :unix - else - raise Error::WebDriverError, "unknown os: #{host_os.inspect}" + when "linux" + "#{PS_PSA_DEBUG}" == "DEBUG" ? show_debug = true : show_debug = false + + find_sites(domain).each do |s| + # set vars + url = "${ADMINSERVER_PROTOCOL?}://${ADMINSERVER_HOSTNAME?}:${ADMINSERVER_PORT?}/psp/#{s}/?cmd=login&" + src_env = ". ${PS_CFG_HOME?}/webserv/#{domain}/bin/setEnv.sh" + prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" + + # set reload in config.props + do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) + + # source setEnv and ping site + show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug) + + # unset reload in config.props + do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) + + # done + puts " - #{s}" end - ) -end + when "windows" + puts "Windows support coming soon." + #do_cmd(". #{env('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") + + #find_sites.each do |s| + # # set vars + # prop_file = "#{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" + # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" + # # set reload in config.props + # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") + # # ping site + # do_cmd("curl -s -o /dev/null '#{url}'") + # # unset reload in config.props + # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") + # # done + # puts " - #{s}" + #end + else + puts " badOS - #{OS_CONST}" + end + puts "" + end + + def os + @os ||= ( + host_os = RbConfig::CONFIG['host_os'] + case host_os + when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + :windows + when /darwin|mac os/ + :macosx + when /linux/ + :linux + when /solaris|bsd/ + :unix + else + raise Error::WebDriverError, "unknown os: #{host_os.inspect}" + end + ) + end +end \ No newline at end of file From 3974a6211f4c5544d17d5aad91647fe6670bd586 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:56:59 -0500 Subject: [PATCH 064/168] Fix module name --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index e2c67a1..da9829e 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -6,7 +6,7 @@ require 'logger' require_relative 'runner' -module psadmin_plus +module Psadmin_plus logger = Logger.new($stdout) logger.formatter = proc do |severity, datetime, progname, msg| From 0f9313a61e0e7136d0192ffbc566d6554da173bb Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 11:58:48 -0500 Subject: [PATCH 065/168] Using RUBY_PLATFORM for os --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index af8ed86..75cd165 100755 --- a/bin/psa +++ b/bin/psa @@ -43,7 +43,7 @@ if File.exists?(PS_PSA_CONF) then end # constants -OS_CONST = os +OS_CONST = RUBY_PLATFORM PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2" PS_HOOK_INTERP = ENV['PS_HOOK_INTERP'] || "ruby" PS_HOOK_PRE = ENV['PS_HOOK_PRE'] || "false" From 8895196da70e07d2de3fcee4030d02cddd85d356 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:00:25 -0500 Subject: [PATCH 066/168] Change env( to ENV( --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index 75cd165..d2bb2ed 100755 --- a/bin/psa +++ b/bin/psa @@ -51,7 +51,7 @@ PS_HOOK_POST = ENV['PS_HOOK_POST'] || "false" PS_HOOK_START = ENV['PS_HOOK_START'] || "false" PS_HOOK_STOP = ENV['PS_HOOK_STOP'] || "false" PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on" -PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "cmd /c #{env('PS_HOME')}/appserv" +PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{ENV('PS_HOME')}/bin" : "cmd /c #{ENV('PS_HOME')}/appserv" PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false" PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false" PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" From a7c1e33d9516014393c9b76f7fc407feef50c9bb Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:08:28 -0500 Subject: [PATCH 067/168] Starting ENV chagnes --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index d2bb2ed..56fd398 100755 --- a/bin/psa +++ b/bin/psa @@ -51,7 +51,7 @@ PS_HOOK_POST = ENV['PS_HOOK_POST'] || "false" PS_HOOK_START = ENV['PS_HOOK_START'] || "false" PS_HOOK_STOP = ENV['PS_HOOK_STOP'] || "false" PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on" -PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{ENV('PS_HOME')}/bin" : "cmd /c #{ENV('PS_HOME')}/appserv" +PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? ENV['PS_HOME'] + "/bin" : "cmd /c " + ENV['PS_HOME'] + "/appserv" PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false" PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false" PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" From a512b192d4387e4ce9cbf1a38cfbd0da654a1712 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:35:26 -0500 Subject: [PATCH 068/168] Switch back to 'os' --- bin/psa | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/psa b/bin/psa index 56fd398..f22acbf 100755 --- a/bin/psa +++ b/bin/psa @@ -1,5 +1,6 @@ #!/usr/bin/env ruby +require 'os' begin require 'psadmin_plus' rescue LoadError @@ -43,7 +44,7 @@ if File.exists?(PS_PSA_CONF) then end # constants -OS_CONST = RUBY_PLATFORM +OS_CONST = os PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2" PS_HOOK_INTERP = ENV['PS_HOOK_INTERP'] || "ruby" PS_HOOK_PRE = ENV['PS_HOOK_PRE'] || "false" @@ -51,7 +52,7 @@ PS_HOOK_POST = ENV['PS_HOOK_POST'] || "false" PS_HOOK_START = ENV['PS_HOOK_START'] || "false" PS_HOOK_STOP = ENV['PS_HOOK_STOP'] || "false" PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on" -PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? ENV['PS_HOME'] + "/bin" : "cmd /c " + ENV['PS_HOME'] + "/appserv" +PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "cmd /c #{env('PS_HOME')}/appserv" PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false" PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false" PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" From 461957a0d90957a8dbaee5602db1b3f63e868a8d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:40:45 -0500 Subject: [PATCH 069/168] Add modulename to os call --- bin/psa | 3 +- lib/psadmin_plus.rb | 71 +++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/bin/psa b/bin/psa index f22acbf..ff6df7d 100755 --- a/bin/psa +++ b/bin/psa @@ -1,6 +1,5 @@ #!/usr/bin/env ruby -require 'os' begin require 'psadmin_plus' rescue LoadError @@ -44,7 +43,7 @@ if File.exists?(PS_PSA_CONF) then end # constants -OS_CONST = os +OS_CONST = psadmin_plus.os PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2" PS_HOOK_INTERP = ENV['PS_HOOK_INTERP'] || "ruby" PS_HOOK_PRE = ENV['PS_HOOK_PRE'] || "false" diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index da9829e..c5dcf3f 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -26,7 +26,6 @@ def do_help puts " " puts " help display this help message" puts " list list domains" - #puts " admin launch psadmin" puts " summary PS_CFG_HOME summary, no type or domain needed" puts " status status of the domain" puts " start hookstart, if enabled, then start the domain" @@ -45,19 +44,14 @@ def do_help puts " prcs act on process scheduler domains" puts " web act on web domains" puts " all, act on web, app, and prcs domains" - puts " pubsub act on PUBSUB group of application domains (status only)" - puts " tux act on tuxedo domain (status only)" + puts " pubsub (status only) PUBSUB group status" + puts " tux (status only) Tuxedo Queue status" puts " " puts "Domains:" puts " " puts " dom act on specific domains" puts " all, act on all domains" puts " " - puts "Tux Status Options" - puts " " - puts " psr print server status" - puts " pq print queue status" - puts " " puts "Each parameter type can be enter in a comma separated list " puts " " end @@ -68,6 +62,24 @@ def green(text); colorize(text, 32); end def info(msg); logger.info(msg); end def debug(msg); logger.debug(msg); end + def os + @os ||= ( + host_os = RbConfig::CONFIG['host_os'] + case host_os + when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + :windows + when /darwin|mac os/ + :macosx + when /linux/ + :linux + when /solaris|bsd/ + :unix + else + raise Error::WebDriverError, "unknown os: #{host_os.inspect}" + end + ) + end + def do_is_runtime_user_nix result = ENV['USER'] == PS_RUNTIME_USER ? true : false end @@ -189,7 +201,7 @@ def do_set_cfg_home(d) def find_apps_nix case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + apps = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) else apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) end @@ -199,7 +211,7 @@ def find_apps_nix def find_prcss_nix case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + prcss = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) else prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) end @@ -209,7 +221,7 @@ def find_prcss_nix def find_webs_nix case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + webs = do_cmd("find #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) else webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) end @@ -224,7 +236,7 @@ def find_sites_nix(domain) def find_apps_win case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + apps = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end @@ -234,7 +246,7 @@ def find_apps_win def find_prcss_win case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + prcss = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end @@ -244,7 +256,7 @@ def find_prcss_win def find_webs_win case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + webs = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end @@ -253,7 +265,7 @@ def find_webs_win def find_sites_win(domain) #TODO - #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+/) + #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+/) #sites.map! {|site| site.split("\\")[-2]} end @@ -284,9 +296,9 @@ def do_admin def do_list puts "---" print "hostname: " ; do_cmd('hostname') - print "ps-home: " ; do_cmd('echo ' + env('PS_HOME')) + print "ps-home: " ; do_cmd('echo ' + ENV('PS_HOME')) if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME')) + print "ps-cfg-home: " ; do_cmd('echo ' + ENV('PS_CFG_HOME')) else puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" end @@ -357,10 +369,10 @@ def do_status(type, domain) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + ENV('TUXDIR') + "/bin/tmadmin -r ") when "pubsub" do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + ENV('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") @@ -669,11 +681,11 @@ def do_webprof_reload(domain) end when "windows" puts "Windows support coming soon." - #do_cmd(". #{env('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") + #do_cmd(". #{ENV('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") #find_sites.each do |s| # # set vars - # prop_file = "#{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" + # prop_file = "#{ENV('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" # # set reload in config.props # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") @@ -690,21 +702,4 @@ def do_webprof_reload(domain) puts "" end - def os - @os ||= ( - host_os = RbConfig::CONFIG['host_os'] - case host_os - when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - :windows - when /darwin|mac os/ - :macosx - when /linux/ - :linux - when /solaris|bsd/ - :unix - else - raise Error::WebDriverError, "unknown os: #{host_os.inspect}" - end - ) - end end \ No newline at end of file From 0f0740f812212a3f363756a14fc57627098fbc86 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:41:24 -0500 Subject: [PATCH 070/168] Fix module name --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index ff6df7d..3ab3dbb 100755 --- a/bin/psa +++ b/bin/psa @@ -43,7 +43,7 @@ if File.exists?(PS_PSA_CONF) then end # constants -OS_CONST = psadmin_plus.os +OS_CONST = Psadmin_plus.os PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2" PS_HOOK_INTERP = ENV['PS_HOOK_INTERP'] || "ruby" PS_HOOK_PRE = ENV['PS_HOOK_PRE'] || "false" From d5f6c8577c6a23004e1bde5968eb46a4937ce782 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:43:54 -0500 Subject: [PATCH 071/168] Playing with a new psa class --- bin/psa | 4 +- lib/psadmin_plus.rb | 1274 ++++++++++++++++++++++--------------------- 2 files changed, 641 insertions(+), 637 deletions(-) diff --git a/bin/psa b/bin/psa index 3ab3dbb..ed332bd 100755 --- a/bin/psa +++ b/bin/psa @@ -42,8 +42,10 @@ if File.exists?(PS_PSA_CONF) then end end +psa = Psadmin_plus.psa + # constants -OS_CONST = Psadmin_plus.os +OS_CONST = psa.os PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2" PS_HOOK_INTERP = ENV['PS_HOOK_INTERP'] || "ruby" PS_HOOK_PRE = ENV['PS_HOOK_PRE'] || "false" diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index c5dcf3f..324cbc3 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -8,698 +8,700 @@ module Psadmin_plus - logger = Logger.new($stdout) - logger.formatter = proc do |severity, datetime, progname, msg| - date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") - case severity - when "INFO" - "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" - when "DEBUG" - "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" - end - end - - def do_help - puts "Usage: psa [command] " - puts " " - puts "Commands:" - puts " " - puts " help display this help message" - puts " list list domains" - puts " summary PS_CFG_HOME summary, no type or domain needed" - puts " status status of the domain" - puts " start hookstart, if enabled, then start the domain" - puts " stop hookstop, if enabled, stop the domain" - puts " restart stop and start the domain" - puts " purge clear domain cache" - puts " reconfigure stop, configure, and start the domain" - puts " bounce stop, flush, purge, configure and start the domain" - puts " kill force stop the domain" - puts " configure configure the domain" - puts " flush clear domain IPC" - puts " " - puts "Types:" - puts " " - puts " app act on application domains" - puts " prcs act on process scheduler domains" - puts " web act on web domains" - puts " all, act on web, app, and prcs domains" - puts " pubsub (status only) PUBSUB group status" - puts " tux (status only) Tuxedo Queue status" - puts " " - puts "Domains:" - puts " " - puts " dom act on specific domains" - puts " all, act on all domains" - puts " " - puts "Each parameter type can be enter in a comma separated list " - puts " " - end - - def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end - def red(text); colorize(text, 31); end - def green(text); colorize(text, 32); end - def info(msg); logger.info(msg); end - def debug(msg); logger.debug(msg); end - - def os - @os ||= ( - host_os = RbConfig::CONFIG['host_os'] - case host_os - when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - :windows - when /darwin|mac os/ - :macosx - when /linux/ - :linux - when /solaris|bsd/ - :unix + class psa + logger = Logger.new($stdout) + logger.formatter = proc do |severity, datetime, progname, msg| + date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") + case severity + when "INFO" + "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" + when "DEBUG" + "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" + end + end + + def do_help + puts "Usage: psa [command] " + puts " " + puts "Commands:" + puts " " + puts " help display this help message" + puts " list list domains" + puts " summary PS_CFG_HOME summary, no type or domain needed" + puts " status status of the domain" + puts " start hookstart, if enabled, then start the domain" + puts " stop hookstop, if enabled, stop the domain" + puts " restart stop and start the domain" + puts " purge clear domain cache" + puts " reconfigure stop, configure, and start the domain" + puts " bounce stop, flush, purge, configure and start the domain" + puts " kill force stop the domain" + puts " configure configure the domain" + puts " flush clear domain IPC" + puts " " + puts "Types:" + puts " " + puts " app act on application domains" + puts " prcs act on process scheduler domains" + puts " web act on web domains" + puts " all, act on web, app, and prcs domains" + puts " pubsub (status only) PUBSUB group status" + puts " tux (status only) Tuxedo Queue status" + puts " " + puts "Domains:" + puts " " + puts " dom act on specific domains" + puts " all, act on all domains" + puts " " + puts "Each parameter type can be enter in a comma separated list " + puts " " + end + + def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end + def red(text); colorize(text, 31); end + def green(text); colorize(text, 32); end + def info(msg); logger.info(msg); end + def debug(msg); logger.debug(msg); end + + def os + @os ||= ( + host_os = RbConfig::CONFIG['host_os'] + case host_os + when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + :windows + when /darwin|mac os/ + :macosx + when /linux/ + :linux + when /solaris|bsd/ + :unix + else + raise Error::WebDriverError, "unknown os: #{host_os.inspect}" + end + ) + end + + def do_is_runtime_user_nix + result = ENV['USER'] == PS_RUNTIME_USER ? true : false + end + + def do_is_runtime_user_win + result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false + end + + def env(var) + result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" + end + + def do_cmd(cmd, print = true, powershell = true, timestamp = nil) + case "#{OS_CONST}" + when "linux" + if do_is_runtime_user_nix + debug "Command: #{cmd}" + out = `#{cmd}` else - raise Error::WebDriverError, "unknown os: #{host_os.inspect}" + if "#{PS_PSA_SUDO}" == "on" + debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" + # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) + runner.run + # runner.stdout + else + print "#{PS_RUNTIME_USER} " + debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" + out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` + end end - ) - end - - def do_is_runtime_user_nix - result = ENV['USER'] == PS_RUNTIME_USER ? true : false - end - - def do_is_runtime_user_win - result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false - end - - def env(var) - result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" - end - - def do_cmd(cmd, print = true, powershell = true, timestamp = nil) - case "#{OS_CONST}" - when "linux" - if do_is_runtime_user_nix - debug "Command: #{cmd}" - out = `#{cmd}` - else - if "#{PS_PSA_SUDO}" == "on" - debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" - # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") - runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) - runner.run - # runner.stdout + when "windows" + case powershell + when true + debug "Command: powershell -NoProfile -Command \"#{cmd}\"" + out = `powershell -NoProfile -Command "#{cmd}"` else - print "#{PS_RUNTIME_USER} " - debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" - out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` + debug "Command: #{cmd}" + out = `#{cmd}` end + else + out = "Invalid OS" end - when "windows" - case powershell - when true - debug "Command: powershell -NoProfile -Command \"#{cmd}\"" - out = `powershell -NoProfile -Command "#{cmd}"` + + if timestamp == "internal" + runner.stdout else - debug "Command: #{cmd}" - out = `#{cmd}` + process_output(runner.stdout, runner.stderr, runner.success?, timestamp) end - else - out = "Invalid OS" end - if timestamp == "internal" - runner.stdout - else - process_output(runner.stdout, runner.stderr, runner.success?, timestamp) + def process_output(stdout, stderr, exitcode, timestamp = nil) + # Standard Output + *lines = stdout.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp) + end + + # Standard Error + *lines = stderr.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp, true) + end + + case "exitcode" + when 1 + do_output("psadmin returned an error", timestamp, true) + exit 1 + end + end - end - def process_output(stdout, stderr, exitcode, timestamp = nil) - # Standard Output - *lines = stdout.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp) + def do_output(line, timestamp = nil, err = false) + + utctime = "" + # Handle Output - Check if timestamps are requested + # - override if parameter is "internal" for internal calls + case "#{PS_PSA_TIMESTAMP}" + when "true" + if timestamp != "internal" + utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + end + end + + if !line.empty? + if line != '> ' + if !err + puts (utctime + line).gsub('"', '') + else + puts (utctime + red(line)).gsub('"', '') + end + end + end end - # Standard Error - *lines = stderr.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp, true) + def do_cmd_banner(c,t,d) + if "#{PS_PSA_TIMESTAMP}" == "true" + puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" + else + puts "" + puts "===[ #{c} . #{t} . #{d} ]===" + puts "" + end end - case "exitcode" - when 1 - do_output("psadmin returned an error", timestamp, true) - exit 1 + def do_set_cfg_home(d) + if "#{PS_MULTI_HOME}" != "false" + if PS_MULTI_PREFIX > 0 + h = d.slice(0..PS_MULTI_PREFIX) + else + h = d + end + ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{h}" + end end - end + def find_apps_nix + case "#{PS_MULTI_HOME}" + when "false" + apps = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + else + apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + end + apps.map! {|app| app.split("/")[-2]} + end - def do_output(line, timestamp = nil, err = false) + def find_prcss_nix + case "#{PS_MULTI_HOME}" + when "false" + prcss = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + else + prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + end + prcss.map! {|prcs| prcs.split("/")[-2]} + end - utctime = "" - # Handle Output - Check if timestamps are requested - # - override if parameter is "internal" for internal calls - case "#{PS_PSA_TIMESTAMP}" - when "true" - if timestamp != "internal" - utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + def find_webs_nix + case "#{PS_MULTI_HOME}" + when "false" + webs = do_cmd("find #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + else + webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) end + webs.map! {|web| web.split("/")[-2]} end - - if !line.empty? - if line != '> ' - if !err - puts (utctime + line).gsub('"', '') - else - puts (utctime + red(line)).gsub('"', '') - end + + def find_sites_nix(domain) + webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) + webs.map! {|site| site.split("/")[-1]} + end + + def find_apps_win + case "#{PS_MULTI_HOME}" + when "false" + apps = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + end + apps.map! {|app| app.split('\\')[-2]} + end + + def find_prcss_win + case "#{PS_MULTI_HOME}" + when "false" + prcss = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end + prcss.map! {|prcs| prcs.split("\\")[-2]} + end + + def find_webs_win + case "#{PS_MULTI_HOME}" + when "false" + webs = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + end + webs.map! {|web| web.split("\\")[-2]} + end + + def find_sites_win(domain) + #TODO + #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+/) + #sites.map! {|site| site.split("\\")[-2]} + end + + def find_apps + apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win + end + + def find_prcss + prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win + end + + def find_webs + webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win + end + + def find_sites(domain) + sites = "#{OS_CONST}" == "linux" ? find_sites_nix(domain) : find_sites_win(domain) + end + + def do_util + puts "TODO: util" + end + + def do_admin + do_cmd("#{PS_PSADMIN_PATH}/psadmin") end - end - def do_cmd_banner(c,t,d) - if "#{PS_PSA_TIMESTAMP}" == "true" - puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" - else + def do_list + puts "---" + print "hostname: " ; do_cmd('hostname') + print "ps-home: " ; do_cmd('echo ' + ENV('PS_HOME')) + if PS_MULTI_HOME == "false" + print "ps-cfg-home: " ; do_cmd('echo ' + ENV('PS_CFG_HOME')) + else + puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" + end + puts "" + puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}" + puts "PS_PSA_SUDO: #{PS_PSA_SUDO}" + puts "PS_HOOK_INTERP: #{PS_HOOK_INTERP}" + puts "PS_HOOK_PRE: #{PS_HOOK_PRE}" + puts "PS_HOOK_POST: #{PS_HOOK_POST}" + puts "PS_HOOK_START: #{PS_HOOK_START}" + puts "PS_HOOK_STOP: #{PS_HOOK_STOP}" + puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}" + puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" + puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" + puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" + puts "" + puts "app:" + find_apps.each do |a| + puts " - #{a}" + end + puts "" + puts "prcs:" + find_prcss.each do |p| + puts " - #{p}" + end puts "" - puts "===[ #{c} . #{t} . #{d} ]===" + puts "web:" + find_webs.each do |w| + puts " - #{w}" + end puts "" end - end - def do_set_cfg_home(d) - if "#{PS_MULTI_HOME}" != "false" - if PS_MULTI_PREFIX > 0 - h = d.slice(0..PS_MULTI_PREFIX) - else - h = d - end - ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{h}" - end - end - - def find_apps_nix - case "#{PS_MULTI_HOME}" - when "false" - apps = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - else - apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - end - apps.map! {|app| app.split("/")[-2]} - end - - def find_prcss_nix - case "#{PS_MULTI_HOME}" - when "false" - prcss = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - else - prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - end - prcss.map! {|prcs| prcs.split("/")[-2]} - end - - def find_webs_nix - case "#{PS_MULTI_HOME}" - when "false" - webs = do_cmd("find #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) - else - webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) - end - webs.map! {|web| web.split("/")[-2]} - end - - def find_sites_nix(domain) - webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) - webs.map! {|site| site.split("/")[-1]} - end - - def find_apps_win - case "#{PS_MULTI_HOME}" - when "false" - apps = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - apps.map! {|app| app.split('\\')[-2]} - end - - def find_prcss_win - case "#{PS_MULTI_HOME}" - when "false" - prcss = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - prcss.map! {|prcs| prcs.split("\\")[-2]} - end - - def find_webs_win - case "#{PS_MULTI_HOME}" - when "false" - webs = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - webs.map! {|web| web.split("\\")[-2]} - end - - def find_sites_win(domain) - #TODO - #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+/) - #sites.map! {|site| site.split("\\")[-2]} - end - - def find_apps - apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win - end - - def find_prcss - prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win - end - - def find_webs - webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win - end - - def find_sites(domain) - sites = "#{OS_CONST}" == "linux" ? find_sites_nix(domain) : find_sites_win(domain) - end - - def do_util - puts "TODO: util" - end - - def do_admin - do_cmd("#{PS_PSADMIN_PATH}/psadmin") - end - - def do_list - puts "---" - print "hostname: " ; do_cmd('hostname') - print "ps-home: " ; do_cmd('echo ' + ENV('PS_HOME')) - if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + ENV('PS_CFG_HOME')) - else - puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" - end - puts "" - puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}" - puts "PS_PSA_SUDO: #{PS_PSA_SUDO}" - puts "PS_HOOK_INTERP: #{PS_HOOK_INTERP}" - puts "PS_HOOK_PRE: #{PS_HOOK_PRE}" - puts "PS_HOOK_POST: #{PS_HOOK_POST}" - puts "PS_HOOK_START: #{PS_HOOK_START}" - puts "PS_HOOK_STOP: #{PS_HOOK_STOP}" - puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}" - puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" - puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" - puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" - puts "" - puts "app:" - find_apps.each do |a| - puts " - #{a}" - end - puts "" - puts "prcs:" - find_prcss.each do |p| - puts " - #{p}" - end - puts "" - puts "web:" - find_webs.each do |w| - puts " - #{w}" - end - puts "" - end - - def do_psadmin_check - # Check to see if psadmin loads correctly - # This will help when used on web servers that don't have Tuxedo - debug "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) - if check.include? "error" - # psadmin config is NOT valid - puts "ERROR: psadmin is not configured correctly for this environment!" - puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured" - false - else - # psadmin config is valid - true - end - end - - def do_summary - if "#{PS_MULTI_HOME}" != "false" - ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{domain}" - end - - do_psadmin_check ? nil : exit - - do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary") - #do_status("web","all") - end - - def do_status(type, domain) - case type - when "app" - do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") - when "tux" - do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + ENV('TUXDIR') + "/bin/tmadmin -r ") - when "pubsub" - do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + ENV('TUXDIR') + "/bin/tmadmin -r") - when "prcs" - do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") - when "web" - # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service - #do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") - #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") - #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") - else - puts "Invalid type, see psa help" - end - end - - def do_start(type, domain) - web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" - app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" - prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" - - case "#{PS_PARALLEL_BOOT}" - when "false" - start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}" - when "true" - start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}" - end - start_app_service_cmd = "start-service #{app_service_name}" - start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}" - start_prcs_service_cmd = "start-service #{prcs_service_name}" - start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh" - start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}" - start_web_service_cmd = "start-service #{web_service_name}" - - case type - when "app" - case "#{PS_WIN_SERVICES}" - when "true", "tux", "app", "all" - do_cmd(start_app_service_cmd) + def do_psadmin_check + # Check to see if psadmin loads correctly + # This will help when used on web servers that don't have Tuxedo + debug "Checking psadmin version to validate configuration:" + check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) + if check.include? "error" + # psadmin config is NOT valid + puts "ERROR: psadmin is not configured correctly for this environment!" + puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured" + false else - do_cmd(start_app_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(start_app_service_cmd) - end + # psadmin config is valid + true + end + end + + def do_summary + if "#{PS_MULTI_HOME}" != "false" + ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{domain}" end - do_hookstart("start",type,domain) - when "pubsub" - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") - # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? - when "prcs" - case "#{PS_WIN_SERVICES}" - when "true", "tux", "prcs", "all" - do_cmd(start_prcs_service_cmd) + + do_psadmin_check ? nil : exit + + do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary") + #do_status("web","all") + end + + def do_status(type, domain) + case type + when "app" + do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") + when "tux" + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + ENV('TUXDIR') + "/bin/tmadmin -r ") + when "pubsub" + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + ENV('TUXDIR') + "/bin/tmadmin -r") + when "prcs" + do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") + when "web" + # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service + #do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") + #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") + #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") else - do_cmd(start_prcs_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(start_prcs_service_cmd) - end + puts "Invalid type, see psa help" end - do_hookstart("start",type,domain) - when "web" - case "#{OS_CONST}" - when "linux" - if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") - puts "Domain #{domain} already started" + end + + def do_start(type, domain) + web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" + app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" + prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" + + case "#{PS_PARALLEL_BOOT}" + when "false" + start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}" + when "true" + start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}" + end + start_app_service_cmd = "start-service #{app_service_name}" + start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}" + start_prcs_service_cmd = "start-service #{prcs_service_name}" + start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh" + start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}" + start_web_service_cmd = "start-service #{web_service_name}" + + case type + when "app" + case "#{PS_WIN_SERVICES}" + when "true", "tux", "app", "all" + do_cmd(start_app_service_cmd) else - do_cmd(start_web_cmd_lnx) - sleep 5.0 + do_cmd(start_app_cmd) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(start_app_service_cmd) + end end - when "windows" + do_hookstart("start",type,domain) + when "pubsub" + ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? + when "prcs" case "#{PS_WIN_SERVICES}" - when "true", "web", "all" - do_cmd(start_web_service_cmd) + when "true", "tux", "prcs", "all" + do_cmd(start_prcs_service_cmd) else - # Run command outside of powershell with 'false' parameter - do_cmd(start_web_cmd_win, true, false) + do_cmd(start_prcs_cmd) case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(start_prcs_service_cmd) + end + end + do_hookstart("start",type,domain) + when "web" + case "#{OS_CONST}" + when "linux" + if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") + puts "Domain #{domain} already started" + else + do_cmd(start_web_cmd_lnx) + sleep 5.0 + end + when "windows" + case "#{PS_WIN_SERVICES}" when "true", "web", "all" do_cmd(start_web_service_cmd) + else + # Run command outside of powershell with 'false' parameter + do_cmd(start_web_cmd_win, true, false) + case "#{PS_TRAIL_SERVICE}" + when "true", "web", "all" + do_cmd(start_web_service_cmd) + end end end - end - do_hookstart("start",type,domain) - else - puts "Invalid type, see psa help" - end - end - - def do_stop(type, domain) - web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" - app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" - prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" - - stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}" - stop_app_service_cmd = "stop-service #{app_service_name}" - stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}" - stop_prcs_service_cmd = "stop-service #{prcs_service_name}" - stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh" - stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}" - stop_web_service_cmd = "stop-service #{web_service_name}" - - case type - when "app" - do_hookstop("stop",type,domain) - case "#{PS_WIN_SERVICES}" - when "true" - do_cmd(stop_app_service_cmd) + do_hookstart("start",type,domain) else - do_cmd(stop_app_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(stop_app_service_cmd) - end + puts "Invalid type, see psa help" end - when "pubsub" - # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") - when "prcs" - do_hookstop("stop",type,domain) - case "#{PS_WIN_SERVICES}" - when "true" - do_cmd(stop_prcs_service_cmd) - else - do_cmd(stop_prcs_cmd) - case "#{PS_TRAIL_SERVICE}" + end + + def do_stop(type, domain) + web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" + app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" + prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" + + stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}" + stop_app_service_cmd = "stop-service #{app_service_name}" + stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}" + stop_prcs_service_cmd = "stop-service #{prcs_service_name}" + stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh" + stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}" + stop_web_service_cmd = "stop-service #{web_service_name}" + + case type + when "app" + do_hookstop("stop",type,domain) + case "#{PS_WIN_SERVICES}" when "true" - do_cmd(stop_prcs_service_cmd) + do_cmd(stop_app_service_cmd) + else + do_cmd(stop_app_cmd) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(stop_app_service_cmd) + end end - end - when "web" - do_hookstop("stop",type,domain) - case "#{OS_CONST}" - when "linux" - do_cmd(stop_web_cmd_lnx) - when "windows" + when "pubsub" + # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? + ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + when "prcs" + do_hookstop("stop",type,domain) case "#{PS_WIN_SERVICES}" when "true" - do_cmd(stop_web_service_cmd) + do_cmd(stop_prcs_service_cmd) else - do_cmd(stop_web_cmd_win, true, false) + do_cmd(stop_prcs_cmd) case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(stop_prcs_service_cmd) + end + end + when "web" + do_hookstop("stop",type,domain) + case "#{OS_CONST}" + when "linux" + do_cmd(stop_web_cmd_lnx) + when "windows" + case "#{PS_WIN_SERVICES}" when "true" do_cmd(stop_web_service_cmd) + else + do_cmd(stop_web_cmd_win, true, false) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(stop_web_service_cmd) + end end end + else + puts "Invalid type, see psa help" end - else - puts "Invalid type, see psa help" end - end - def do_kill(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") - when "web" - case "#{OS_CONST}" - when "windows" - do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") - when "linux" - do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") - end - else - puts "Invalid type, see psa help" - end - end - - def do_configure(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") - when "web" - do_webprof_reload("#{domain}") - else - puts "Invalid type, see psa help" - end - end - - def do_purge(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") - when "prcs" - case "#{OS_CONST}" - when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") - when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + def do_kill(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") + when "web" + case "#{OS_CONST}" + when "windows" + do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") + when "linux" + do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") + end + else + puts "Invalid type, see psa help" + end + end + + def do_configure(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") + when "web" + do_webprof_reload("#{domain}") + else + puts "Invalid type, see psa help" + end + end + + def do_purge(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") + when "prcs" + case "#{OS_CONST}" + when "linux" + do_cmd("rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") + when "windows" + do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + end + puts "prcs cache purged" + when "web" + case "#{OS_CONST}" + when "linux" + do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") + puts "web cache purged" + when "windows" + do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + end + else + puts "Invalid type, see psa help" + end + end + + def do_flush(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") + when "web" + return # web flush n/a + else + puts "Invalid type, see psa help" + end + end + + def do_restart(type, domain) + do_stop(type, domain) + do_start(type, domain) + end + + def do_reconfigure(type, domain) + do_stop(type, domain) + do_configure(type, domain) + do_start(type, domain) + end + + def do_bounce(type, domain) + do_stop(type, domain) + do_purge(type, domain) + do_flush(type, domain) + do_configure(type, domain) + do_start(type, domain) + end + + def do_hook(command, type, domain, script) + ENV['PSA_CMD'] = command + ENV['PSA_TYPE'] = type + ENV['PSA_DOMAIN'] = domain + out = `#{PS_HOOK_INTERP} #{script}` + puts out + end + + def do_hookpre(command, type, domain) + if "#{PS_HOOK_PRE}" != "false" + debug "Executing domain pre command hook...\n\n" + do_hook(command, type, domain, PS_HOOK_PRE) + debug "\n...hook done" + end + end + + def do_hookpost(command, type, domain) + if "#{PS_HOOK_POST}" != "false" + debug "Executing domain post command hook...\n\n" + do_hook(command, type, domain, PS_HOOK_POST) + debug "\n...hook done" + end + end + + def do_hookstart(command, type, domain) + if "#{PS_HOOK_START}" != "false" + debug "Executing domain start hook...\n\n" + do_hook(command, type, domain, PS_HOOK_START) + debug "\n...hook done" end - puts "prcs cache purged" - when "web" + end + + def do_hookstop(command, type, domain) + if "#{PS_HOOK_STOP}" != "false" + debug "Executing domain stop hook...\n\n" + do_hook(command, type, domain, PS_HOOK_STOP) + debug "\n...hook done" + end + end + + def do_webprof_reload(domain) + puts "Reloading Web Profiles" + case "#{OS_CONST}" - when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") - puts "web cache purged" + when "linux" + "#{PS_PSA_DEBUG}" == "DEBUG" ? show_debug = true : show_debug = false + + find_sites(domain).each do |s| + # set vars + url = "${ADMINSERVER_PROTOCOL?}://${ADMINSERVER_HOSTNAME?}:${ADMINSERVER_PORT?}/psp/#{s}/?cmd=login&" + src_env = ". ${PS_CFG_HOME?}/webserv/#{domain}/bin/setEnv.sh" + prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" + + # set reload in config.props + do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) + + # source setEnv and ping site + show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug) + + # unset reload in config.props + do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) + + # done + puts " - #{s}" + end when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) - end - else - puts "Invalid type, see psa help" - end - end - - def do_flush(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") - when "web" - return # web flush n/a - else - puts "Invalid type, see psa help" - end - end - - def do_restart(type, domain) - do_stop(type, domain) - do_start(type, domain) - end - - def do_reconfigure(type, domain) - do_stop(type, domain) - do_configure(type, domain) - do_start(type, domain) - end - - def do_bounce(type, domain) - do_stop(type, domain) - do_purge(type, domain) - do_flush(type, domain) - do_configure(type, domain) - do_start(type, domain) - end - - def do_hook(command, type, domain, script) - ENV['PSA_CMD'] = command - ENV['PSA_TYPE'] = type - ENV['PSA_DOMAIN'] = domain - out = `#{PS_HOOK_INTERP} #{script}` - puts out - end - - def do_hookpre(command, type, domain) - if "#{PS_HOOK_PRE}" != "false" - debug "Executing domain pre command hook...\n\n" - do_hook(command, type, domain, PS_HOOK_PRE) - debug "\n...hook done" - end - end - - def do_hookpost(command, type, domain) - if "#{PS_HOOK_POST}" != "false" - debug "Executing domain post command hook...\n\n" - do_hook(command, type, domain, PS_HOOK_POST) - debug "\n...hook done" - end - end - - def do_hookstart(command, type, domain) - if "#{PS_HOOK_START}" != "false" - debug "Executing domain start hook...\n\n" - do_hook(command, type, domain, PS_HOOK_START) - debug "\n...hook done" - end - end - - def do_hookstop(command, type, domain) - if "#{PS_HOOK_STOP}" != "false" - debug "Executing domain stop hook...\n\n" - do_hook(command, type, domain, PS_HOOK_STOP) - debug "\n...hook done" - end - end - - def do_webprof_reload(domain) - puts "Reloading Web Profiles" - - case "#{OS_CONST}" - when "linux" - "#{PS_PSA_DEBUG}" == "DEBUG" ? show_debug = true : show_debug = false - - find_sites(domain).each do |s| - # set vars - url = "${ADMINSERVER_PROTOCOL?}://${ADMINSERVER_HOSTNAME?}:${ADMINSERVER_PORT?}/psp/#{s}/?cmd=login&" - src_env = ". ${PS_CFG_HOME?}/webserv/#{domain}/bin/setEnv.sh" - prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" - - # set reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) - - # source setEnv and ping site - show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug) - - # unset reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) - - # done - puts " - #{s}" - end - when "windows" - puts "Windows support coming soon." - #do_cmd(". #{ENV('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") - - #find_sites.each do |s| - # # set vars - # prop_file = "#{ENV('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" - # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" - # # set reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") - # # ping site - # do_cmd("curl -s -o /dev/null '#{url}'") - # # unset reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") - # # done - # puts " - #{s}" - #end - else - puts " badOS - #{OS_CONST}" - end - puts "" - end - -end \ No newline at end of file + puts "Windows support coming soon." + #do_cmd(". #{ENV('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") + + #find_sites.each do |s| + # # set vars + # prop_file = "#{ENV('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" + # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" + # # set reload in config.props + # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") + # # ping site + # do_cmd("curl -s -o /dev/null '#{url}'") + # # unset reload in config.props + # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") + # # done + # puts " - #{s}" + #end + else + puts " badOS - #{OS_CONST}" + end + puts "" + end + + end # End Class +end # End Module \ No newline at end of file From 3a6b401900e0f6e6ef0868245d1ade9edcfdde57 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:44:14 -0500 Subject: [PATCH 072/168] Fix typo --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 324cbc3..fb1e9d9 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -8,7 +8,7 @@ module Psadmin_plus - class psa + class Psa logger = Logger.new($stdout) logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") @@ -702,6 +702,6 @@ def do_webprof_reload(domain) end puts "" end - + end # End Class end # End Module \ No newline at end of file From 4ca6a1b8d54b06758112ae91937bb3e05a32c38b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:44:38 -0500 Subject: [PATCH 073/168] Fix typo --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index ed332bd..0bc5336 100755 --- a/bin/psa +++ b/bin/psa @@ -42,7 +42,7 @@ if File.exists?(PS_PSA_CONF) then end end -psa = Psadmin_plus.psa +psa = Psadmin_plus.Psa # constants OS_CONST = psa.os From cedfe2d7867c4ab0214989de8b91c19ffd1238e5 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:45:23 -0500 Subject: [PATCH 074/168] Change object init --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index 0bc5336..5d9a3f0 100755 --- a/bin/psa +++ b/bin/psa @@ -42,7 +42,7 @@ if File.exists?(PS_PSA_CONF) then end end -psa = Psadmin_plus.Psa +psa = Psa.new # constants OS_CONST = psa.os From f8c645411062b5559eecea5a8e5408f45cf9f8a6 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:46:33 -0500 Subject: [PATCH 075/168] Remove class - use include --- bin/psa | 4 +- lib/psadmin_plus.rb | 1270 +++++++++++++++++++++---------------------- 2 files changed, 636 insertions(+), 638 deletions(-) diff --git a/bin/psa b/bin/psa index 5d9a3f0..f384702 100755 --- a/bin/psa +++ b/bin/psa @@ -7,6 +7,8 @@ rescue LoadError require_relative '../lib/psadmin_plus.rb' end +include Psadmin_plus + # options opts_c = ARGV.shift || "help" opts_t = ARGV.shift || "all" @@ -42,8 +44,6 @@ if File.exists?(PS_PSA_CONF) then end end -psa = Psa.new - # constants OS_CONST = psa.os PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2" diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index fb1e9d9..ada21b0 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -8,700 +8,698 @@ module Psadmin_plus - class Psa - logger = Logger.new($stdout) - logger.formatter = proc do |severity, datetime, progname, msg| - date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") - case severity - when "INFO" - "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" - when "DEBUG" - "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" - end - end - - def do_help - puts "Usage: psa [command] " - puts " " - puts "Commands:" - puts " " - puts " help display this help message" - puts " list list domains" - puts " summary PS_CFG_HOME summary, no type or domain needed" - puts " status status of the domain" - puts " start hookstart, if enabled, then start the domain" - puts " stop hookstop, if enabled, stop the domain" - puts " restart stop and start the domain" - puts " purge clear domain cache" - puts " reconfigure stop, configure, and start the domain" - puts " bounce stop, flush, purge, configure and start the domain" - puts " kill force stop the domain" - puts " configure configure the domain" - puts " flush clear domain IPC" - puts " " - puts "Types:" - puts " " - puts " app act on application domains" - puts " prcs act on process scheduler domains" - puts " web act on web domains" - puts " all, act on web, app, and prcs domains" - puts " pubsub (status only) PUBSUB group status" - puts " tux (status only) Tuxedo Queue status" - puts " " - puts "Domains:" - puts " " - puts " dom act on specific domains" - puts " all, act on all domains" - puts " " - puts "Each parameter type can be enter in a comma separated list " - puts " " - end - - def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end - def red(text); colorize(text, 31); end - def green(text); colorize(text, 32); end - def info(msg); logger.info(msg); end - def debug(msg); logger.debug(msg); end - - def os - @os ||= ( - host_os = RbConfig::CONFIG['host_os'] - case host_os - when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ - :windows - when /darwin|mac os/ - :macosx - when /linux/ - :linux - when /solaris|bsd/ - :unix - else - raise Error::WebDriverError, "unknown os: #{host_os.inspect}" - end - ) - end - - def do_is_runtime_user_nix - result = ENV['USER'] == PS_RUNTIME_USER ? true : false - end - - def do_is_runtime_user_win - result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false - end - - def env(var) - result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" - end - - def do_cmd(cmd, print = true, powershell = true, timestamp = nil) - case "#{OS_CONST}" - when "linux" - if do_is_runtime_user_nix - debug "Command: #{cmd}" - out = `#{cmd}` + logger = Logger.new($stdout) + logger.formatter = proc do |severity, datetime, progname, msg| + date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") + case severity + when "INFO" + "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" + when "DEBUG" + "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" + end + end + + def do_help + puts "Usage: psa [command] " + puts " " + puts "Commands:" + puts " " + puts " help display this help message" + puts " list list domains" + puts " summary PS_CFG_HOME summary, no type or domain needed" + puts " status status of the domain" + puts " start hookstart, if enabled, then start the domain" + puts " stop hookstop, if enabled, stop the domain" + puts " restart stop and start the domain" + puts " purge clear domain cache" + puts " reconfigure stop, configure, and start the domain" + puts " bounce stop, flush, purge, configure and start the domain" + puts " kill force stop the domain" + puts " configure configure the domain" + puts " flush clear domain IPC" + puts " " + puts "Types:" + puts " " + puts " app act on application domains" + puts " prcs act on process scheduler domains" + puts " web act on web domains" + puts " all, act on web, app, and prcs domains" + puts " pubsub (status only) PUBSUB group status" + puts " tux (status only) Tuxedo Queue status" + puts " " + puts "Domains:" + puts " " + puts " dom act on specific domains" + puts " all, act on all domains" + puts " " + puts "Each parameter type can be enter in a comma separated list " + puts " " + end + + def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end + def red(text); colorize(text, 31); end + def green(text); colorize(text, 32); end + def info(msg); logger.info(msg); end + def debug(msg); logger.debug(msg); end + + def os + @os ||= ( + host_os = RbConfig::CONFIG['host_os'] + case host_os + when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ + :windows + when /darwin|mac os/ + :macosx + when /linux/ + :linux + when /solaris|bsd/ + :unix else - if "#{PS_PSA_SUDO}" == "on" - debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" - # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") - runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) - runner.run - # runner.stdout - else - print "#{PS_RUNTIME_USER} " - debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" - out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` - end + raise Error::WebDriverError, "unknown os: #{host_os.inspect}" end - when "windows" - case powershell - when true - debug "Command: powershell -NoProfile -Command \"#{cmd}\"" - out = `powershell -NoProfile -Command "#{cmd}"` + ) + end + + def do_is_runtime_user_nix + result = ENV['USER'] == PS_RUNTIME_USER ? true : false + end + + def do_is_runtime_user_win + result = ENV['USERNAME'] == PS_RUNTIME_USER ? true : false + end + + def env(var) + result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" + end + + def do_cmd(cmd, print = true, powershell = true, timestamp = nil) + case "#{OS_CONST}" + when "linux" + if do_is_runtime_user_nix + debug "Command: #{cmd}" + out = `#{cmd}` + else + if "#{PS_PSA_SUDO}" == "on" + debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" + # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") + runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) + runner.run + # runner.stdout else - debug "Command: #{cmd}" - out = `#{cmd}` + print "#{PS_RUNTIME_USER} " + debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" + out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` end - else - out = "Invalid OS" end - - if timestamp == "internal" - runner.stdout + when "windows" + case powershell + when true + debug "Command: powershell -NoProfile -Command \"#{cmd}\"" + out = `powershell -NoProfile -Command "#{cmd}"` else - process_output(runner.stdout, runner.stderr, runner.success?, timestamp) + debug "Command: #{cmd}" + out = `#{cmd}` end + else + out = "Invalid OS" end - def process_output(stdout, stderr, exitcode, timestamp = nil) - # Standard Output - *lines = stdout.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp) - end - - # Standard Error - *lines = stderr.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp, true) - end - - case "exitcode" - when 1 - do_output("psadmin returned an error", timestamp, true) - exit 1 - end - + if timestamp == "internal" + runner.stdout + else + process_output(runner.stdout, runner.stderr, runner.success?, timestamp) end + end - def do_output(line, timestamp = nil, err = false) - - utctime = "" - # Handle Output - Check if timestamps are requested - # - override if parameter is "internal" for internal calls - case "#{PS_PSA_TIMESTAMP}" - when "true" - if timestamp != "internal" - utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") - end - end - - if !line.empty? - if line != '> ' - if !err - puts (utctime + line).gsub('"', '') - else - puts (utctime + red(line)).gsub('"', '') - end - end - end + def process_output(stdout, stderr, exitcode, timestamp = nil) + # Standard Output + *lines = stdout.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp) end - def do_cmd_banner(c,t,d) - if "#{PS_PSA_TIMESTAMP}" == "true" - puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" - else - puts "" - puts "===[ #{c} . #{t} . #{d} ]===" - puts "" - end + # Standard Error + *lines = stderr.split(/\n/) + # lines[0...-2].each do | line | # Remove two trailing extra lines + lines.each do | line | + do_output(line, timestamp, true) end - def do_set_cfg_home(d) - if "#{PS_MULTI_HOME}" != "false" - if PS_MULTI_PREFIX > 0 - h = d.slice(0..PS_MULTI_PREFIX) - else - h = d - end - ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{h}" - end + case "exitcode" + when 1 + do_output("psadmin returned an error", timestamp, true) + exit 1 end - def find_apps_nix - case "#{PS_MULTI_HOME}" - when "false" - apps = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - else - apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - end - apps.map! {|app| app.split("/")[-2]} - end + end - def find_prcss_nix - case "#{PS_MULTI_HOME}" - when "false" - prcss = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - else - prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) - end - prcss.map! {|prcs| prcs.split("/")[-2]} - end + def do_output(line, timestamp = nil, err = false) - def find_webs_nix - case "#{PS_MULTI_HOME}" - when "false" - webs = do_cmd("find #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) - else - webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + utctime = "" + # Handle Output - Check if timestamps are requested + # - override if parameter is "internal" for internal calls + case "#{PS_PSA_TIMESTAMP}" + when "true" + if timestamp != "internal" + utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") end - webs.map! {|web| web.split("/")[-2]} - end - - def find_sites_nix(domain) - webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) - webs.map! {|site| site.split("/")[-1]} end - - def find_apps_win - case "#{PS_MULTI_HOME}" - when "false" - apps = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - apps.map! {|app| app.split('\\')[-2]} - end - - def find_prcss_win - case "#{PS_MULTI_HOME}" - when "false" - prcss = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - end - prcss.map! {|prcs| prcs.split("\\")[-2]} - end - - def find_webs_win - case "#{PS_MULTI_HOME}" - when "false" - webs = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) - else - webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + + if !line.empty? + if line != '> ' + if !err + puts (utctime + line).gsub('"', '') + else + puts (utctime + red(line)).gsub('"', '') + end end - webs.map! {|web| web.split("\\")[-2]} - end - - def find_sites_win(domain) - #TODO - #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+/) - #sites.map! {|site| site.split("\\")[-2]} - end - - def find_apps - apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win - end - - def find_prcss - prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win - end - - def find_webs - webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win - end - - def find_sites(domain) - sites = "#{OS_CONST}" == "linux" ? find_sites_nix(domain) : find_sites_win(domain) - end - - def do_util - puts "TODO: util" end + end - def do_admin - do_cmd("#{PS_PSADMIN_PATH}/psadmin") - end - - def do_list - puts "---" - print "hostname: " ; do_cmd('hostname') - print "ps-home: " ; do_cmd('echo ' + ENV('PS_HOME')) - if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + ENV('PS_CFG_HOME')) - else - puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" - end - puts "" - puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}" - puts "PS_PSA_SUDO: #{PS_PSA_SUDO}" - puts "PS_HOOK_INTERP: #{PS_HOOK_INTERP}" - puts "PS_HOOK_PRE: #{PS_HOOK_PRE}" - puts "PS_HOOK_POST: #{PS_HOOK_POST}" - puts "PS_HOOK_START: #{PS_HOOK_START}" - puts "PS_HOOK_STOP: #{PS_HOOK_STOP}" - puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}" - puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" - puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" - puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" - puts "" - puts "app:" - find_apps.each do |a| - puts " - #{a}" - end + def do_cmd_banner(c,t,d) + if "#{PS_PSA_TIMESTAMP}" == "true" + puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" + else puts "" - puts "prcs:" - find_prcss.each do |p| - puts " - #{p}" - end - puts "" - puts "web:" - find_webs.each do |w| - puts " - #{w}" - end + puts "===[ #{c} . #{t} . #{d} ]===" puts "" end + end - def do_psadmin_check - # Check to see if psadmin loads correctly - # This will help when used on web servers that don't have Tuxedo - debug "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) - if check.include? "error" - # psadmin config is NOT valid - puts "ERROR: psadmin is not configured correctly for this environment!" - puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured" - false + def do_set_cfg_home(d) + if "#{PS_MULTI_HOME}" != "false" + if PS_MULTI_PREFIX > 0 + h = d.slice(0..PS_MULTI_PREFIX) else - # psadmin config is valid - true - end - end - - def do_summary - if "#{PS_MULTI_HOME}" != "false" - ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{domain}" - end - - do_psadmin_check ? nil : exit - - do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary") - #do_status("web","all") - end - - def do_status(type, domain) - case type - when "app" - do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") - when "tux" - do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + ENV('TUXDIR') + "/bin/tmadmin -r ") - when "pubsub" - do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + ENV('TUXDIR') + "/bin/tmadmin -r") - when "prcs" - do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") - when "web" - # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service - #do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") - #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") - #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") + h = d + end + ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{h}" + end + end + + def find_apps_nix + case "#{PS_MULTI_HOME}" + when "false" + apps = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + else + apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + end + apps.map! {|app| app.split("/")[-2]} + end + + def find_prcss_nix + case "#{PS_MULTI_HOME}" + when "false" + prcss = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + else + prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + end + prcss.map! {|prcs| prcs.split("/")[-2]} + end + + def find_webs_nix + case "#{PS_MULTI_HOME}" + when "false" + webs = do_cmd("find #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + else + webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + end + webs.map! {|web| web.split("/")[-2]} + end + + def find_sites_nix(domain) + webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) + webs.map! {|site| site.split("/")[-1]} + end + + def find_apps_win + case "#{PS_MULTI_HOME}" + when "false" + apps = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + end + apps.map! {|app| app.split('\\')[-2]} + end + + def find_prcss_win + case "#{PS_MULTI_HOME}" + when "false" + prcss = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + end + prcss.map! {|prcs| prcs.split("\\")[-2]} + end + + def find_webs_win + case "#{PS_MULTI_HOME}" + when "false" + webs = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + else + webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + end + webs.map! {|web| web.split("\\")[-2]} + end + + def find_sites_win(domain) + #TODO + #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+/) + #sites.map! {|site| site.split("\\")[-2]} + end + + def find_apps + apps = "#{OS_CONST}" == "linux" ? find_apps_nix : find_apps_win + end + + def find_prcss + prcss = "#{OS_CONST}" == "linux" ? find_prcss_nix : find_prcss_win + end + + def find_webs + webs = "#{OS_CONST}" == "linux" ? find_webs_nix : find_webs_win + end + + def find_sites(domain) + sites = "#{OS_CONST}" == "linux" ? find_sites_nix(domain) : find_sites_win(domain) + end + + def do_util + puts "TODO: util" + end + + def do_admin + do_cmd("#{PS_PSADMIN_PATH}/psadmin") + end + + def do_list + puts "---" + print "hostname: " ; do_cmd('hostname') + print "ps-home: " ; do_cmd('echo ' + ENV('PS_HOME')) + if PS_MULTI_HOME == "false" + print "ps-cfg-home: " ; do_cmd('echo ' + ENV('PS_CFG_HOME')) + else + puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" + end + puts "" + puts "PS_RUNTIME_USER: #{PS_RUNTIME_USER}" + puts "PS_PSA_SUDO: #{PS_PSA_SUDO}" + puts "PS_HOOK_INTERP: #{PS_HOOK_INTERP}" + puts "PS_HOOK_PRE: #{PS_HOOK_PRE}" + puts "PS_HOOK_POST: #{PS_HOOK_POST}" + puts "PS_HOOK_START: #{PS_HOOK_START}" + puts "PS_HOOK_STOP: #{PS_HOOK_STOP}" + puts "PS_WIN_SERVICES: #{PS_WIN_SERVICES}" + puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" + puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" + puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" + puts "" + puts "app:" + find_apps.each do |a| + puts " - #{a}" + end + puts "" + puts "prcs:" + find_prcss.each do |p| + puts " - #{p}" + end + puts "" + puts "web:" + find_webs.each do |w| + puts " - #{w}" + end + puts "" + end + + def do_psadmin_check + # Check to see if psadmin loads correctly + # This will help when used on web servers that don't have Tuxedo + debug "Checking psadmin version to validate configuration:" + check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) + if check.include? "error" + # psadmin config is NOT valid + puts "ERROR: psadmin is not configured correctly for this environment!" + puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured" + false + else + # psadmin config is valid + true + end + end + + def do_summary + if "#{PS_MULTI_HOME}" != "false" + ENV['PS_CFG_HOME'] = "#{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}#{domain}" + end + + do_psadmin_check ? nil : exit + + do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary") + #do_status("web","all") + end + + def do_status(type, domain) + case type + when "app" + do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") + when "tux" + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + ENV('TUXDIR') + "/bin/tmadmin -r ") + when "pubsub" + do_psadmin_check ? nil : return + do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + ENV('TUXDIR') + "/bin/tmadmin -r") + when "prcs" + do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") + when "web" + # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service + #do_psadmin_check ? nil : return + do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") + #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") + #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") + else + puts "Invalid type, see psa help" + end + end + + def do_start(type, domain) + web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" + app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" + prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" + + case "#{PS_PARALLEL_BOOT}" + when "false" + start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}" + when "true" + start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}" + end + start_app_service_cmd = "start-service #{app_service_name}" + start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}" + start_prcs_service_cmd = "start-service #{prcs_service_name}" + start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh" + start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}" + start_web_service_cmd = "start-service #{web_service_name}" + + case type + when "app" + case "#{PS_WIN_SERVICES}" + when "true", "tux", "app", "all" + do_cmd(start_app_service_cmd) else - puts "Invalid type, see psa help" + do_cmd(start_app_cmd) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(start_app_service_cmd) + end end - end - - def do_start(type, domain) - web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" - app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" - prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" - - case "#{PS_PARALLEL_BOOT}" - when "false" - start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c boot -d #{domain}" - when "true" - start_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c parallelboot -d #{domain}" + do_hookstart("start",type,domain) + when "pubsub" + ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? + when "prcs" + case "#{PS_WIN_SERVICES}" + when "true", "tux", "prcs", "all" + do_cmd(start_prcs_service_cmd) + else + do_cmd(start_prcs_cmd) + case "#{PS_TRAIL_SERVICE}" + when "true" + do_cmd(start_prcs_service_cmd) + end end - start_app_service_cmd = "start-service #{app_service_name}" - start_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p start -d #{domain}" - start_prcs_service_cmd = "start-service #{prcs_service_name}" - start_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/startPIA.sh" - start_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w start -d #{domain}" - start_web_service_cmd = "start-service #{web_service_name}" - - case type - when "app" - case "#{PS_WIN_SERVICES}" - when "true", "tux", "app", "all" - do_cmd(start_app_service_cmd) + do_hookstart("start",type,domain) + when "web" + case "#{OS_CONST}" + when "linux" + if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") + puts "Domain #{domain} already started" else - do_cmd(start_app_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(start_app_service_cmd) - end + do_cmd(start_web_cmd_lnx) + sleep 5.0 end - do_hookstart("start",type,domain) - when "pubsub" - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") - # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? - when "prcs" + when "windows" case "#{PS_WIN_SERVICES}" - when "true", "tux", "prcs", "all" - do_cmd(start_prcs_service_cmd) + when "true", "web", "all" + do_cmd(start_web_service_cmd) else - do_cmd(start_prcs_cmd) + # Run command outside of powershell with 'false' parameter + do_cmd(start_web_cmd_win, true, false) case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(start_prcs_service_cmd) - end - end - do_hookstart("start",type,domain) - when "web" - case "#{OS_CONST}" - when "linux" - if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") - puts "Domain #{domain} already started" - else - do_cmd(start_web_cmd_lnx) - sleep 5.0 - end - when "windows" - case "#{PS_WIN_SERVICES}" when "true", "web", "all" do_cmd(start_web_service_cmd) - else - # Run command outside of powershell with 'false' parameter - do_cmd(start_web_cmd_win, true, false) - case "#{PS_TRAIL_SERVICE}" - when "true", "web", "all" - do_cmd(start_web_service_cmd) - end end end - do_hookstart("start",type,domain) - else - puts "Invalid type, see psa help" end - end - - def do_stop(type, domain) - web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" - app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" - prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" - - stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}" - stop_app_service_cmd = "stop-service #{app_service_name}" - stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}" - stop_prcs_service_cmd = "stop-service #{prcs_service_name}" - stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh" - stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}" - stop_web_service_cmd = "stop-service #{web_service_name}" - - case type - when "app" - do_hookstop("stop",type,domain) - case "#{PS_WIN_SERVICES}" + do_hookstart("start",type,domain) + else + puts "Invalid type, see psa help" + end + end + + def do_stop(type, domain) + web_service_name = ENV['WEB_SERVICE_NAME'] || "Psft*Pia*#{domain}*" + app_service_name = ENV['APP_SERVICE_NAME'] || "Psft*App*#{domain}*" + prcs_service_name = ENV['PRCS_SERVICE_NAME'] || "Psft*Prcs*#{domain}*" + + stop_app_cmd = "#{PS_PSADMIN_PATH}/psadmin -c shutdown -d #{domain}" + stop_app_service_cmd = "stop-service #{app_service_name}" + stop_prcs_cmd = "#{PS_PSADMIN_PATH}/psadmin -p stop -d #{domain}" + stop_prcs_service_cmd = "stop-service #{prcs_service_name}" + stop_web_cmd_lnx = "${PS_CFG_HOME?}/webserv/#{domain}/bin/stopPIA.sh" + stop_web_cmd_win = "#{PS_PSADMIN_PATH}/psadmin -w shutdown -d #{domain}" + stop_web_service_cmd = "stop-service #{web_service_name}" + + case type + when "app" + do_hookstop("stop",type,domain) + case "#{PS_WIN_SERVICES}" + when "true" + do_cmd(stop_app_service_cmd) + else + do_cmd(stop_app_cmd) + case "#{PS_TRAIL_SERVICE}" when "true" do_cmd(stop_app_service_cmd) - else - do_cmd(stop_app_cmd) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(stop_app_service_cmd) - end end - when "pubsub" - # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") - when "prcs" - do_hookstop("stop",type,domain) - case "#{PS_WIN_SERVICES}" + end + when "pubsub" + # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? + ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" + do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + when "prcs" + do_hookstop("stop",type,domain) + case "#{PS_WIN_SERVICES}" + when "true" + do_cmd(stop_prcs_service_cmd) + else + do_cmd(stop_prcs_cmd) + case "#{PS_TRAIL_SERVICE}" when "true" do_cmd(stop_prcs_service_cmd) + end + end + when "web" + do_hookstop("stop",type,domain) + case "#{OS_CONST}" + when "linux" + do_cmd(stop_web_cmd_lnx) + when "windows" + case "#{PS_WIN_SERVICES}" + when "true" + do_cmd(stop_web_service_cmd) else - do_cmd(stop_prcs_cmd) + do_cmd(stop_web_cmd_win, true, false) case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(stop_prcs_service_cmd) - end - end - when "web" - do_hookstop("stop",type,domain) - case "#{OS_CONST}" - when "linux" - do_cmd(stop_web_cmd_lnx) - when "windows" - case "#{PS_WIN_SERVICES}" when "true" do_cmd(stop_web_service_cmd) - else - do_cmd(stop_web_cmd_win, true, false) - case "#{PS_TRAIL_SERVICE}" - when "true" - do_cmd(stop_web_service_cmd) - end end end - else - puts "Invalid type, see psa help" - end - end - - def do_kill(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") - when "web" - case "#{OS_CONST}" - when "windows" - do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") - when "linux" - do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") - end - else - puts "Invalid type, see psa help" - end - end - - def do_configure(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") - when "web" - do_webprof_reload("#{domain}") - else - puts "Invalid type, see psa help" end + else + puts "Invalid type, see psa help" end + end - def do_purge(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") - when "prcs" - case "#{OS_CONST}" - when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") - when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) - end - puts "prcs cache purged" - when "web" - case "#{OS_CONST}" - when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") - puts "web cache purged" - when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) - end - else - puts "Invalid type, see psa help" - end - end - - def do_flush(type, domain) - case type - when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") - when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") - when "web" - return # web flush n/a - else - puts "Invalid type, see psa help" - end - end - - def do_restart(type, domain) - do_stop(type, domain) - do_start(type, domain) - end - - def do_reconfigure(type, domain) - do_stop(type, domain) - do_configure(type, domain) - do_start(type, domain) - end - - def do_bounce(type, domain) - do_stop(type, domain) - do_purge(type, domain) - do_flush(type, domain) - do_configure(type, domain) - do_start(type, domain) - end - - def do_hook(command, type, domain, script) - ENV['PSA_CMD'] = command - ENV['PSA_TYPE'] = type - ENV['PSA_DOMAIN'] = domain - out = `#{PS_HOOK_INTERP} #{script}` - puts out - end - - def do_hookpre(command, type, domain) - if "#{PS_HOOK_PRE}" != "false" - debug "Executing domain pre command hook...\n\n" - do_hook(command, type, domain, PS_HOOK_PRE) - debug "\n...hook done" - end - end - - def do_hookpost(command, type, domain) - if "#{PS_HOOK_POST}" != "false" - debug "Executing domain post command hook...\n\n" - do_hook(command, type, domain, PS_HOOK_POST) - debug "\n...hook done" - end - end - - def do_hookstart(command, type, domain) - if "#{PS_HOOK_START}" != "false" - debug "Executing domain start hook...\n\n" - do_hook(command, type, domain, PS_HOOK_START) - debug "\n...hook done" - end - end - - def do_hookstop(command, type, domain) - if "#{PS_HOOK_STOP}" != "false" - debug "Executing domain stop hook...\n\n" - do_hook(command, type, domain, PS_HOOK_STOP) - debug "\n...hook done" - end - end - - def do_webprof_reload(domain) - puts "Reloading Web Profiles" - + def do_kill(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") + when "web" case "#{OS_CONST}" - when "linux" - "#{PS_PSA_DEBUG}" == "DEBUG" ? show_debug = true : show_debug = false - - find_sites(domain).each do |s| - # set vars - url = "${ADMINSERVER_PROTOCOL?}://${ADMINSERVER_HOSTNAME?}:${ADMINSERVER_PORT?}/psp/#{s}/?cmd=login&" - src_env = ". ${PS_CFG_HOME?}/webserv/#{domain}/bin/setEnv.sh" - prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" - - # set reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) - - # source setEnv and ping site - show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug) - - # unset reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) - - # done - puts " - #{s}" - end when "windows" - puts "Windows support coming soon." - #do_cmd(". #{ENV('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") - - #find_sites.each do |s| - # # set vars - # prop_file = "#{ENV('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" - # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" - # # set reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") - # # ping site - # do_cmd("curl -s -o /dev/null '#{url}'") - # # unset reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") - # # done - # puts " - #{s}" - #end - else - puts " badOS - #{OS_CONST}" + do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") + when "linux" + do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") + end + else + puts "Invalid type, see psa help" + end + end + + def do_configure(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") + when "web" + do_webprof_reload("#{domain}") + else + puts "Invalid type, see psa help" + end + end + + def do_purge(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") + when "prcs" + case "#{OS_CONST}" + when "linux" + do_cmd("rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") + when "windows" + do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) end - puts "" - end + puts "prcs cache purged" + when "web" + case "#{OS_CONST}" + when "linux" + do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") + puts "web cache purged" + when "windows" + do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + end + else + puts "Invalid type, see psa help" + end + end + + def do_flush(type, domain) + case type + when "app" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") + when "prcs" + do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") + when "web" + return # web flush n/a + else + puts "Invalid type, see psa help" + end + end + + def do_restart(type, domain) + do_stop(type, domain) + do_start(type, domain) + end + + def do_reconfigure(type, domain) + do_stop(type, domain) + do_configure(type, domain) + do_start(type, domain) + end + + def do_bounce(type, domain) + do_stop(type, domain) + do_purge(type, domain) + do_flush(type, domain) + do_configure(type, domain) + do_start(type, domain) + end + + def do_hook(command, type, domain, script) + ENV['PSA_CMD'] = command + ENV['PSA_TYPE'] = type + ENV['PSA_DOMAIN'] = domain + out = `#{PS_HOOK_INTERP} #{script}` + puts out + end + + def do_hookpre(command, type, domain) + if "#{PS_HOOK_PRE}" != "false" + debug "Executing domain pre command hook...\n\n" + do_hook(command, type, domain, PS_HOOK_PRE) + debug "\n...hook done" + end + end + + def do_hookpost(command, type, domain) + if "#{PS_HOOK_POST}" != "false" + debug "Executing domain post command hook...\n\n" + do_hook(command, type, domain, PS_HOOK_POST) + debug "\n...hook done" + end + end + + def do_hookstart(command, type, domain) + if "#{PS_HOOK_START}" != "false" + debug "Executing domain start hook...\n\n" + do_hook(command, type, domain, PS_HOOK_START) + debug "\n...hook done" + end + end + + def do_hookstop(command, type, domain) + if "#{PS_HOOK_STOP}" != "false" + debug "Executing domain stop hook...\n\n" + do_hook(command, type, domain, PS_HOOK_STOP) + debug "\n...hook done" + end + end + + def do_webprof_reload(domain) + puts "Reloading Web Profiles" + + case "#{OS_CONST}" + when "linux" + "#{PS_PSA_DEBUG}" == "DEBUG" ? show_debug = true : show_debug = false + + find_sites(domain).each do |s| + # set vars + url = "${ADMINSERVER_PROTOCOL?}://${ADMINSERVER_HOSTNAME?}:${ADMINSERVER_PORT?}/psp/#{s}/?cmd=login&" + src_env = ". ${PS_CFG_HOME?}/webserv/#{domain}/bin/setEnv.sh" + prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" + + # set reload in config.props + do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) + + # source setEnv and ping site + show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug) + + # unset reload in config.props + do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) + + # done + puts " - #{s}" + end + when "windows" + puts "Windows support coming soon." + #do_cmd(". #{ENV('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") + + #find_sites.each do |s| + # # set vars + # prop_file = "#{ENV('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" + # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" + # # set reload in config.props + # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") + # # ping site + # do_cmd("curl -s -o /dev/null '#{url}'") + # # unset reload in config.props + # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") + # # done + # puts " - #{s}" + #end + else + puts " badOS - #{OS_CONST}" + end + puts "" + end - end # End Class end # End Module \ No newline at end of file From b14cfc511f0c292bb60933a83e6186521bc990f6 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:46:57 -0500 Subject: [PATCH 076/168] Remove psa prefix --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index f384702..0d024f0 100755 --- a/bin/psa +++ b/bin/psa @@ -45,7 +45,7 @@ if File.exists?(PS_PSA_CONF) then end # constants -OS_CONST = psa.os +OS_CONST = os PS_RUNTIME_USER = ENV['PS_RUNTIME_USER'] || "psadm2" PS_HOOK_INTERP = ENV['PS_HOOK_INTERP'] || "ruby" PS_HOOK_PRE = ENV['PS_HOOK_PRE'] || "false" From 0b20e5745f5423585a17cec89fea6efbadc842b7 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 12:47:53 -0500 Subject: [PATCH 077/168] Change ENV back to env --- lib/psadmin_plus.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index ada21b0..905f88b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -201,7 +201,7 @@ def do_set_cfg_home(d) def find_apps_nix case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) else apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) end @@ -211,7 +211,7 @@ def find_apps_nix def find_prcss_nix case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("find #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) else prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) end @@ -221,7 +221,7 @@ def find_prcss_nix def find_webs_nix case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("find #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) else webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) end @@ -236,7 +236,7 @@ def find_sites_nix(domain) def find_apps_win case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end @@ -246,7 +246,7 @@ def find_apps_win def find_prcss_win case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end @@ -256,7 +256,7 @@ def find_prcss_win def find_webs_win case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("(get-childitem #{ENV('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end @@ -265,7 +265,7 @@ def find_webs_win def find_sites_win(domain) #TODO - #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+/) + #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+/) #sites.map! {|site| site.split("\\")[-2]} end @@ -296,9 +296,9 @@ def do_admin def do_list puts "---" print "hostname: " ; do_cmd('hostname') - print "ps-home: " ; do_cmd('echo ' + ENV('PS_HOME')) + print "ps-home: " ; do_cmd('echo ' + env('PS_HOME')) if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + ENV('PS_CFG_HOME')) + print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME')) else puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" end @@ -369,10 +369,10 @@ def do_status(type, domain) do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + ENV('TUXDIR') + "/bin/tmadmin -r ") + do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "pubsub" do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{ENV('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + ENV('TUXDIR') + "/bin/tmadmin -r") + do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") @@ -681,11 +681,11 @@ def do_webprof_reload(domain) end when "windows" puts "Windows support coming soon." - #do_cmd(". #{ENV('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") + #do_cmd(". #{env('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") #find_sites.each do |s| # # set vars - # prop_file = "#{ENV('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" + # prop_file = "#{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" # # set reload in config.props # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") From 60d2fedb29bdaba0271f7f76673d65b09dccacac Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:35:44 -0500 Subject: [PATCH 078/168] Testing module-level vars --- bin/psa | 2 +- lib/psadmin_plus.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/psa b/bin/psa index 0d024f0..516dfb1 100755 --- a/bin/psa +++ b/bin/psa @@ -7,7 +7,7 @@ rescue LoadError require_relative '../lib/psadmin_plus.rb' end -include Psadmin_plus +include PsadminPlus # options opts_c = ARGV.shift || "help" diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 905f88b..f004e26 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -6,9 +6,9 @@ require 'logger' require_relative 'runner' -module Psadmin_plus +module PsadminPlus - logger = Logger.new($stdout) + @@logger = Logger.new($stdout) logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity @@ -59,8 +59,8 @@ def do_help def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end - def info(msg); logger.info(msg); end - def debug(msg); logger.debug(msg); end + def info(msg); PsadminPlus.logger.info(msg); end + def debug(msg); PsadminPlus.logger.debug(msg); end def os @os ||= ( From c7e51266deb744859ad1d7581424377ada90cee0 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:36:13 -0500 Subject: [PATCH 079/168] Fix syntax for module vars --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f004e26..9b69c25 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -59,8 +59,8 @@ def do_help def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end - def info(msg); PsadminPlus.logger.info(msg); end - def debug(msg); PsadminPlus.logger.debug(msg); end + def info(msg); @@logger.info(msg); end + def debug(msg); @@logger.debug(msg); end def os @os ||= ( From 5263d0f5930133676f15141e2d0e8d7e7ecfed9d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:36:36 -0500 Subject: [PATCH 080/168] Missing @@ --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 9b69c25..d1837f6 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -9,7 +9,7 @@ module PsadminPlus @@logger = Logger.new($stdout) - logger.formatter = proc do |severity, datetime, progname, msg| + @@logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity when "INFO" From 30566593664e77111adf46f3bfafd444b9358ecb Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:38:45 -0500 Subject: [PATCH 081/168] Try encoding stars --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index d1837f6..b524e6b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -13,9 +13,9 @@ module PsadminPlus date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity when "INFO" - "[#{date_format}] ☆ #{severity.ljust(5)}: " + green(msg) + "'\n" + "[#{date_format}] " + "☆".encode('UTF-16') + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" - "[#{date_format}] ★ #{severity.ljust(5)}: " + red(msg) + "'\n" + "[#{date_format}] " + "★".encode('UTF-16') + " #{severity.ljust(5)}: " + red(msg) + "'\n" end end From 53ef471c790139bf056a871b89d05c52535c8a26 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:39:12 -0500 Subject: [PATCH 082/168] Use utf-8 --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index b524e6b..3a1f6fe 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -13,9 +13,9 @@ module PsadminPlus date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity when "INFO" - "[#{date_format}] " + "☆".encode('UTF-16') + " #{severity.ljust(5)}: " + green(msg) + "'\n" + "[#{date_format}] " + "☆".encode('UTF-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" - "[#{date_format}] " + "★".encode('UTF-16') + " #{severity.ljust(5)}: " + red(msg) + "'\n" + "[#{date_format}] " + "★".encode('UTF-8') + " #{severity.ljust(5)}: " + red(msg) + "'\n" end end From 8b2d8dac343f792196ae845bf56cf15945661f5b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:41:24 -0500 Subject: [PATCH 083/168] Disable print for psadmin_check --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 3a1f6fe..9ddb978 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -336,7 +336,7 @@ def do_psadmin_check # Check to see if psadmin loads correctly # This will help when used on web servers that don't have Tuxedo debug "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",true) + check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",false) if check.include? "error" # psadmin config is NOT valid puts "ERROR: psadmin is not configured correctly for this environment!" From 9f933a8bcf6ae650c680e535d9a3db238223eb9b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:44:38 -0500 Subject: [PATCH 084/168] Fixing internal calls to do_cmd --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 9ddb978..9d17af4 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -336,11 +336,11 @@ def do_psadmin_check # Check to see if psadmin loads correctly # This will help when used on web servers that don't have Tuxedo debug "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",false) + check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",false,false,"internal") if check.include? "error" # psadmin config is NOT valid - puts "ERROR: psadmin is not configured correctly for this environment!" - puts " Some psadmin-plus actions only work when Tuxedo and psadmin are configured" + do_output("ERROR: psadmin is not configured correctly for this environment!") + do_output(" Some psadmin-plus actions only work when Tuxedo and psadmin are configured") false else # psadmin config is valid From 497c178a47fa6da7e3f3fd1786c8523004351a7f Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:46:35 -0500 Subject: [PATCH 085/168] Set logger level from PS_PSA_DEBUG --- lib/psadmin_plus.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 9d17af4..9303b5a 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -9,6 +9,7 @@ module PsadminPlus @@logger = Logger.new($stdout) + @@logger.level = ENV['PS_PSA_DEBUG'] @@logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity From c3a6c1f7e511ada9f0539cee285416eb7c654341 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 16:55:49 -0500 Subject: [PATCH 086/168] starting output types --- bin/psa | 1 + lib/psadmin_plus.rb | 3 +-- lib/runner.rb | 38 ++++++++++++++++++++------------------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/bin/psa b/bin/psa index 516dfb1..93c3ee3 100755 --- a/bin/psa +++ b/bin/psa @@ -62,6 +62,7 @@ PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0 PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" +PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary", "quiet" # validation # check runtime user diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 9303b5a..5213aeb 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -103,9 +103,8 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) if "#{PS_PSA_SUDO}" == "on" debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") - runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = true) + runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = PS_PSA_OUTPUT) runner.run - # runner.stdout else print "#{PS_RUNTIME_USER} " debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" diff --git a/lib/runner.rb b/lib/runner.rb index 7753e69..360a722 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -43,26 +43,28 @@ def success? # @return [Runner] def run Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| - until [stdout, stderr].all?(&:eof?) - readable = IO.select([stdout, stderr]) - next unless readable&.first + if realtime == "all" + until [stdout, stderr].all?(&:eof?) + readable = IO.select([stdout, stderr]) + next unless readable&.first - readable.first.each do |stream| - data = +'' - # rubocop:disable Lint/HandleExceptions - begin - stream.read_nonblock(1024, data) - rescue EOFError - # ignore, it's expected for read_nonblock to raise EOFError - # when all is read - end + readable.first.each do |stream| + data = +'' + # rubocop:disable Lint/HandleExceptions + begin + stream.read_nonblock(1024, data) + rescue EOFError + # ignore, it's expected for read_nonblock to raise EOFError + # when all is read + end - if stream == stdout - @stdout << data - $stdout.write(data) - else - @stderr << data - $stderr.write(data) + if stream == stdout + @stdout << data + $stdout.write(data) + else + @stderr << data + $stderr.write(data) + end end end end From e4802e3b623a17beecac45ccd3b8bdc960aace45 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:01:21 -0500 Subject: [PATCH 087/168] Adding check for summary output --- lib/psadmin_plus.rb | 24 ++++++++++++++---------- lib/runner.rb | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 5213aeb..b146d00 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -132,21 +132,25 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) end def process_output(stdout, stderr, exitcode, timestamp = nil) - # Standard Output - *lines = stdout.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp) + if PS_PSA_OUTPUT == "summary" + # Standard Output + *lines = stdout.split(/\n/) + lines.each do | line | + do_output(line, timestamp) + end end - # Standard Error - *lines = stderr.split(/\n/) - # lines[0...-2].each do | line | # Remove two trailing extra lines - lines.each do | line | - do_output(line, timestamp, true) + if PS_PSA_OUTPUT == "all" + # Standard Error + *lines = stderr.split(/\n/) + lines.each do | line | + do_output(line, timestamp, true) + end end case "exitcode" + when 0 + do_output("psadmin returned success", timestamp) when 1 do_output("psadmin returned an error", timestamp, true) exit 1 diff --git a/lib/runner.rb b/lib/runner.rb index 360a722..5187516 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -43,7 +43,7 @@ def success? # @return [Runner] def run Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| - if realtime == "all" + if realtime == "all" || realtime == "summary" until [stdout, stderr].all?(&:eof?) readable = IO.select([stdout, stderr]) next unless readable&.first From 918d300c751260b6e5c32beff749fe31b37f2b83 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:02:38 -0500 Subject: [PATCH 088/168] Testing output level in runner --- lib/runner.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/runner.rb b/lib/runner.rb index 5187516..41450ed 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -60,22 +60,18 @@ def run if stream == stdout @stdout << data - $stdout.write(data) + if realtime == "all" + $stdout.write(data) + end else @stderr << data - $stderr.write(data) + if realtime == "all" + $stderr.write(data) + end end end end end - # DJI - # if @realtime == true - # Thread.new do - # stdout.each {|l| puts l } - # stderr.each {|l| puts l } - # end - # wait_thread.value - # end @exit_status = wait_thr.value.exitstatus end From 177f23d79846669107a448c3653706354956ce2d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:06:54 -0500 Subject: [PATCH 089/168] Method for printing stdout/stderr --- lib/psadmin_plus.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index b146d00..953c2bd 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -133,31 +133,32 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) def process_output(stdout, stderr, exitcode, timestamp = nil) if PS_PSA_OUTPUT == "summary" - # Standard Output - *lines = stdout.split(/\n/) - lines.each do | line | - do_output(line, timestamp) - end + print_std(stdout, timestamp) end if PS_PSA_OUTPUT == "all" - # Standard Error - *lines = stderr.split(/\n/) - lines.each do | line | - do_output(line, timestamp, true) - end + print_std(stderr, timestamp, true) end - case "exitcode" + case exitcode when 0 do_output("psadmin returned success", timestamp) when 1 do_output("psadmin returned an error", timestamp, true) + print_std(stderr, timestamp, true) exit 1 end end + def print_std(std, timestamp, err = false) + # Standard Output + *lines = std.split(/\n/) + lines.each do | line | + do_output(line, timestamp, err) + end + end + def do_output(line, timestamp = nil, err = false) utctime = "" From d2d87426da4d044d9d45cbfc1ff4599446bbf094 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:08:49 -0500 Subject: [PATCH 090/168] Checking exitcode boolean --- lib/psadmin_plus.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 953c2bd..51c1372 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -141,14 +141,13 @@ def process_output(stdout, stderr, exitcode, timestamp = nil) end case exitcode - when 0 + when true do_output("psadmin returned success", timestamp) - when 1 + when false do_output("psadmin returned an error", timestamp, true) print_std(stderr, timestamp, true) exit 1 end - end def print_std(std, timestamp, err = false) From 7c69cc57f4f015a9d520a81df664ac3bf8afd51e Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:13:17 -0500 Subject: [PATCH 091/168] Remove success message --- lib/psadmin_plus.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 51c1372..b3cd52c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -127,11 +127,19 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) if timestamp == "internal" runner.stdout else - process_output(runner.stdout, runner.stderr, runner.success?, timestamp) + process_output(runner.stdout, runner.stderr, timestamp) + end + + # Check exitcode and pass any errors + case runner.success? + when false + do_output("psadmin returned an error", timestamp, true) + print_std(stderr, timestamp, true) + exit 1 end end - def process_output(stdout, stderr, exitcode, timestamp = nil) + def process_output(stdout, stderr, timestamp = nil) if PS_PSA_OUTPUT == "summary" print_std(stdout, timestamp) end @@ -139,15 +147,6 @@ def process_output(stdout, stderr, exitcode, timestamp = nil) if PS_PSA_OUTPUT == "all" print_std(stderr, timestamp, true) end - - case exitcode - when true - do_output("psadmin returned success", timestamp) - when false - do_output("psadmin returned an error", timestamp, true) - print_std(stderr, timestamp, true) - exit 1 - end end def print_std(std, timestamp, err = false) From e4577803893e18a094af53b28c663d63e6c18ec9 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:14:28 -0500 Subject: [PATCH 092/168] Move exitcode check to output-based calls only --- lib/psadmin_plus.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index b3cd52c..af24d2d 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -128,14 +128,13 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) runner.stdout else process_output(runner.stdout, runner.stderr, timestamp) - end - - # Check exitcode and pass any errors - case runner.success? - when false - do_output("psadmin returned an error", timestamp, true) - print_std(stderr, timestamp, true) - exit 1 + # Check exitcode and pass any errors for non-internal calls + case runner.success? + when false + do_output("psadmin returned an error", timestamp, true) + print_std(stderr, timestamp, true) + exit 1 + end end end From 6f6bd86491ea81be0c6d5fc1e708ae4dad8e43bd Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:23:53 -0500 Subject: [PATCH 093/168] Moving output processing around a bit --- lib/psadmin_plus.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index af24d2d..fa9f0a1 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -128,23 +128,25 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) runner.stdout else process_output(runner.stdout, runner.stderr, timestamp) - # Check exitcode and pass any errors for non-internal calls - case runner.success? - when false - do_output("psadmin returned an error", timestamp, true) - print_std(stderr, timestamp, true) - exit 1 - end end end - def process_output(stdout, stderr, timestamp = nil) + def process_output(stdout, stderr, timestamp) if PS_PSA_OUTPUT == "summary" print_std(stdout, timestamp) end - if PS_PSA_OUTPUT == "all" - print_std(stderr, timestamp, true) + case runner.success? + when true + if PS_PSA_OUTPUT == "quiet" + do_output("psadmin returned success", timestamp) + end + when false + do_output("psadmin returned an error", timestamp, true) + if PS_PSA_OUTPUT == "summary" || PS_PSA_OUTPUT == "quiet" + print_std(stderr, timestamp, true) + end + exit 1 end end From cf951b356a8067293268aab1ea3807dd8f5935e1 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:25:17 -0500 Subject: [PATCH 094/168] fix object reference --- bin/psa | 2 +- lib/psadmin_plus.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/psa b/bin/psa index 93c3ee3..7bd0645 100755 --- a/bin/psa +++ b/bin/psa @@ -62,7 +62,7 @@ PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0 PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" -PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary", "quiet" +PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "summary" # values are "all", "summary", "quiet" # validation # check runtime user diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index fa9f0a1..bfdb20c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -127,16 +127,16 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) if timestamp == "internal" runner.stdout else - process_output(runner.stdout, runner.stderr, timestamp) + process_output(runner.stdout, runner.stderr, runner.success?, timestamp) end end - def process_output(stdout, stderr, timestamp) + def process_output(stdout, stderr, success, timestamp) if PS_PSA_OUTPUT == "summary" print_std(stdout, timestamp) end - case runner.success? + case success when true if PS_PSA_OUTPUT == "quiet" do_output("psadmin returned success", timestamp) From 680405802176d23cf23a47e600c3d76fbf0e4b5d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Wed, 14 Jun 2023 17:28:32 -0500 Subject: [PATCH 095/168] Add error 40 as OK --- lib/runner.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/runner.rb b/lib/runner.rb index 41450ed..6b1a54a 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -36,7 +36,14 @@ def initialize(cmd, realtime = false) # @return [Boolean] success or failure? def success? - exit_status.zero? + case exit_status + when 0 + true + when 40 # stop an already stopped domain + true + else + false + end end # Run the command, return self From 66927fb3cde17cd12ced88bc5316659311c23110 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 09:13:12 -0500 Subject: [PATCH 096/168] Removing timestamps from logger --- lib/psadmin_plus.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index bfdb20c..f4d8d34 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -14,9 +14,11 @@ module PsadminPlus date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity when "INFO" - "[#{date_format}] " + "☆".encode('UTF-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" + # "[#{date_format}] " + + " ☆".encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: " * ") + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" - "[#{date_format}] " + "★".encode('UTF-8') + " #{severity.ljust(5)}: " + red(msg) + "'\n" + # "[#{date_format}] " + + " ★".encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: " * ") + " #{severity.ljust(5)}: " + red(msg) + "'\n" end end From c10def221532958b1c7b3ca95e6bcd31cb715a1c Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 09:27:45 -0500 Subject: [PATCH 097/168] Testing output handling in runner --- lib/psadmin_plus.rb | 1 + lib/runner.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f4d8d34..f46b30f 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -126,6 +126,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) out = "Invalid OS" end + # "internal" is used to bypass output processing for psa internal functions if timestamp == "internal" runner.stdout else diff --git a/lib/runner.rb b/lib/runner.rb index 6b1a54a..9580748 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -50,7 +50,7 @@ def success? # @return [Runner] def run Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| - if realtime == "all" || realtime == "summary" + if realtime == "all" # || realtime == "summary" until [stdout, stderr].all?(&:eof?) readable = IO.select([stdout, stderr]) next unless readable&.first @@ -91,7 +91,7 @@ def run def run! return run.stdout if run.success? - raise(Error, "command failed, exit: %d - stdout: %s / stderr: %s" % [exit_status, stdout, stderr]) + raise(Error, "psadmin returned an error, exit: %d - stdout: %s / stderr: %s" % [exit_status, stdout, stderr]) end # Run the command and return true if success, false if failure From 5e56e49b9df53919dd6d2bcc8da7e6d5debafd2b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 09:32:03 -0500 Subject: [PATCH 098/168] Set logger level first for class var --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f46b30f..3c599ea 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -9,7 +9,7 @@ module PsadminPlus @@logger = Logger.new($stdout) - @@logger.level = ENV['PS_PSA_DEBUG'] + @@logger.level = ENV['PS_PSA_DEBUG'] || "INFO" @@logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity From a2875541aec04cf518f46786f43ff0ecaca7978d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 12:10:35 -0500 Subject: [PATCH 099/168] Use instance vars --- lib/runner.rb | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/runner.rb b/lib/runner.rb index 9580748..d9e9f3a 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -50,31 +50,29 @@ def success? # @return [Runner] def run Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr| - if realtime == "all" # || realtime == "summary" - until [stdout, stderr].all?(&:eof?) - readable = IO.select([stdout, stderr]) - next unless readable&.first + until [stdout, stderr].all?(&:eof?) + readable = IO.select([stdout, stderr]) + next unless readable&.first - readable.first.each do |stream| - data = +'' - # rubocop:disable Lint/HandleExceptions - begin - stream.read_nonblock(1024, data) - rescue EOFError - # ignore, it's expected for read_nonblock to raise EOFError - # when all is read - end + readable.first.each do |stream| + data = +'' + # rubocop:disable Lint/HandleExceptions + begin + stream.read_nonblock(1024, data) + rescue EOFError + # ignore, it's expected for read_nonblock to raise EOFError + # when all is read + end - if stream == stdout - @stdout << data - if realtime == "all" - $stdout.write(data) - end - else - @stderr << data - if realtime == "all" - $stderr.write(data) - end + if stream == stdout + @stdout << data + if @realtime == "all" + $stdout.write(data) + end + else + @stderr << data + if @realtime == "all" + $stderr.write(data) end end end From 765da2794b09b412d66e647666552e41e0271b86 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 12:44:10 -0500 Subject: [PATCH 100/168] Try to capture start/stop messages --- lib/psadmin_plus.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 3c599ea..61295fb 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -137,6 +137,8 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) def process_output(stdout, stderr, success, timestamp) if PS_PSA_OUTPUT == "summary" print_std(stdout, timestamp) + print_std(stderr, timestamp, false, true) + end case success @@ -153,14 +155,24 @@ def process_output(stdout, stderr, success, timestamp) end end - def print_std(std, timestamp, err = false) + def print_std(std, timestamp, err = false, summary = false) # Standard Output *lines = std.split(/\n/) lines.each do | line | - do_output(line, timestamp, err) + if summary + if line_matches(line) + do_output(line, timestamp, err) + end + else + do_output(line, timestamp, err) + end end end + def line_matches(line) + line.include?("processes started") || line.include?("processes stopped") + end + def do_output(line, timestamp = nil, err = false) utctime = "" From 608c01d23edc31f597a4192cdf47ab27eb932ab6 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 12:46:12 -0500 Subject: [PATCH 101/168] Capture single process start --- lib/psadmin_plus.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 61295fb..fc99cba 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -170,7 +170,9 @@ def print_std(std, timestamp, err = false, summary = false) end def line_matches(line) - line.include?("processes started") || line.include?("processes stopped") + line.include?("processes started") || + line.include?("process started") || + line.include?("processes stopped") end def do_output(line, timestamp = nil, err = false) From 09ddae1efb28104242323e1a61aa490742797121 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 12:56:52 -0500 Subject: [PATCH 102/168] Use single call with platform prefix/suffix --- lib/psadmin_plus.rb | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index fc99cba..2f40e8c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -96,36 +96,41 @@ def env(var) end def do_cmd(cmd, print = true, powershell = true, timestamp = nil) + if timestamp != "internal" + timestamp = PS_PSA_TIMESTAMP + end + + prefix = "" + suffix = "" case "#{OS_CONST}" when "linux" if do_is_runtime_user_nix - debug "Command: #{cmd}" - out = `#{cmd}` + # No prefix/suffix needed else if "#{PS_PSA_SUDO}" == "on" - debug "Command: sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'" - # stdout, stderr, status = Open3.capture3("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'") - runner = Runner.new("sudo su - #{PS_RUNTIME_USER} -c '#{cmd}'", realtime = PS_PSA_OUTPUT) - runner.run + prefix = "sudo su - #{PS_RUNTIME_USER} -c '" + suffix = "'" else - print "#{PS_RUNTIME_USER} " - debug "Command: su - #{PS_RUNTIME_USER} -c '#{cmd}'" - out = `su - #{PS_RUNTIME_USER} -c '#{cmd}'` + prefix = "su - #{PS_RUNTIME_USER} -c '" + suffix = "'" end end when "windows" case powershell when true - debug "Command: powershell -NoProfile -Command \"#{cmd}\"" - out = `powershell -NoProfile -Command "#{cmd}"` + prefix = "powershell -NoProfile -Command \"" + suffix = "\"" else - debug "Command: #{cmd}" - out = `#{cmd}` + # No prefix/suffix needed end else - out = "Invalid OS" + puts "Invalid OS" end + debug "Command: #{prefix}#{cmd}#{suffix}" + runner = Runner.new("#{cmd}'", realtime = PS_PSA_OUTPUT) + runner.run + # "internal" is used to bypass output processing for psa internal functions if timestamp == "internal" runner.stdout From 4f44ce687c618221165c8d7dea332974ab857289 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 12:59:15 -0500 Subject: [PATCH 103/168] Include pre/suff in command --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 2f40e8c..8b33ff3 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -128,7 +128,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) end debug "Command: #{prefix}#{cmd}#{suffix}" - runner = Runner.new("#{cmd}'", realtime = PS_PSA_OUTPUT) + runner = Runner.new("#{prefix}#{cmd}#{suffix}", realtime = PS_PSA_OUTPUT) runner.run # "internal" is used to bypass output processing for psa internal functions From c4f37d68205976db0e7dce9e590356eda6271e2d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:00:49 -0500 Subject: [PATCH 104/168] Unicode chars --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 8b33ff3..02d8ac5 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -15,10 +15,10 @@ module PsadminPlus case severity when "INFO" # "[#{date_format}] " + - " ☆".encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: " * ") + " #{severity.ljust(5)}: " + green(msg) + "'\n" + " \u2606 #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" # "[#{date_format}] " + - " ★".encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: " * ") + " #{severity.ljust(5)}: " + red(msg) + "'\n" + " \u2605 #{severity.ljust(5)}: " + red(msg) + "'\n" end end From c92bab6471539190fc372820f71d818a1d56e827 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:02:23 -0500 Subject: [PATCH 105/168] Try encoding stars --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 02d8ac5..d1d4676 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -15,10 +15,10 @@ module PsadminPlus case severity when "INFO" # "[#{date_format}] " + - " \u2606 #{severity.ljust(5)}: " + green(msg) + "'\n" + " \u2606".encoding('utf-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" # "[#{date_format}] " + - " \u2605 #{severity.ljust(5)}: " + red(msg) + "'\n" + " \u2605".encoding('utf-8') + " #{severity.ljust(5)}: " + red(msg) + "'\n" end end From 75fda7aa8fd94c1b9057ecb71afbc360dbf7f40d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:02:55 -0500 Subject: [PATCH 106/168] Remov encoding --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index d1d4676..f0c152f 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -15,10 +15,10 @@ module PsadminPlus case severity when "INFO" # "[#{date_format}] " + - " \u2606".encoding('utf-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" + " \u2606" + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" # "[#{date_format}] " + - " \u2605".encoding('utf-8') + " #{severity.ljust(5)}: " + red(msg) + "'\n" + " \u2605" + " #{severity.ljust(5)}: " + red(msg) + "'\n" end end From 1c9f02826610dfbff25852f725d26184a5e5d938 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:04:29 -0500 Subject: [PATCH 107/168] Encode just that char --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f0c152f..8a35a9c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -15,10 +15,10 @@ module PsadminPlus case severity when "INFO" # "[#{date_format}] " + - " \u2606" + " #{severity.ljust(5)}: " + green(msg) + "'\n" + " " + "☆".encode('utf-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" # "[#{date_format}] " + - " \u2605" + " #{severity.ljust(5)}: " + red(msg) + "'\n" + " " + "★".encode('utf-8')+ " #{severity.ljust(5)}: " + red(msg) + "'\n" end end From e69eb851aa752f7b85f5db726bac818e8ce66f3b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:05:31 -0500 Subject: [PATCH 108/168] Force encoding --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 8a35a9c..2ea7bae 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -15,10 +15,10 @@ module PsadminPlus case severity when "INFO" # "[#{date_format}] " + - " " + "☆".encode('utf-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" + " " + "\u2606".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" # "[#{date_format}] " + - " " + "★".encode('utf-8')+ " #{severity.ljust(5)}: " + red(msg) + "'\n" + " " + "\u2605".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + red(msg) + "'\n" end end From 660489fb4cb7cba69d02b63053eb98df28c2f85e Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:09:47 -0500 Subject: [PATCH 109/168] Change debug to yellow --- lib/psadmin_plus.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 2ea7bae..e53c677 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -17,6 +17,9 @@ module PsadminPlus # "[#{date_format}] " + " " + "\u2606".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" when "DEBUG" + # "[#{date_format}] " + + " " + "\u2605".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + yellow(msg) + "'\n" + when "ERROR" # "[#{date_format}] " + " " + "\u2605".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + red(msg) + "'\n" end @@ -60,10 +63,12 @@ def do_help end def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end - def red(text); colorize(text, 31); end - def green(text); colorize(text, 32); end - def info(msg); @@logger.info(msg); end - def debug(msg); @@logger.debug(msg); end + def red(text); colorize(text, 31); end + def green(text); colorize(text, 32); end + def yellow(text); colorize(text, 34); end + def info(msg); @@logger.info(msg); end + def debug(msg); @@logger.debug(msg); end + def error(msg); @@logger.error(msg); end def os @os ||= ( From b7a74d493f912ab2c1b0d6e3a4d2758654eb6ee7 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:12:53 -0500 Subject: [PATCH 110/168] Change coloring to match bash template --- lib/psadmin_plus.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index e53c677..4ebf15e 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -15,13 +15,13 @@ module PsadminPlus case severity when "INFO" # "[#{date_format}] " + - " " + "\u2606".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + green(msg) + "'\n" + " " + "\u2606".force_encoding('UTF-8') + green(severity.ljust(5)) + ": #{msg} \n" when "DEBUG" # "[#{date_format}] " + - " " + "\u2605".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + yellow(msg) + "'\n" + " " + "\u2605".force_encoding('UTF-8') + blue({severity.ljust(5)) + ": #{msg} \n" when "ERROR" # "[#{date_format}] " + - " " + "\u2605".force_encoding('UTF-8') + " #{severity.ljust(5)}: " + red(msg) + "'\n" + " " + "\u2605".force_encoding('UTF-8') + red(severity.ljust(5)) + ": #{msg} \n" end end @@ -65,7 +65,7 @@ def do_help def colorize(text, color_code); "\e[#{color_code}m#{text}\e[0m"; end def red(text); colorize(text, 31); end def green(text); colorize(text, 32); end - def yellow(text); colorize(text, 34); end + def blue(text); colorize(text, 34); end def info(msg); @@logger.info(msg); end def debug(msg); @@logger.debug(msg); end def error(msg); @@logger.error(msg); end From 759f55baf08dc050698115eb7d7646000642c97b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:13:12 -0500 Subject: [PATCH 111/168] Change coloring to match bash template --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4ebf15e..c58563b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -18,7 +18,7 @@ module PsadminPlus " " + "\u2606".force_encoding('UTF-8') + green(severity.ljust(5)) + ": #{msg} \n" when "DEBUG" # "[#{date_format}] " + - " " + "\u2605".force_encoding('UTF-8') + blue({severity.ljust(5)) + ": #{msg} \n" + " " + "\u2605".force_encoding('UTF-8') + blue(severity.ljust(5)) + ": #{msg} \n" when "ERROR" # "[#{date_format}] " + " " + "\u2605".force_encoding('UTF-8') + red(severity.ljust(5)) + ": #{msg} \n" From bec97cda3f44c98de65a817df475cd016d7c46fb Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:16:09 -0500 Subject: [PATCH 112/168] Command banner to use INFO --- lib/psadmin_plus.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index c58563b..a65e32d 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -15,13 +15,13 @@ module PsadminPlus case severity when "INFO" # "[#{date_format}] " + - " " + "\u2606".force_encoding('UTF-8') + green(severity.ljust(5)) + ": #{msg} \n" + " ☆ " + green(severity.ljust(5)) + ": #{msg} \n" when "DEBUG" # "[#{date_format}] " + - " " + "\u2605".force_encoding('UTF-8') + blue(severity.ljust(5)) + ": #{msg} \n" + " ★ " + blue(severity.ljust(5)) + ": #{msg} \n" when "ERROR" # "[#{date_format}] " + - " " + "\u2605".force_encoding('UTF-8') + red(severity.ljust(5)) + ": #{msg} \n" + " ✖ " + red(severity.ljust(5)) + ": #{msg} \n" end end @@ -209,13 +209,14 @@ def do_output(line, timestamp = nil, err = false) end def do_cmd_banner(c,t,d) - if "#{PS_PSA_TIMESTAMP}" == "true" - puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" - else - puts "" - puts "===[ #{c} . #{t} . #{d} ]===" - puts "" - end + # if "#{PS_PSA_TIMESTAMP}" == "true" + # puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" + # else + # puts "" + # puts "===[ #{c} . #{t} . #{d} ]===" + # puts "" + # end + info "===[ #{c} . #{t} . #{d} ]===" end def do_set_cfg_home(d) From 131bd37a0eecd0013539cac14b8d6a6379f16c89 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:17:25 -0500 Subject: [PATCH 113/168] Remove unicode chars --- lib/psadmin_plus.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index a65e32d..703081c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -14,14 +14,11 @@ module PsadminPlus date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") case severity when "INFO" - # "[#{date_format}] " + - " ☆ " + green(severity.ljust(5)) + ": #{msg} \n" + green(severity.ljust(5)) + ": #{msg} \n" when "DEBUG" - # "[#{date_format}] " + - " ★ " + blue(severity.ljust(5)) + ": #{msg} \n" + blue(severity.ljust(5)) + ": #{msg} \n" when "ERROR" - # "[#{date_format}] " + - " ✖ " + red(severity.ljust(5)) + ": #{msg} \n" + red(severity.ljust(5)) + ": #{msg} \n" end end From 81148b5d030f9af100ca4a0932a7f0ce683fac07 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:20:05 -0500 Subject: [PATCH 114/168] Add more consts to list --- lib/psadmin_plus.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 703081c..93b669b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -343,6 +343,8 @@ def do_list puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" + puts "PS_PSA_TIMETAMP: #{PS_PSA_TIMESTAMP}" + puts "PS_PSA_OUTPUT: #{PS_PSA_OUTPUT}" puts "" puts "app:" find_apps.each do |a| From e583bcaa0db20af624896972a0fac8778cdd4fef Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:25:48 -0500 Subject: [PATCH 115/168] Cleaning up timestamp code --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 93b669b..47fe39a 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -187,7 +187,7 @@ def do_output(line, timestamp = nil, err = false) utctime = "" # Handle Output - Check if timestamps are requested # - override if parameter is "internal" for internal calls - case "#{PS_PSA_TIMESTAMP}" + case timestamp when "true" if timestamp != "internal" utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") From 6cbbf155d38e3f4d98d3301c94cfbfc73c176a3e Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 13:47:00 -0500 Subject: [PATCH 116/168] On quiet - no output unless error --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 47fe39a..6b39d44 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -150,9 +150,9 @@ def process_output(stdout, stderr, success, timestamp) case success when true - if PS_PSA_OUTPUT == "quiet" - do_output("psadmin returned success", timestamp) - end + # if PS_PSA_OUTPUT == "quiet" + # do_output("psadmin returned success", timestamp) + # end when false do_output("psadmin returned an error", timestamp, true) if PS_PSA_OUTPUT == "summary" || PS_PSA_OUTPUT == "quiet" From cad96c9d9b36701d893ffd59ad6a25960248056c Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:36:58 -0500 Subject: [PATCH 117/168] Set banner back to default --- lib/psadmin_plus.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 6b39d44..0939604 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -206,14 +206,9 @@ def do_output(line, timestamp = nil, err = false) end def do_cmd_banner(c,t,d) - # if "#{PS_PSA_TIMESTAMP}" == "true" - # puts Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") + "===[ #{c} . #{t} . #{d} ]===" - # else - # puts "" - # puts "===[ #{c} . #{t} . #{d} ]===" - # puts "" - # end - info "===[ #{c} . #{t} . #{d} ]===" + puts "" + puts "===[ #{c} . #{t} . #{d} ]===" + puts "" end def do_set_cfg_home(d) From 7a057df05bdb1f13e5fd88d53ce7836c32780e25 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:37:55 -0500 Subject: [PATCH 118/168] No timestamp for list --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0939604..4e5ea35 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -319,10 +319,10 @@ def do_admin def do_list puts "---" - print "hostname: " ; do_cmd('hostname') - print "ps-home: " ; do_cmd('echo ' + env('PS_HOME')) + print "hostname: " ; do_cmd('hostname', false, false, "internal") + print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), false, false, "internal") if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME')) + print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'), false, false, "internal") else puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" end From ac3bc4e7c67c3fffabcad6c485579804c7659e0e Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:41:07 -0500 Subject: [PATCH 119/168] Named params for list --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4e5ea35..c45a660 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -319,10 +319,10 @@ def do_admin def do_list puts "---" - print "hostname: " ; do_cmd('hostname', false, false, "internal") - print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), false, false, "internal") + print "hostname: " ; do_cmd('hostname', timestamp: "internal") + print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), timestamp: "internal") if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'), false, false, "internal") + print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'), timestamp: "internal") else puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" end From a8b17e7411369e38a6437ab47b9655efa42cc6e4 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:48:36 -0500 Subject: [PATCH 120/168] Fix list alignment --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index c45a660..57fb652 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -319,8 +319,8 @@ def do_admin def do_list puts "---" - print "hostname: " ; do_cmd('hostname', timestamp: "internal") - print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), timestamp: "internal") + print "hostname: " ; do_cmd('hostname', timestamp: "internal") + print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), timestamp: "internal") if PS_MULTI_HOME == "false" print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'), timestamp: "internal") else From bba1108f19f89fe848473fa0154005facbebe1c1 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:49:35 -0500 Subject: [PATCH 121/168] Change output to all for default. Summary and quiet are optional --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index 7bd0645..93c3ee3 100755 --- a/bin/psa +++ b/bin/psa @@ -62,7 +62,7 @@ PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0 PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" -PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "summary" # values are "all", "summary", "quiet" +PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary", "quiet" # validation # check runtime user From f4e3e3c47b7cb6ed0726236dfba2f55189102d76 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:52:05 -0500 Subject: [PATCH 122/168] Adding debug --- lib/psadmin_plus.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 57fb652..ed4379e 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -135,6 +135,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) # "internal" is used to bypass output processing for psa internal functions if timestamp == "internal" + debug "internal output: #{runner.stdout}" runner.stdout else process_output(runner.stdout, runner.stderr, runner.success?, timestamp) From 376f3f43f40cf82b0fe8ecd8b0f654b6fa6f9c08 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:55:43 -0500 Subject: [PATCH 123/168] Mucking with internal calls again --- lib/psadmin_plus.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index ed4379e..192037f 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -97,8 +97,8 @@ def env(var) result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" end - def do_cmd(cmd, print = true, powershell = true, timestamp = nil) - if timestamp != "internal" + def do_cmd(cmd, print = true, powershell = true, timestamp = nil, internal = false) + if !internal timestamp = PS_PSA_TIMESTAMP end @@ -134,7 +134,7 @@ def do_cmd(cmd, print = true, powershell = true, timestamp = nil) runner.run # "internal" is used to bypass output processing for psa internal functions - if timestamp == "internal" + if internal debug "internal output: #{runner.stdout}" runner.stdout else @@ -226,9 +226,9 @@ def do_set_cfg_home(d) def find_apps_nix case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",internal: true).split(/\n+/) else - apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",internal: true).split(/\n+/) end apps.map! {|app| app.split("/")[-2]} end @@ -236,9 +236,9 @@ def find_apps_nix def find_prcss_nix case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",internal: true).split(/\n+/) else - prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",false,false,"internal").split(/\n+/) + prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",internal: true).split(/\n+/) end prcss.map! {|prcs| prcs.split("/")[-2]} end @@ -246,15 +246,15 @@ def find_prcss_nix def find_webs_nix case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",internal: true).split(/\n+/) else - webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",false,false,"internal").split(/\n+/) + webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",internal: true).split(/\n+/) end webs.map! {|web| web.split("/")[-2]} end def find_sites_nix(domain) - webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",false,false,"internal").split(/\n+/) + webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",internal: true).split(/\n+/) webs.map! {|site| site.split("/")[-1]} end @@ -320,10 +320,10 @@ def do_admin def do_list puts "---" - print "hostname: " ; do_cmd('hostname', timestamp: "internal") - print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), timestamp: "internal") + print "hostname: " ; do_cmd('hostname', internal: true) + print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), internal: true) if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'), timestamp: "internal") + print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'), internal: true) else puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" end @@ -363,7 +363,7 @@ def do_psadmin_check # Check to see if psadmin loads correctly # This will help when used on web servers that don't have Tuxedo debug "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1",false,false,"internal") + check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1", internal: true) if check.include? "error" # psadmin config is NOT valid do_output("ERROR: psadmin is not configured correctly for this environment!") From e81cbf3a07d1da84657ac6145f06de10cbef3dc8 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:57:14 -0500 Subject: [PATCH 124/168] Named params for list --- lib/psadmin_plus.rb | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 192037f..35c6364 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -226,9 +226,9 @@ def do_set_cfg_home(d) def find_apps_nix case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",internal: true).split(/\n+/) + apps = do_cmd(cmd: "find #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx 2>/dev/null",internal: true).split(/\n+/) else - apps = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",internal: true).split(/\n+/) + apps = do_cmd(cmd: "find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx 2>/dev/null",internal: true).split(/\n+/) end apps.map! {|app| app.split("/")[-2]} end @@ -236,9 +236,9 @@ def find_apps_nix def find_prcss_nix case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",internal: true).split(/\n+/) + prcss = do_cmd(cmd: "find #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",internal: true).split(/\n+/) else - prcss = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",internal: true).split(/\n+/) + prcss = do_cmd(cmd: "find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx 2>/dev/null",internal: true).split(/\n+/) end prcss.map! {|prcs| prcs.split("/")[-2]} end @@ -246,24 +246,24 @@ def find_prcss_nix def find_webs_nix case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",internal: true).split(/\n+/) + webs = do_cmd(cmd: "find #{env('PS_CFG_HOME')}/webserv/*/piaconfig -maxdepth 0",internal: true).split(/\n+/) else - webs = do_cmd("find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",internal: true).split(/\n+/) + webs = do_cmd(cmd: "find #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig -maxdepth 0",internal: true).split(/\n+/) end webs.map! {|web| web.split("/")[-2]} end def find_sites_nix(domain) - webs = do_cmd("find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",internal: true).split(/\n+/) + webs = do_cmd(cmd: "find ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/* -maxdepth 0",internal: true).split(/\n+/) webs.map! {|site| site.split("/")[-1]} end def find_apps_win case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + apps = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else - apps = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + apps = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end apps.map! {|app| app.split('\\')[-2]} end @@ -271,9 +271,9 @@ def find_apps_win def find_prcss_win case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + prcss = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else - prcss = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + prcss = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end prcss.map! {|prcs| prcs.split("\\")[-2]} end @@ -281,9 +281,9 @@ def find_prcss_win def find_webs_win case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd("(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + webs = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) else - webs = do_cmd("(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + webs = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) end webs.map! {|web| web.split("\\")[-2]} end @@ -320,10 +320,10 @@ def do_admin def do_list puts "---" - print "hostname: " ; do_cmd('hostname', internal: true) - print "ps-home: " ; do_cmd('echo ' + env('PS_HOME'), internal: true) + print "hostname: " ; do_cmd(cmd:'hostname', internal: true) + print "ps-home: " ; do_cmd(cmd:'echo ' + env('PS_HOME'), internal: true) if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd('echo ' + env('PS_CFG_HOME'), internal: true) + print "ps-cfg-home: " ; do_cmd(cmd:'echo ' + env('PS_CFG_HOME'), internal: true) else puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" end @@ -363,7 +363,7 @@ def do_psadmin_check # Check to see if psadmin loads correctly # This will help when used on web servers that don't have Tuxedo debug "Checking psadmin version to validate configuration:" - check = do_cmd("#{PS_PSADMIN_PATH}/psadmin -v 2>&1", internal: true) + check = do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -v 2>&1", internal: true) if check.include? "error" # psadmin config is NOT valid do_output("ERROR: psadmin is not configured correctly for this environment!") From 6e9aa2fa7cb59c96da9aaf11740034c815256956 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 14:58:03 -0500 Subject: [PATCH 125/168] Named params for list --- lib/psadmin_plus.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 35c6364..85c670c 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -261,9 +261,9 @@ def find_sites_nix(domain) def find_apps_win case "#{PS_MULTI_HOME}" when "false" - apps = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + apps = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",internal: true).split(/\n+/) else - apps = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + apps = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/*/psappsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",internal: true).split(/\n+/) end apps.map! {|app| app.split('\\')[-2]} end @@ -271,9 +271,9 @@ def find_apps_win def find_prcss_win case "#{PS_MULTI_HOME}" when "false" - prcss = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + prcss = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",).split(/\n+/) else - prcss = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + prcss = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/appserv/prcs/*/psprcsrv.ubx | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",internal: true).split(/\n+/) end prcss.map! {|prcs| prcs.split("\\")[-2]} end @@ -281,9 +281,9 @@ def find_prcss_win def find_webs_win case "#{PS_MULTI_HOME}" when "false" - webs = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + webs = do_cmd(cmd: "(get-childitem #{env('PS_CFG_HOME')}/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",internal: true).split(/\n+/) else - webs = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",false,true,"internal").split(/\n+/) + webs = do_cmd(cmd: "(get-childitem #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*/webserv/*/piaconfig | Format-Table -property FullName -HideTableHeaders | Out-String).Trim()",internal: true).split(/\n+/) end webs.map! {|web| web.split("\\")[-2]} end From aaecab4398da33ed68d948e5537faf6c8719251b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:00:05 -0500 Subject: [PATCH 126/168] Trying named params --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 85c670c..2947c2b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -97,7 +97,7 @@ def env(var) result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" end - def do_cmd(cmd, print = true, powershell = true, timestamp = nil, internal = false) + def do_cmd(cmd:, print = true, powershell = true, timestamp = nil, internal: false) if !internal timestamp = PS_PSA_TIMESTAMP end From eedf7fdb5ffc1b899d66ab3d4b34c12cbdefa9a3 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:10:09 -0500 Subject: [PATCH 127/168] More named params --- lib/psadmin_plus.rb | 50 ++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 2947c2b..7034940 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -97,11 +97,7 @@ def env(var) result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" end - def do_cmd(cmd:, print = true, powershell = true, timestamp = nil, internal: false) - if !internal - timestamp = PS_PSA_TIMESTAMP - end - + def do_cmd(cmd:, internal: false) prefix = "" suffix = "" case "#{OS_CONST}" @@ -118,13 +114,8 @@ def do_cmd(cmd:, print = true, powershell = true, timestamp = nil, internal: fal end end when "windows" - case powershell - when true - prefix = "powershell -NoProfile -Command \"" - suffix = "\"" - else - # No prefix/suffix needed - end + prefix = "powershell -NoProfile -Command \"" + suffix = "\"" else puts "Invalid OS" end @@ -135,64 +126,63 @@ def do_cmd(cmd:, print = true, powershell = true, timestamp = nil, internal: fal # "internal" is used to bypass output processing for psa internal functions if internal - debug "internal output: #{runner.stdout}" + debug "internal output" runner.stdout else - process_output(runner.stdout, runner.stderr, runner.success?, timestamp) + debug "processing output" + process_output(stdout: runner.stdout, stderr: runner.stderr, success:runner.success?) end end - def process_output(stdout, stderr, success, timestamp) + def process_output(stdout:, stderr:, success:) if PS_PSA_OUTPUT == "summary" - print_std(stdout, timestamp) - print_std(stderr, timestamp, false, true) + debug "summary output - stdout" + print_std(std: stdout) + debug "summary output - stderr" + print_std(std: stderr, summary: true) end case success when true - # if PS_PSA_OUTPUT == "quiet" - # do_output("psadmin returned success", timestamp) - # end + debug "command success" when false do_output("psadmin returned an error", timestamp, true) if PS_PSA_OUTPUT == "summary" || PS_PSA_OUTPUT == "quiet" - print_std(stderr, timestamp, true) + print_std(std:stderr, err: true) end exit 1 end end - def print_std(std, timestamp, err = false, summary = false) + def print_std(std:, err: false, summary: false) # Standard Output *lines = std.split(/\n/) lines.each do | line | if summary if line_matches(line) - do_output(line, timestamp, err) + do_output(line, err) end else - do_output(line, timestamp, err) + do_output(line, err) end end end def line_matches(line) + debug "matching lines for summary output" line.include?("processes started") || line.include?("process started") || line.include?("processes stopped") end - def do_output(line, timestamp = nil, err = false) - + def do_output(line, err = false) utctime = "" # Handle Output - Check if timestamps are requested # - override if parameter is "internal" for internal calls - case timestamp + case PS_PSA_TIMESTAMP when "true" - if timestamp != "internal" - utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") - end + utctime = Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") end if !line.empty? From 48509f198d01aa5d6952f45ce5e29ea9953c70f0 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:10:56 -0500 Subject: [PATCH 128/168] Set cmd: param name --- lib/psadmin_plus.rb | 68 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 7034940..6bd9700 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -280,7 +280,7 @@ def find_webs_win def find_sites_win(domain) #TODO - #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+/) + #sites = do_cmd(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+/) #sites.map! {|site| site.split("\\")[-2]} end @@ -305,7 +305,7 @@ def do_util end def do_admin - do_cmd("#{PS_PSADMIN_PATH}/psadmin") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin") end def do_list @@ -372,7 +372,7 @@ def do_summary do_psadmin_check ? nil : exit - do_cmd("#{PS_PSADMIN_PATH}/psadmin -envsummary") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -envsummary") #do_status("web","all") end @@ -380,24 +380,24 @@ def do_status(type, domain) case type when "app" do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c sstatus -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c cstatus -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c qstatus -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "pubsub" do_psadmin_check ? nil : return - do_cmd("export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") when "web" # TODO - PIA script status? 1. psadmin, 2. script, 3. lock file, 4. service #do_psadmin_check ? nil : return - do_cmd("#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") - #do_cmd("${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -w status -d #{domain}") + #do_cmd(cmd: "${PS_CFG_HOME?}/webserv/#{domain}/bin/singleserverStatus.sh") #if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") else puts "Invalid type, see psa help" @@ -437,7 +437,7 @@ def do_start(type, domain) do_hookstart("start",type,domain) when "pubsub" ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + do_cmd(cmd: "echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? when "prcs" case "#{PS_WIN_SERVICES}" @@ -508,7 +508,7 @@ def do_stop(type, domain) when "pubsub" # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd("echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + do_cmd(cmd: "echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") when "prcs" do_hookstop("stop",type,domain) case "#{PS_WIN_SERVICES}" @@ -546,15 +546,15 @@ def do_stop(type, domain) def do_kill(type, domain) case type when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c shutdown! -d #{domain}") when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p kill -d #{domain}") when "web" case "#{OS_CONST}" when "windows" - do_cmd("(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") + do_cmd(cmd: "(gwmi win32_process | where {$_.Name -eq 'Java.exe'} | where {$_.CommandLine -match '#{domain}'}).ProcessId -ErrorAction SilentlyContinue | % { stop-process $_ -force } -ErrorAction SilentlyContinue") when "linux" - do_cmd("kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") + do_cmd(cmd: "kill $(ps aux|grep java|grep ${PS_CFG_HOME?}/webserv/#{domain}/piaconfig|awk ' {print $2}')") end else puts "Invalid type, see psa help" @@ -564,9 +564,9 @@ def do_kill(type, domain) def do_configure(type, domain) case type when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c configure -d #{domain}") when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p configure -d #{domain}") when "web" do_webprof_reload("#{domain}") else @@ -577,22 +577,22 @@ def do_configure(type, domain) def do_purge(type, domain) case type when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c purge -d #{domain}") when "prcs" case "#{OS_CONST}" when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") + do_cmd(cmd: "rm -rf ${PS_CFG_HOME?}/appserv/prcs/#{domain}/CACHE/*") when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + do_cmd(cmd: "Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/appserv/prcs/#{domain}/CACHE/* | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) end puts "prcs cache purged" when "web" case "#{OS_CONST}" when "linux" - do_cmd("rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") + do_cmd(cmd: "rm -rf ${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/") puts "web cache purged" when "windows" - do_cmd("Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) + do_cmd(cmd: "Remove-Item $(Get-ChildItem ${env:PS_CFG_HOME}/webserv/#{domain}/applications/peoplesoft/PORTAL*/*/cache*/ | ?{ $_.PSIsContainer}) -recurse -force -ErrorAction SilentlyContinue".gsub('/','\\')) end else puts "Invalid type, see psa help" @@ -602,9 +602,9 @@ def do_purge(type, domain) def do_flush(type, domain) case type when "app" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c cleanipc -d #{domain}") when "prcs" - do_cmd("#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") + do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p cleanipc -d #{domain}") when "web" return # web flush n/a else @@ -685,31 +685,31 @@ def do_webprof_reload(domain) prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" # set reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) + do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) # source setEnv and ping site - show_debug ? do_cmd("#{src_env} ; curl -s #{url}",show_debug) : do_cmd("#{src_env} ; curl -s -o /dev/null #{url}",show_debug) + show_debug ? do_cmd(cmd: "#{src_env} ; curl -s #{url}",show_debug) : do_cmd(cmd: "#{src_env} ; curl -s -o /dev/null #{url}",show_debug) # unset reload in config.props - do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) + do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) # done puts " - #{s}" end when "windows" puts "Windows support coming soon." - #do_cmd(". #{env('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") + #do_cmd(cmd: ". #{env('PS_CFG_HOME')}/webserv/#{domain}/bin/setEnv.sh") #find_sites.each do |s| # # set vars # prop_file = "#{env('PS_CFG_HOME')}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}}/configuration.properties" # url = "http://#{PS_PIA_HOST}.#{PS_PIA_DOMAIN}:#{PS_PIA_PORT}/psp/#{s}/?cmd=login&" # # set reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") + # do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") # # ping site - # do_cmd("curl -s -o /dev/null '#{url}'") + # do_cmd(cmd: "curl -s -o /dev/null '#{url}'") # # unset reload in config.props - # do_cmd("sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") + # do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") # # done # puts " - #{s}" #end From 70a6423749e163d335f620b385adee9ed4c25c08 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:14:01 -0500 Subject: [PATCH 129/168] Set cmd: param name --- lib/psadmin_plus.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 6bd9700..0ab1776 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -436,9 +436,7 @@ def do_start(type, domain) end do_hookstart("start",type,domain) when "pubsub" - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd(cmd: "echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") - # do_hookstart("start",type,domain) - TODO skip hook for PUBSUB? + do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" case "#{PS_WIN_SERVICES}" when "true", "tux", "prcs", "all" @@ -506,9 +504,7 @@ def do_stop(type, domain) end end when "pubsub" - # do_hookstop("stop",type,domain) - TODO skip hook for PUBSUB? - ENV['TUXCONFIG'] = "#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG" - do_cmd(cmd: "echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin") + do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo shutdown -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_hookstop("stop",type,domain) case "#{PS_WIN_SERVICES}" @@ -685,13 +681,13 @@ def do_webprof_reload(domain) prop_file = "${PS_CFG_HOME?}/webserv/#{domain}/applications/peoplesoft/PORTAL.war/WEB-INF/psftdocs/#{s}/configuration.properties" # set reload in config.props - do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}",show_debug) + do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=1/g' #{prop_file}") # source setEnv and ping site - show_debug ? do_cmd(cmd: "#{src_env} ; curl -s #{url}",show_debug) : do_cmd(cmd: "#{src_env} ; curl -s -o /dev/null #{url}",show_debug) + show_debug ? do_cmd(cmd: "#{src_env} ; curl -s #{url}") : do_cmd(cmd: "#{src_env} ; curl -s -o /dev/null #{url}") # unset reload in config.props - do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}",show_debug) + do_cmd(cmd: "sed -i 's/ReloadWebProfileWithoutRestart=.*/ReloadWebProfileWithoutRestart=0/g' #{prop_file}") # done puts " - #{s}" From 74b628cf1bf92a45c6f1e7a58751fcfde62b1300 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:20:47 -0500 Subject: [PATCH 130/168] Finetine internal output --- lib/psadmin_plus.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0ab1776..00b5323 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -98,6 +98,11 @@ def env(var) end def do_cmd(cmd:, internal: false) + if internal + output = "off" + else + output = PS_PSA_OUTPUT + end prefix = "" suffix = "" case "#{OS_CONST}" @@ -121,7 +126,7 @@ def do_cmd(cmd:, internal: false) end debug "Command: #{prefix}#{cmd}#{suffix}" - runner = Runner.new("#{prefix}#{cmd}#{suffix}", realtime = PS_PSA_OUTPUT) + runner = Runner.new("#{prefix}#{cmd}#{suffix}", realtime = output) runner.run # "internal" is used to bypass output processing for psa internal functions From f05f21d57ae4b6b34f0131af6b189e2e64773adf Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:24:21 -0500 Subject: [PATCH 131/168] Finetine internal output --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 00b5323..1c49961 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -315,7 +315,7 @@ def do_admin def do_list puts "---" - print "hostname: " ; do_cmd(cmd:'hostname', internal: true) + print "hostname: " ; do_cmd(cmd:'hostname') print "ps-home: " ; do_cmd(cmd:'echo ' + env('PS_HOME'), internal: true) if PS_MULTI_HOME == "false" print "ps-cfg-home: " ; do_cmd(cmd:'echo ' + env('PS_CFG_HOME'), internal: true) From b31890340b70bb3f465ef0579ee785b7bbba8b80 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:24:55 -0500 Subject: [PATCH 132/168] Finetine internal output --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 1c49961..13206ac 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -316,9 +316,9 @@ def do_admin def do_list puts "---" print "hostname: " ; do_cmd(cmd:'hostname') - print "ps-home: " ; do_cmd(cmd:'echo ' + env('PS_HOME'), internal: true) + print "ps-home: " ; do_cmd(cmd:'echo ' + env('PS_HOME')) if PS_MULTI_HOME == "false" - print "ps-cfg-home: " ; do_cmd(cmd:'echo ' + env('PS_CFG_HOME'), internal: true) + print "ps-cfg-home: " ; do_cmd(cmd:'echo ' + env('PS_CFG_HOME')) else puts "ps-cfg-home base: #{PS_MULTI_HOME}#{PS_MULTI_DELIMIT}*" end From c7a49056767a1a74b82cd9171a317a6c621b3dc7 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:26:37 -0500 Subject: [PATCH 133/168] Add no banner env --- bin/psa | 1 + lib/psadmin_plus.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/psa b/bin/psa index 93c3ee3..db861a7 100755 --- a/bin/psa +++ b/bin/psa @@ -63,6 +63,7 @@ PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary", "quiet" +PS_PSA_NO_BANNER = ENV['PS_PSA_NO_BANNER'] || "false" # validation # check runtime user diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 13206ac..5884944 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -336,6 +336,7 @@ def do_list puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" puts "PS_PSA_TIMETAMP: #{PS_PSA_TIMESTAMP}" puts "PS_PSA_OUTPUT: #{PS_PSA_OUTPUT}" + puts "PS_PSA_NO_BANNER: #{PS_PSA_NO_BANNER}" puts "" puts "app:" find_apps.each do |a| From 111cc9776c738e1f9811fb76dd4658dec97233c7 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:27:27 -0500 Subject: [PATCH 134/168] Add no banner env --- lib/psadmin_plus.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 5884944..26483b4 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -202,9 +202,11 @@ def do_output(line, err = false) end def do_cmd_banner(c,t,d) - puts "" - puts "===[ #{c} . #{t} . #{d} ]===" - puts "" + if PS_PSA_NO_BANNER != "true" + puts "" + puts "===[ #{c} . #{t} . #{d} ]===" + puts "" + end end def do_set_cfg_home(d) From c9029c433f5a4a9ebaa24603d7558b852138a609 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:30:22 -0500 Subject: [PATCH 135/168] Add misssing cmd: --- lib/psadmin_plus.rb | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 26483b4..4596e72 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -434,12 +434,12 @@ def do_start(type, domain) when "app" case "#{PS_WIN_SERVICES}" when "true", "tux", "app", "all" - do_cmd(start_app_service_cmd) + do_cmd(cmd: start_app_service_cmd) else - do_cmd(start_app_cmd) + do_cmd(cmd: start_app_cmd) case "#{PS_TRAIL_SERVICE}" when "true" - do_cmd(start_app_service_cmd) + do_cmd(cmd: start_app_service_cmd) end end do_hookstart("start",type,domain) @@ -448,12 +448,12 @@ def do_start(type, domain) when "prcs" case "#{PS_WIN_SERVICES}" when "true", "tux", "prcs", "all" - do_cmd(start_prcs_service_cmd) + do_cmd(cmd: start_prcs_service_cmd) else - do_cmd(start_prcs_cmd) + do_cmd(cmd: start_prcs_cmd) case "#{PS_TRAIL_SERVICE}" when "true" - do_cmd(start_prcs_service_cmd) + do_cmd(cmd: start_prcs_service_cmd) end end do_hookstart("start",type,domain) @@ -463,19 +463,19 @@ def do_start(type, domain) if File.exist?("#{ENV['PS_CFG_HOME']}/webserv/#{domain}/servers/PIA/tmp/PIA.lok") puts "Domain #{domain} already started" else - do_cmd(start_web_cmd_lnx) + do_cmd(cmd: start_web_cmd_lnx) sleep 5.0 end when "windows" case "#{PS_WIN_SERVICES}" when "true", "web", "all" - do_cmd(start_web_service_cmd) + do_cmd(cmd: start_web_service_cmd) else # Run command outside of powershell with 'false' parameter - do_cmd(start_web_cmd_win, true, false) + do_cmd(cmd: start_web_cmd_win, true, false) case "#{PS_TRAIL_SERVICE}" when "true", "web", "all" - do_cmd(start_web_service_cmd) + do_cmd(cmd: start_web_service_cmd) end end end @@ -503,12 +503,12 @@ def do_stop(type, domain) do_hookstop("stop",type,domain) case "#{PS_WIN_SERVICES}" when "true" - do_cmd(stop_app_service_cmd) + do_cmd(cmd: stop_app_service_cmd) else - do_cmd(stop_app_cmd) + do_cmd(cmd: stop_app_cmd) case "#{PS_TRAIL_SERVICE}" when "true" - do_cmd(stop_app_service_cmd) + do_cmd(cmd: stop_app_service_cmd) end end when "pubsub" @@ -517,28 +517,28 @@ def do_stop(type, domain) do_hookstop("stop",type,domain) case "#{PS_WIN_SERVICES}" when "true" - do_cmd(stop_prcs_service_cmd) + do_cmd(cmd: stop_prcs_service_cmd) else - do_cmd(stop_prcs_cmd) + do_cmd(cmd: stop_prcs_cmd) case "#{PS_TRAIL_SERVICE}" when "true" - do_cmd(stop_prcs_service_cmd) + do_cmd(cmd: stop_prcs_service_cmd) end end when "web" do_hookstop("stop",type,domain) case "#{OS_CONST}" when "linux" - do_cmd(stop_web_cmd_lnx) + do_cmd(cmd: stop_web_cmd_lnx) when "windows" case "#{PS_WIN_SERVICES}" when "true" - do_cmd(stop_web_service_cmd) + do_cmd(cmd: stop_web_service_cmd) else - do_cmd(stop_web_cmd_win, true, false) + do_cmd(cmd: stop_web_cmd_win, true, false) case "#{PS_TRAIL_SERVICE}" when "true" - do_cmd(stop_web_service_cmd) + do_cmd(cmd: stop_web_service_cmd) end end end From 54e2c41a1a2e9151ff1a410548fdbeb1a3400626 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Thu, 15 Jun 2023 15:31:22 -0500 Subject: [PATCH 136/168] Remove ps flag --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4596e72..1711177 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -471,8 +471,8 @@ def do_start(type, domain) when "true", "web", "all" do_cmd(cmd: start_web_service_cmd) else - # Run command outside of powershell with 'false' parameter - do_cmd(cmd: start_web_cmd_win, true, false) + # Run command outside of powershell with 'false' parameter - use powershell now + do_cmd(cmd: start_web_cmd_win) case "#{PS_TRAIL_SERVICE}" when "true", "web", "all" do_cmd(cmd: start_web_service_cmd) From a7c1cdca45af132b4479480068c40f0b844f1ccc Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 07:53:17 -0500 Subject: [PATCH 137/168] Remove ps flag --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 1711177..0ca6bef 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -535,7 +535,7 @@ def do_stop(type, domain) when "true" do_cmd(cmd: stop_web_service_cmd) else - do_cmd(cmd: stop_web_cmd_win, true, false) + do_cmd(cmd: stop_web_cmd_win) case "#{PS_TRAIL_SERVICE}" when "true" do_cmd(cmd: stop_web_service_cmd) From 004752923b07ab8cc46a803a3bb9fe9bafb38172 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:14:24 -0500 Subject: [PATCH 138/168] Adding os-specific join commands --- bin/psa | 5 ++++- lib/psadmin_plus.rb | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/psa b/bin/psa index db861a7..5ca2536 100755 --- a/bin/psa +++ b/bin/psa @@ -68,12 +68,15 @@ PS_PSA_NO_BANNER = ENV['PS_PSA_NO_BANNER'] || "false" # validation # check runtime user if "#{OS_CONST}" == "linux" then + os_join = "&&" + os_set_env = "export " if !system("id #{PS_RUNTIME_USER} &> /dev/null") then puts "#{PS_RUNTIME_USER} is not valid. Please correct PS_RUNTIME_USER, then try again." exit end else - # windows - TODO + os_join = ";" + os_set_env = "$env:" end # process diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0ca6bef..dca507b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -94,7 +94,7 @@ def do_is_runtime_user_win end def env(var) - result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "%#{var}%" + result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "${env:#{var}}" #"%#{var}%" end def do_cmd(cmd:, internal: false) @@ -394,10 +394,10 @@ def do_status(type, domain) do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" do_psadmin_check ? nil : return - do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd(cmd: os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + os_join + " echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "pubsub" do_psadmin_check ? nil : return - do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + os_join + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") @@ -444,7 +444,7 @@ def do_start(type, domain) end do_hookstart("start",type,domain) when "pubsub" - do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + os_join + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" case "#{PS_WIN_SERVICES}" when "true", "tux", "prcs", "all" From a21a4c060c827cbd7730bab3db620be8330d6f78 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:16:23 -0500 Subject: [PATCH 139/168] Testing instance vars --- lib/psadmin_plus.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index dca507b..fe14d43 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -22,6 +22,14 @@ module PsadminPlus end end + if "#{OS_CONST}" == "linux" then + @@os_join = "&&" + @@os_set_env = "export " + else + @@os_join = ";" + @@os_set_env = "$env:" + end + def do_help puts "Usage: psa [command] " puts " " @@ -394,10 +402,10 @@ def do_status(type, domain) do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" do_psadmin_check ? nil : return - do_cmd(cmd: os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + os_join + " echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd(cmd: @@os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + @@os_join + " echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "pubsub" do_psadmin_check ? nil : return - do_cmd(cmd: os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + os_join + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: @@os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + @@os_join + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") @@ -444,7 +452,7 @@ def do_start(type, domain) end do_hookstart("start",type,domain) when "pubsub" - do_cmd(cmd: os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + os_join + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: @@os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + @@os_join + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" case "#{PS_WIN_SERVICES}" when "true", "tux", "prcs", "all" From 088509c026e4496782d87f2c2f52e8b7657a7aa0 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:17:19 -0500 Subject: [PATCH 140/168] Using method --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index fe14d43..1899fa5 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -22,7 +22,7 @@ module PsadminPlus end end - if "#{OS_CONST}" == "linux" then + if os == "linux" then @@os_join = "&&" @@os_set_env = "export " else From 1d6905fe712d286a6e72104bac4b03c847c3359b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:20:04 -0500 Subject: [PATCH 141/168] Using contasnts --- bin/psa | 10 +++++----- lib/psadmin_plus.rb | 14 +++----------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/bin/psa b/bin/psa index 5ca2536..96b12ef 100755 --- a/bin/psa +++ b/bin/psa @@ -66,17 +66,17 @@ PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary PS_PSA_NO_BANNER = ENV['PS_PSA_NO_BANNER'] || "false" # validation -# check runtime user +# check runtime user and set OS constants if "#{OS_CONST}" == "linux" then - os_join = "&&" - os_set_env = "export " + OS_JOIN = "&&" + OS_SETENV = "export " if !system("id #{PS_RUNTIME_USER} &> /dev/null") then puts "#{PS_RUNTIME_USER} is not valid. Please correct PS_RUNTIME_USER, then try again." exit end else - os_join = ";" - os_set_env = "$env:" + OS_SETENV = ";" + OS_SETENV = "$env:" end # process diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 1899fa5..6faa626 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -22,14 +22,6 @@ module PsadminPlus end end - if os == "linux" then - @@os_join = "&&" - @@os_set_env = "export " - else - @@os_join = ";" - @@os_set_env = "$env:" - end - def do_help puts "Usage: psa [command] " puts " " @@ -402,10 +394,10 @@ def do_status(type, domain) do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" do_psadmin_check ? nil : return - do_cmd(cmd: @@os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + @@os_join + " echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "pubsub" do_psadmin_check ? nil : return - do_cmd(cmd: @@os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + @@os_join + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" do_psadmin_check ? nil : return do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") @@ -452,7 +444,7 @@ def do_start(type, domain) end do_hookstart("start",type,domain) when "pubsub" - do_cmd(cmd: @@os_set_env + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + @@os_join + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "prcs" case "#{PS_WIN_SERVICES}" when "true", "tux", "prcs", "all" From d19958bcfa054cb0c9035c3026df4d07c09533f0 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:22:36 -0500 Subject: [PATCH 142/168] moving constant init --- bin/psa | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/psa b/bin/psa index 96b12ef..13346f2 100755 --- a/bin/psa +++ b/bin/psa @@ -64,19 +64,18 @@ PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary", "quiet" PS_PSA_NO_BANNER = ENV['PS_PSA_NO_BANNER'] || "false" +OS_JOIN = "#{OS_CONST}" == "linux" ? "&&" : ";" +OS_SETENV = "#{OS_CONST}" == "linux" ? "export " : "$env:" # validation -# check runtime user and set OS constants +# check runtime user if "#{OS_CONST}" == "linux" then - OS_JOIN = "&&" - OS_SETENV = "export " if !system("id #{PS_RUNTIME_USER} &> /dev/null") then puts "#{PS_RUNTIME_USER} is not valid. Please correct PS_RUNTIME_USER, then try again." exit end else - OS_SETENV = ";" - OS_SETENV = "$env:" + # nothing end # process From 1cdb38534abd36b20506b25369e3e3a68bef085e Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:24:59 -0500 Subject: [PATCH 143/168] Remove extra timestamp param --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 6faa626..d910a9b 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -152,7 +152,7 @@ def process_output(stdout:, stderr:, success:) when true debug "command success" when false - do_output("psadmin returned an error", timestamp, true) + do_output("psadmin returned an error", true) if PS_PSA_OUTPUT == "summary" || PS_PSA_OUTPUT == "quiet" print_std(std:stderr, err: true) end From 076998a28c718bc4c4d3deded95e4915bb128a14 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:43:14 -0500 Subject: [PATCH 144/168] Fixing tux commands on windows --- lib/psadmin_plus.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index d910a9b..6dd36c1 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -394,10 +394,20 @@ def do_status(type, domain) do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -c pslist -d #{domain}") when "tux" do_psadmin_check ? nil : return - do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + case "#{OS_CONST}" + when "linux" + do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") + when "windows" + do_cmd(cmd: "$env:TUXCONFIG=\"#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG\"; 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r ") + end when "pubsub" do_psadmin_check ? nil : return - do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + case "#{OS_CONST}" + when "linux" + do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + when "windows" + do_cmd(cmd: "$env:TUXCONFIG=\"#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG\"; 'printserver -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") + end when "prcs" do_psadmin_check ? nil : return do_cmd(cmd: "#{PS_PSADMIN_PATH}/psadmin -p status -d #{domain}") @@ -444,7 +454,12 @@ def do_start(type, domain) end do_hookstart("start",type,domain) when "pubsub" - do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + case "#{OS_CONST}" + when "linux" + do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + when "windows" + do_cmd(cmd: "$env:TUXCONFIG=\"#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") + end when "prcs" case "#{PS_WIN_SERVICES}" when "true", "tux", "prcs", "all" From dde7cc8c2e9c0a8f915b85103622fd29fff97d8d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 08:46:44 -0500 Subject: [PATCH 145/168] Fixing tux commands on windows --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 6dd36c1..4c36dfe 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -398,7 +398,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "$env:TUXCONFIG=\"#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG\"; 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r ") end when "pubsub" do_psadmin_check ? nil : return @@ -406,7 +406,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "windows" - do_cmd(cmd: "$env:TUXCONFIG=\"#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG\"; 'printserver -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'printserver -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end when "prcs" do_psadmin_check ? nil : return @@ -458,7 +458,7 @@ def do_start(type, domain) when "linux" do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "windows" - do_cmd(cmd: "$env:TUXCONFIG=\"#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end when "prcs" case "#{PS_WIN_SERVICES}" From d979df99f1fdd5c84d5cfd08d3785bdfab1714db Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:27:50 -0500 Subject: [PATCH 146/168] Testing cmd /c for tux stats --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4c36dfe..0529df2 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -398,7 +398,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd(cmd: "cmd / set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r ") end when "pubsub" do_psadmin_check ? nil : return From 1332878cef824d948040dbff2cb7cc37107958f8 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:29:02 -0500 Subject: [PATCH 147/168] Forgot c --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 0529df2..4982e56 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -398,7 +398,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "cmd / set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r ") + do_cmd(cmd: "cmd /c 'set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r '") end when "pubsub" do_psadmin_check ? nil : return From 448626ab67d0a4f0c6da46ca904faa8ffe0c530d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:29:23 -0500 Subject: [PATCH 148/168] Add echo --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 4982e56..aee7493 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -398,7 +398,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "cmd /c 'set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r '") + do_cmd(cmd: "cmd /c 'set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & echo 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r '") end when "pubsub" do_psadmin_check ? nil : return From 667fac25ef5509a1e903435ba26a97bf0c8a1180 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:29:48 -0500 Subject: [PATCH 149/168] Remove dot --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index aee7493..861832e 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -398,7 +398,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "cmd /c 'set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & echo 'pq' | . " + env('TUXDIR') + "/bin/tmadmin -r '") + do_cmd(cmd: "cmd /c 'set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & echo 'pq' | " + env('TUXDIR') + "/bin/tmadmin -r '") end when "pubsub" do_psadmin_check ? nil : return From 6850c84c00817b66c55fc3138fefa43066c4f275 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:32:03 -0500 Subject: [PATCH 150/168] Change envs for cmd --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 861832e..71ca3bf 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -398,7 +398,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "cmd /c 'set TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\" & echo 'pq' | " + env('TUXDIR') + "/bin/tmadmin -r '") + do_cmd(cmd: "cmd /c set TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG & echo 'pq' | #{ENV['TUXDIR']}/bin/tmadmin -r") end when "pubsub" do_psadmin_check ? nil : return From e7822e625d1dd6ff8642c081608be07b2e5bb947 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:34:26 -0500 Subject: [PATCH 151/168] Add powershell flag back to do_cmd --- lib/psadmin_plus.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 71ca3bf..9419f50 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -97,7 +97,7 @@ def env(var) result = "#{OS_CONST}" == "linux" ? "${#{var}}" : "${env:#{var}}" #"%#{var}%" end - def do_cmd(cmd:, internal: false) + def do_cmd(cmd:, internal: false, powershell: true) if internal output = "off" else @@ -119,8 +119,13 @@ def do_cmd(cmd:, internal: false) end end when "windows" - prefix = "powershell -NoProfile -Command \"" - suffix = "\"" + if powershell + prefix = "powershell -NoProfile -Command \"" + suffix = "\"" + else + prefix = "cmd /c " + suffix = "" + end else puts "Invalid OS" end @@ -398,7 +403,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "cmd /c set TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG & echo 'pq' | #{ENV['TUXDIR']}/bin/tmadmin -r") + do_cmd(cmd: "set TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG & echo 'pq' | #{ENV['TUXDIR']}/bin/tmadmin -r", powershell: false) end when "pubsub" do_psadmin_check ? nil : return From fd7b92051dd016e1dc180d8d0731670941d4d37d Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:36:24 -0500 Subject: [PATCH 152/168] Switch path separator --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 9419f50..6aabf2f 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -403,7 +403,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "set TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG & echo 'pq' | #{ENV['TUXDIR']}/bin/tmadmin -r", powershell: false) + do_cmd(cmd: "set TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG & echo 'pq' | #{ENV['TUXDIR']}\\bin\\tmadmin -r", powershell: false) end when "pubsub" do_psadmin_check ? nil : return From b06a8bb49ed4073808e3f56b04e34deb106d3c2b Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:37:04 -0500 Subject: [PATCH 153/168] Enable debug for now --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index 13346f2..43814c1 100755 --- a/bin/psa +++ b/bin/psa @@ -60,7 +60,7 @@ PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" PS_MULTI_DELIMIT = ENV['PS_MULTI_DELIMIT'] || "/" PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0 PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" -PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" +PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "DEBUG" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary", "quiet" PS_PSA_NO_BANNER = ENV['PS_PSA_NO_BANNER'] || "false" From 72cc25d56c5d271920e14348c4fcfb930b9c6b76 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:45:13 -0500 Subject: [PATCH 154/168] Quote cmd /c commands --- bin/psa | 2 +- lib/psadmin_plus.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/psa b/bin/psa index 43814c1..13346f2 100755 --- a/bin/psa +++ b/bin/psa @@ -60,7 +60,7 @@ PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" PS_MULTI_DELIMIT = ENV['PS_MULTI_DELIMIT'] || "/" PS_MULTI_PREFIX = ENV['PS_MULTI_PREFIX'].to_i || 0 PS_PARALLEL_BOOT = ENV['PS_PARALLEL_BOOT'] || "false" -PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "DEBUG" +PS_PSA_DEBUG = ENV['PS_PSA_DEBUG'] || "INFO" PS_PSA_TIMESTAMP = ENV['PS_PSA_TIMESTAMP'] || "false" PS_PSA_OUTPUT = ENV['PS_PSA_OUTPUT'] || "all" # values are "all", "summary", "quiet" PS_PSA_NO_BANNER = ENV['PS_PSA_NO_BANNER'] || "false" diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 6aabf2f..f3b122e 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -403,7 +403,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "set TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG & echo 'pq' | #{ENV['TUXDIR']}\\bin\\tmadmin -r", powershell: false) + do_cmd(cmd: "\"set TUXCONFIG=#{ENV['PS_CFG_HOME']}\\appserv\\#{domain}\\PSTUXCFG && echo 'pq' | #{ENV['TUXDIR']}\\bin\\tmadmin -r \"", powershell: false) end when "pubsub" do_psadmin_check ? nil : return From 2e49e52ebcd96d2330df6b1edf7dc8e2feef3457 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 09:51:33 -0500 Subject: [PATCH 155/168] Punting on windows support for tux/pubsub for now --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f3b122e..f4b617a 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -403,7 +403,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo pq | " + env('TUXDIR') + "/bin/tmadmin -r ") when "windows" - do_cmd(cmd: "\"set TUXCONFIG=#{ENV['PS_CFG_HOME']}\\appserv\\#{domain}\\PSTUXCFG && echo 'pq' | #{ENV['TUXDIR']}\\bin\\tmadmin -r \"", powershell: false) + #do_cmd(cmd: "\"set TUXCONFIG=#{ENV['PS_CFG_HOME']}\\appserv\\#{domain}\\PSTUXCFG && echo 'pq' | #{ENV['TUXDIR']}\\bin\\tmadmin -r \"", powershell: false) end when "pubsub" do_psadmin_check ? nil : return @@ -411,7 +411,7 @@ def do_status(type, domain) when "linux" do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "windows" - do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'printserver -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") + #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'printserver -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end when "prcs" do_psadmin_check ? nil : return @@ -463,7 +463,7 @@ def do_start(type, domain) when "linux" do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") when "windows" - do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") + #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end when "prcs" case "#{PS_WIN_SERVICES}" From ad46b10aad6bedd38dce09459d938afa0b6a19e2 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 10:12:54 -0500 Subject: [PATCH 156/168] Adding bash test script --- test/test.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/test.sh diff --git a/test/test.sh b/test/test.sh new file mode 100644 index 0000000..15f1305 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Build the array of commands to test +commands=( + "status" + "stop" + "start" + "status tux" + "status pubsub" + "restart" + "bounce" +) + +# Loop through the array and execute each command +for cmd in "${commands[@]}" +do + echo "Executing command: $cmd" + eval "bin/psa $cmd" + + # Verify the result of the command + if [ $? -eq 0 ]; then + echo "Test succeeded" + else + echo "Test failed" + fi + + echo +done From 1c9284cef841a4a12eb0a3b6e987719f09b27348 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 10:13:25 -0500 Subject: [PATCH 157/168] Adding bash test script --- test/test.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/test.sh diff --git a/test/test.sh b/test/test.sh old mode 100644 new mode 100755 From 228a9aca77310e51e8895ab3ef6a376755679567 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 10:17:35 -0500 Subject: [PATCH 158/168] Add powershell test script --- test/test.ps1 | 23 +++++++++++++++++++++++ test/test.sh | 4 +--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/test.ps1 diff --git a/test/test.ps1 b/test/test.ps1 new file mode 100644 index 0000000..d0f4117 --- /dev/null +++ b/test/test.ps1 @@ -0,0 +1,23 @@ +# Build the array of commands to test +$commands = @( + "status", + "status tux", + "status pubsub", + "bounce", + "list" +) + +# Loop through the array and execute each command +foreach ($cmd in $commands) { + Write-Host "Executing command: $cmd" + Invoke-Expression "bin/psa $cmd" + + # Verify the result of the command + if ($LASTEXITCODE -eq 0) { + Write-Host "Command succeeded" + } else { + Write-Host "Command failed" + } + + Write-Host +} \ No newline at end of file diff --git a/test/test.sh b/test/test.sh index 15f1305..97366ac 100755 --- a/test/test.sh +++ b/test/test.sh @@ -3,12 +3,10 @@ # Build the array of commands to test commands=( "status" - "stop" - "start" "status tux" "status pubsub" - "restart" "bounce" + "list" ) # Loop through the array and execute each command From b140527f5d8aaaba8cea0c7de25cfd10f6f2a685 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 10:22:51 -0500 Subject: [PATCH 159/168] Add env var tests --- test/test.ps1 | 15 +++++++++++++++ test/test.sh | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/test/test.ps1 b/test/test.ps1 index d0f4117..cb480db 100644 --- a/test/test.ps1 +++ b/test/test.ps1 @@ -7,9 +7,24 @@ $commands = @( "list" ) +# Build the array of environment variables to set +$variables = @( + "PS_PSA_OUTPUT=all", + "PS_PSA_OUTPUT=summary", + "PS_PSA_TIMESTAMP=true", + "PS_PSA_DEBUG=DEBUG" +) + # Loop through the array and execute each command foreach ($cmd in $commands) { Write-Host "Executing command: $cmd" + + # Set the environment variables for the current command + foreach ($var in $variables) { + $envVar = $var -split "=" + Set-Item -Path "env:$($envVar[0])" -Value $envVar[1] + } + Invoke-Expression "bin/psa $cmd" # Verify the result of the command diff --git a/test/test.sh b/test/test.sh index 97366ac..672cd37 100755 --- a/test/test.sh +++ b/test/test.sh @@ -9,10 +9,25 @@ commands=( "list" ) +# Build the array of environment variables to set +variables=( + "PS_PSA_OUTPUT=all" + "PS_PSA_OUTPUT=summary" + "PS_PSA_TIMESTAMP=true" + "PS_PSA_DEBUG=DEBUG" +) + # Loop through the array and execute each command for cmd in "${commands[@]}" do echo "Executing command: $cmd" + + # Set the environment variables for the current command + for var in "${variables[@]}" + do + export "$var" + done + eval "bin/psa $cmd" # Verify the result of the command From 509f137e00a4b1c0bfc9afb999e454c92761a535 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 10:24:25 -0500 Subject: [PATCH 160/168] loop through env var tests --- test/test.ps1 | 14 +++++++------- test/test.sh | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/test.ps1 b/test/test.ps1 index cb480db..55eb54a 100644 --- a/test/test.ps1 +++ b/test/test.ps1 @@ -23,15 +23,15 @@ foreach ($cmd in $commands) { foreach ($var in $variables) { $envVar = $var -split "=" Set-Item -Path "env:$($envVar[0])" -Value $envVar[1] - } - Invoke-Expression "bin/psa $cmd" + Invoke-Expression "bin/psa $cmd" - # Verify the result of the command - if ($LASTEXITCODE -eq 0) { - Write-Host "Command succeeded" - } else { - Write-Host "Command failed" + # Verify the result of the command + if ($LASTEXITCODE -eq 0) { + Write-Host "Command succeeded" + } else { + Write-Host "Command failed" + } } Write-Host diff --git a/test/test.sh b/test/test.sh index 672cd37..8672142 100755 --- a/test/test.sh +++ b/test/test.sh @@ -26,16 +26,16 @@ do for var in "${variables[@]}" do export "$var" - done - eval "bin/psa $cmd" + eval "bin/psa $cmd" - # Verify the result of the command - if [ $? -eq 0 ]; then - echo "Test succeeded" - else - echo "Test failed" - fi + # Verify the result of the command + if [ $? -eq 0 ]; then + echo "Test succeeded" + else + echo "Test failed" + fi + done echo done From ebb33988bea372d918a503accff1f29158f2a421 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 12:15:42 -0500 Subject: [PATCH 161/168] Windows - web - use cmd --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index f4b617a..a436fc6 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -491,8 +491,8 @@ def do_start(type, domain) when "true", "web", "all" do_cmd(cmd: start_web_service_cmd) else - # Run command outside of powershell with 'false' parameter - use powershell now - do_cmd(cmd: start_web_cmd_win) + # Run command outside of powershell with 'false' parameter + do_cmd(cmd: start_web_cmd_win, powershell: false) case "#{PS_TRAIL_SERVICE}" when "true", "web", "all" do_cmd(cmd: start_web_service_cmd) @@ -555,7 +555,7 @@ def do_stop(type, domain) when "true" do_cmd(cmd: stop_web_service_cmd) else - do_cmd(cmd: stop_web_cmd_win) + do_cmd(cmd: stop_web_cmd_win, powershell: false) case "#{PS_TRAIL_SERVICE}" when "true" do_cmd(cmd: stop_web_service_cmd) From 51e657b3fc471c8341db459c76f272688c26d731 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 12:31:28 -0500 Subject: [PATCH 162/168] Remove dup cmd /c --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index 13346f2..8697a74 100755 --- a/bin/psa +++ b/bin/psa @@ -53,7 +53,7 @@ PS_HOOK_POST = ENV['PS_HOOK_POST'] || "false" PS_HOOK_START = ENV['PS_HOOK_START'] || "false" PS_HOOK_STOP = ENV['PS_HOOK_STOP'] || "false" PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on" -PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "cmd /c #{env('PS_HOME')}/appserv" +PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "#{env('PS_HOME')}/appserv" PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false" PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false" PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" From b4557625506363857cccd02b8bae7e922ef35dc0 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 12:32:15 -0500 Subject: [PATCH 163/168] change windows psadmin path --- bin/psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/psa b/bin/psa index 8697a74..3204bba 100755 --- a/bin/psa +++ b/bin/psa @@ -53,7 +53,7 @@ PS_HOOK_POST = ENV['PS_HOOK_POST'] || "false" PS_HOOK_START = ENV['PS_HOOK_START'] || "false" PS_HOOK_STOP = ENV['PS_HOOK_STOP'] || "false" PS_PSA_SUDO = ENV['PS_PSA_SUDO'] || "on" -PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "#{env('PS_HOME')}/appserv" +PS_PSADMIN_PATH = "#{OS_CONST}" == "linux" ? "#{env('PS_HOME')}/bin" : "#{ENV['PS_HOME']}/appserv" PS_WIN_SERVICES = ENV['PS_WIN_SERVICES'] || "false" PS_TRAIL_SERVICE = ENV['PS_TRAIL_SERVICE'] || "false" PS_MULTI_HOME = ENV['PS_MULTI_HOME'] || "false" From 90bb6c0db7860ce52f10351abcd35da019ac5da5 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 13:00:45 -0500 Subject: [PATCH 164/168] Add shutdown for pubsub --- README.md | 13 +++++++++++++ lib/psadmin_plus.rb | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 996ff75..ec68067 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,19 @@ Environment variables are used to control `psadmin-plus` and `psadmin` functiona * Sets the hook script to run before the `stop` command and after the `start` command. * Examples are found in `lib/hooks`. * If not set, default is `false` and no hook is triggered. +* `PS_PSA_OUTPUT` + * `all` - the default - shows normal output like past versions + * `summary` - only show stdout (plus a few special lines from stderr like "x processes started" but reprocessed into stdout. This will help with Rundeck and other tools to keep stderr from being polluted with informational messages. + * `quiet` - hide all output - you can use exit codes from `psa`. On errors, `psa` will display stderr from `psadmin`. +* `PS_PSA_TIMESTAMP` + * `true` - each line will have a timestamp prepended to it - useful with `psa status tux APPDOM` to output the Tuxedo Queue stats to file + * `false` - default +* `PS_PSA_NO_BANNER` + * `true` - do not display the command banner - useful with the `PS_PSA_OUTPUT=quiet` option + * `false` - default +* `PS_PSA_DEBUG` + * `INFO` - default - only display informational messages + * `DEBUG` - display debug output including commands ## Configuration File diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index a436fc6..a980fc9 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -532,7 +532,12 @@ def do_stop(type, domain) end end when "pubsub" - do_cmd(cmd: "export TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG && echo shutdown -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + case "#{OS_CONST}" + when "linux" + do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo shutdown -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + when "windows" + #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") + end when "prcs" do_hookstop("stop",type,domain) case "#{PS_WIN_SERVICES}" From 4533a7bfbee1485932c789e53469f8fbcc8e16e4 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 13:02:01 -0500 Subject: [PATCH 165/168] Fix PS_PSA_TIMESTAMP typo: --- lib/psadmin_plus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index a980fc9..9e94496 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -341,7 +341,7 @@ def do_list puts "PS_MULTI_HOME: #{PS_MULTI_HOME}" puts "PS_PARALLEL_BOOT: #{PS_PARALLEL_BOOT}" puts "PS_PSA_DEBUG: #{PS_PSA_DEBUG}" - puts "PS_PSA_TIMETAMP: #{PS_PSA_TIMESTAMP}" + puts "PS_PSA_TIMESTAMP: #{PS_PSA_TIMESTAMP}" puts "PS_PSA_OUTPUT: #{PS_PSA_OUTPUT}" puts "PS_PSA_NO_BANNER: #{PS_PSA_NO_BANNER}" puts "" From 61c75c7e05c2f6bd7bf3706d255b2a35321d89df Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 13:04:40 -0500 Subject: [PATCH 166/168] Full paths for tmadmin --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 9e94496..9b55772 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -409,7 +409,7 @@ def do_status(type, domain) do_psadmin_check ? nil : return case "#{OS_CONST}" when "linux" - do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo printserver -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | #{ENV['TUXDIR']}/bin/tmadmin -r") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'printserver -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end @@ -461,7 +461,7 @@ def do_start(type, domain) when "pubsub" case "#{OS_CONST}" when "linux" - do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo boot -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin -r") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end @@ -534,7 +534,7 @@ def do_stop(type, domain) when "pubsub" case "#{OS_CONST}" when "linux" - do_cmd(cmd: OS_SETENV + "TUXCONFIG=#{env('PS_CFG_HOME')}/appserv/#{domain}/PSTUXCFG " + OS_JOIN + " echo shutdown -g PUBSUB | " + env('TUXDIR') + "/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin -r") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end From c9fd11e78827575246d1bddf1d9c809d2db8d9ce Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 13:08:05 -0500 Subject: [PATCH 167/168] Revert for TUXDIR --- lib/psadmin_plus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index 9b55772..c6e13a3 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -409,7 +409,7 @@ def do_status(type, domain) do_psadmin_check ? nil : return case "#{OS_CONST}" when "linux" - do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | #{ENV['TUXDIR']}/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo printserver -g PUBSUB | #{env('TUXDIR')}/bin/tmadmin -r") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'printserver -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end @@ -461,7 +461,7 @@ def do_start(type, domain) when "pubsub" case "#{OS_CONST}" when "linux" - do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo 'boot -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo boot -g PUBSUB | #{env('TUXDIR')}/bin/tmadmin -r") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end @@ -534,7 +534,7 @@ def do_stop(type, domain) when "pubsub" case "#{OS_CONST}" when "linux" - do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo 'shutdown -g PUBSUB' | #{ENV['TUXDIR']}/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo shutdown -g PUBSUB | #{env('TUXDIR')}/bin/tmadmin -r") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end From 2dbf2c4e33d68f8418934ac454b7b9b00ba19209 Mon Sep 17 00:00:00 2001 From: Dan Iverson Date: Fri, 16 Jun 2023 13:20:40 -0500 Subject: [PATCH 168/168] Change tmadmin call for start/stop --- lib/psadmin_plus.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/psadmin_plus.rb b/lib/psadmin_plus.rb index c6e13a3..2e64105 100644 --- a/lib/psadmin_plus.rb +++ b/lib/psadmin_plus.rb @@ -461,7 +461,7 @@ def do_start(type, domain) when "pubsub" case "#{OS_CONST}" when "linux" - do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo boot -g PUBSUB | #{env('TUXDIR')}/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo boot -g PUBSUB | #{env('TUXDIR')}/bin/tmadmin") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end @@ -534,7 +534,7 @@ def do_stop(type, domain) when "pubsub" case "#{OS_CONST}" when "linux" - do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo shutdown -g PUBSUB | #{env('TUXDIR')}/bin/tmadmin -r") + do_cmd(cmd: "export TUXCONFIG=#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG && echo stop -g PUBSUB | #{env('TUXDIR')}/bin/tmadmin") when "windows" #do_cmd(cmd: "$env:TUXCONFIG=\"#{ENV['PS_CFG_HOME']}/appserv/#{domain}/PSTUXCFG\"; 'boot -g PUBSUB' | . " + env('TUXDIR') + "/bin/tmadmin -r") end