x
login Signup

Programmatic updates to Commander -- how to test for server ready?

I do frequent Electric Commander installations through scripts. I've been using sleep statements to wait for the Commander server to come back to life so as to avoid timeout on subsequent ectool commands. There's got to be a better way.

avatar image By gregm 2k asked Nov 25, 2014 at 01:59 PM
more ▼
(comments are locked)
10|750 characters needed characters left

4 answers: sort voted first

In bash you can do this:

 function login {
     ectool --server commanderServerName login user password || login # retry if timeout
 }
 
 login 
avatar image By gregm 2k answered Nov 25, 2014 at 02:01 PM
more ▼
(comments are locked)
10|750 characters needed characters left

You can use the getServerStatus API call and set it to block for a terminal state. You can increase the timeout if the default is not long enough. See the documentation for getServerStatus.

avatar image By tanay ♦ 3.4k answered Nov 25, 2014 at 02:11 PM
more ▼
(comments are locked)
10|750 characters needed characters left

ectool getServerStatus behaves the same as ectool login... it will hang/timeout until the Commander server comes back to life. You can use '/etc/init.d/commanderServer status' to get a non-blocking/hanging response:

 function ecstatus {
         /etc/init.d/commanderServer status | grep 'is running' || (echo "Not running";sleep 5;ecstatus)
 }
 
 ecstatus


avatar image By gregm 2k answered Nov 25, 2014 at 02:43 PM
more ▼
(comments are locked)
avatar image tanay ♦ Nov 25, 2014 at 02:47 PM

Don't you want the call to block to "avoid timeout on subsequent ectool commands"? Or did I misunderstand the original question?

avatar image gregm Nov 25, 2014 at 02:53 PM

Yes, this will block until Commander server 'is running'.

avatar image tanay ♦ Nov 25, 2014 at 02:57 PM

getServerStatus should also block until the server is running. Is the concern that it will timeout if it isn't up and running quickly? Then you can simply increase the timeout by adding --timeout 300 or something.

avatar image tanay ♦ Nov 25, 2014 at 03:00 PM

Using the /etc/init.d/commanderServer status method doesn't protect against the possibility that the server fails to start up correctly. The possible terminal states for the server are running, failed, stopping, and importFailed. If the server is in a non-running terminal state, the script will run forever but the server will never reach "running".

avatar image gregm Nov 25, 2014 at 03:00 PM +

Yes, you can use ectool getServerStatus instead of ectool login in my first example. I used login because I needed to do ectool operations immediately after.

As for increasing the timeout, I'd prefer not to have any timing-dependencies.

10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.