0

I am calling a script via ssh client like this:

ssh root@host "su - oracle -c '~/bin/weblogic start'"

The ~/bin/weblogic is a bash script that actually starts the web server in the background and reads and displays its log until certain pattern is found ('Server state changed to RUNNING') at which point it exits. When I call it from the remote location it hangs after the last bash command is executed. I am sure it has something to do with what is explained at SO (https://stackoverflow.com/questions/8122780/exiting-shell-script-with-background-processes), however I can't start weblogic bash script in the background - I must wait for it to finish and get its exit code along with regular stdout up to the specific pattern.

The bash code is like this:

   function start_server {
        ~/bin/weblogic.py
        echo 'Python script finished'
        exit 1
   }

   ....
   start_server

The output is

... server output ...
...
... Server state changed to RUNNING ....
Python script finished

How can I make SSH client return ? I am running this on Solaris 11.3.

  • 1
    exit 1 command right after echo 'Python script finished' command, denotes an unsuccessful completion. I am just thinking out loud here but your main script might have a error handling mechanism, which is not letting go the control of your ssh session, because of this erroneous exit code. Did you try with plain exit or exit 0 ? – MelBurslan Jun 27 '16 at 22:02
  • 3
    Likely weblogic isn't releasing stdin/stdout/stderr so the ssh connection still believes there are file handles associated with it, and so not closing. You should rewrite your weblogic.py script to disassociate from all file handles (and from any control terminal) as part of setting up the daemon. – Stephen Harris Jun 28 '16 at 0:39
  • @MelBurslan, exit 1 is irrelevant. It wont be there on final script. It didn't work without any exit whatsoever. – majkinetor Jun 28 '16 at 7:27
  • @StephenHarris, could you take a look at my py script ? I tried nohup without any luck. The gist is here: gist.github.com/majkinetor/4896b9f6c85cc5822bc4b5103ea09f83 – majkinetor Jun 28 '16 at 7:29
2

exit 1 signals an error condition. For a script like this you should not include an exit there.

Try this function instead. You can provide the host and port on the command line for startManagedWeblogic.shm, or you can export the variables before starting the server. If you read the startManagedWebLogic.sh script, you should find a variable you can export before running the script to redirect the output instead of the method I used. You could do the same in your python script.

The WebLogic start scripts run until the server has stopped. You will want to background logging output to a file and disown the server. (Consider using the nodeManager to start the server.) Then tail the file until you get it running.

function start_server {
    ~/bin/startManagedWeblogic.sh HOSTNAME PORT &> weblogic.out &
    disown
    ~/bin/tailUntilRunning.py weblogic.out
    echo 'Shell script finished'

}

There are WLST funtions you can use to start the server, although you will need to use wlst.sh as the interpreter for your python (Jython 2.1) script.

  • I am not sure how to utilize that. The python code is here: gist.github.com/majkinetor/4896b9f6c85cc5822bc4b5103ea09f83 – majkinetor Jun 28 '16 at 7:31
  • My last message is not clear enough. While this works, I don't see a log. I can cat weblogic.out but I need to see it as it progresses, not when everything is finished. – majkinetor Jun 28 '16 at 9:19
  • @majkinetor I've updated with some suggestions. You should split the log tailing from the startup. Startup times are relatively stable in my experience, although they vary depending on the number and type of deployed applications. – BillThor Jun 28 '16 at 13:09
  • Thanks for suggestions @BillThor. I ended up changing the python code as described on reddit: goo.gl/U8cwgV. Much cleaner then bash. – majkinetor Jun 30 '16 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.