0

Steps to reproduce this issue:

  1. Glassfish domain called domain1 goes down.

  2. Now, start that domain again.

Assume there are multiple domains, around 8 of them And different servers have varying amount of domains. Also there are some domains that either are named "backup" or named with "*_bak" should not be started. Also the domains that have numbers in it should be avoided to start. Also the domains that have *.tar.gz or *.tar extension should not be started. Anything named "watchdog" should not be started. Anything named "domains_mpf" should not be started. Anything named "admin_newlive" also should not be started.

My pseudocode:

domain_array = get list of all domains in an array

for (i = 0; i < domain_array.length; i++)

{
    if (path / to / asadmin stop - domain domain_array[i] == 0 && domain_array[i] != (list of excluded domains)) //assuming exit code 0 returns if the domain is already stopped
    {
        path / to / asadmin start - domain domain_array[i];
    } else

    {
        do nothing
    }

}

Output of asadmin list-domains
abcd running
efgh running
ijkl running
mnop running
qrst running
uvwx running
uvwx_bak not running
wxyz not running
achhainsan
  • 123
  • 7

1 Answers1

0

You can filter not running domains based on asadmin result. Something like can do the work:

for i in $(asadmin list-domains|awk '/Not Running/ {print $2}')
do
asadmin start-domain "$i"
done

If you have space or special symbol in domain name this can make the script nonoperational

P.S. Or you may try restart-domain command which may do better work in some cases.

If you want to make the search in awk in this case you can use command like:

asadmin list-domains|awk 'tolower($(NF-1)" "$NF)=="not running" {print $2}'

With new format it should be:

asadmin list-domains|awk 'tolower($(NF-1)" "$NF)=="not running" {print $1}'

To exclude domains with number, _bak or _backup you can try something like:

asadmin list-domains|awk 'tolower($(NF-1)" "$NF)=="not running" &&  !/_bak/ && !/_backup/ && !/[0-9]/ {print $1}'
Romeo Ninov
  • 5,263
  • 4
  • 20
  • 26
  • @achhainsan, yes, it is possible, see my edited answer. But IMHO it is not need as you have consistent output from `asadmin` – Romeo Ninov Aug 06 '23 at 09:16
  • @achhainsanm the variable `NF` represent the position of last token/word in the row. `NF-1` is this one before last. Adding `$(NF-1)" "$NF` I print the last two words in line (with space between). – Romeo Ninov Aug 06 '23 at 09:25
  • @achhainsan, I see, thank you for clarification. The info i have is for GlassFish 3.xx :) – Romeo Ninov Aug 06 '23 at 09:31
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/147720/discussion-between-achhainsan-and-romeo-ninov). – achhainsan Aug 06 '23 at 09:33