Score:0

Script to Automatically Start a glassfish domain once it's down?

qa flag

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
Score:0
in flag

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 avatar
in flag
@achhainsan, yes, it is possible, see my edited answer. But IMHO it is not need as you have consistent output from `asadmin`
Romeo Ninov avatar
in flag
@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 avatar
in flag
@achhainsan, I see, thank you for clarification. The info i have is for GlassFish 3.xx :)
achhainsan avatar
qa flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/147720/discussion-between-achhainsan-and-romeo-ninov).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.