You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Corerelates to code central or existential to SaltFeaturenew functionality including changes to functionality and code refactors, etc.ZRELEASED - Boronfixed-pls-verifyfix is linked, bug author to confirm fix
There are times when an application can restart almost immediately, but doesn't necessarily start responding for x seconds. In these cases, I'd like the ability to add a wait timer in the batch call.
e.g.
salt -G 'role:webserver' -b 2 --batch-wait 30 cmd.run 'service tomcat restart'
Where it would iterate through all servers matching the grain, performing 2 at a time, with a 30 second wait between each.
I know this has been marked for post 1.0, is there any chance of squeezing it in sooner? If not, we'll look at creating a quick wrapper - I wouldn't have a clue where to even start for coding it into the main app.
Thanks for your response thatch45, fully understand your time commitments, we'll have a look at either adding to batch.py or writing a quick wrapper. Our problem is that for things like tomcat, the init script returns almost immediately, however the daemon can take up to 30sec to fully start before it'll start responding to requests - cases like that, we need an extra buffer to ensure there's no drops in service.
That in and of itself is something to consider, if we should have some provision to wait for daemons to "really" start up. This is something that a lot of daemons do.
I believe this is also how some of the new init replacements like systemd and upstart function too. They will return as soon as they have spawned the various bits that then spawn the services and return immediately. It might be worth bumping up for that alone. Just my 2 cents.
I have applications that have a similar problem: after a restart they may take a few minutes to preload caches. Since that preload (and other tasks) happen in an uWSGI worker process salt will not wait for that to finish. A delay would be a simple system to use here, but perhaps this is better handled witg a verify-state method that can check if 1) a restart is still running, or 2) it failed in some way, for example a daemon started but aborted after backgrounding.
For now I'm coping with adding an explicit sleep to the command to run. cmd.run "restart foo; sleep 30" - this naturally works for parts like cmd.run but not state.sls
Related to this, I think it would be useful if there is was a way to ping a web server before moving on. Sometimes one may implement a /ping path that returns 200 if the server is up and ready to serve requests. This could be more reliable and quicker than a fixed sleep. For example, what if there is a bug? It'd be nice to catch it immediately before rolling it out to all instances. Maybe the service.running state could have a test option of some sort?
@matthayes I'm not convinced that this belongs in batch. I think it's doable without batch mode, and it's hard to generalize inside of batch mode in a useful way.
You could use state.orchestrate, target a subset of the minions to roll out changes, and then have a separate piece of the orchestration, probably using a custom module, to check if the changes were successful
You could also just use a normal state run. Have the minion check for its own web service. Again, if you need custom checks or a loop with a custom timeout to check the service, a custom module is probably the way to go here.
Thanks @basepi , that makes sense. For point 2, how can the minion check its own web service in a state run? Would there need to be a state that checks the web service is responding when it is evaluated? Does such a state exist that can be used? If I were to write a custom module I would need to use something like state.orchestrate as in point 1 right?
I just noticed you can call modules from states. Is this how you'd suggest doing it if I pursued point 2? It seems like I could write a custom module that makes an HTTP call and fails if the response is not 200. Then it seems I could do a normal state run with a wait between each node and it would work great.
You could also easily write a custom state module. It's not covered in as much detail in that youtube video, but it's just as easy. But yes, you have the idea spot on.
That's a decent hack if you want to arbitrarily wait (assuming you don't know how long echo test will take to run). My use case was to run a command everywhere twice per hour. It would be nice to have salt figure out the batch size to make sure the command is triggered (doesn't have to finish) the correct amount of times in a given timespan.
Corerelates to code central or existential to SaltFeaturenew functionality including changes to functionality and code refactors, etc.ZRELEASED - Boronfixed-pls-verifyfix is linked, bug author to confirm fix
Activity
thatch45 commentedon Apr 3, 2012
I will put this on post 1.0.0, I think it is a good idea
halberom commentedon Aug 6, 2012
I know this has been marked for post 1.0, is there any chance of squeezing it in sooner? If not, we'll look at creating a quick wrapper - I wouldn't have a clue where to even start for coding it into the main app.
thatch45 commentedon Aug 6, 2012
I am happy to bump it up, the problem I have right now is that I am beating down bugs and have a lot of back logged features. The batch system also does not work in large groups, but makes sure that n number of minions are working at a time.
But the place to put the code would be here:
https://github.com/saltstack/salt/blob/develop/salt/cli/batch.py
halberom commentedon Aug 7, 2012
Thanks for your response thatch45, fully understand your time commitments, we'll have a look at either adding to batch.py or writing a quick wrapper. Our problem is that for things like tomcat, the init script returns almost immediately, however the daemon can take up to 30sec to fully start before it'll start responding to requests - cases like that, we need an extra buffer to ensure there's no drops in service.
thatch45 commentedon Aug 8, 2012
That in and of itself is something to consider, if we should have some provision to wait for daemons to "really" start up. This is something that a lot of daemons do.
SEJeff commentedon Nov 1, 2012
I believe this is also how some of the new init replacements like systemd and upstart function too. They will return as soon as they have spawned the various bits that then spawn the services and return immediately. It might be worth bumping up for that alone. Just my 2 cents.
wichert commentedon Apr 15, 2013
I have applications that have a similar problem: after a restart they may take a few minutes to preload caches. Since that preload (and other tasks) happen in an uWSGI worker process salt will not wait for that to finish. A delay would be a simple system to use here, but perhaps this is better handled witg a verify-state method that can check if 1) a restart is still running, or 2) it failed in some way, for example a daemon started but aborted after backgrounding.
thatch45 commentedon Apr 22, 2013
I have been doing more work in this area recently and will try to revisit this for 0.16.0
nikosg commentedon Aug 16, 2013
I was wondering if there is any update-progress on the wait timer for batch.
Thank you.
minaguib commentedon Aug 20, 2013
+1
For now I'm coping with adding an explicit sleep to the command to run. cmd.run "restart foo; sleep 30" - this naturally works for parts like cmd.run but not state.sls
basepi commentedon Aug 21, 2013
Issues get forgotten from time to time. I'll put this on the current milestone so we see it more often.
nikosg commentedon Aug 27, 2013
Thank you for your reply. Really much appreciated.
Will keep a close eye on this thread.
19 remaining items
basepi commentedon Nov 11, 2015
No news, but thanks for the bump, I've put some eyes on it.
matthayes commentedon Dec 11, 2015
Related to this, I think it would be useful if there is was a way to ping a web server before moving on. Sometimes one may implement a /ping path that returns 200 if the server is up and ready to serve requests. This could be more reliable and quicker than a fixed sleep. For example, what if there is a bug? It'd be nice to catch it immediately before rolling it out to all instances. Maybe the service.running state could have a test option of some sort?
lpgauth commentedon Dec 11, 2015
@matthayes 👍
basepi commentedon Dec 11, 2015
@matthayes I'm not convinced that this belongs in batch. I think it's doable without batch mode, and it's hard to generalize inside of batch mode in a useful way.
Here are some resources on custom modules:
https://docs.saltstack.com/en/latest/ref/modules/
https://youtu.be/7CxJGglQhxQ
Does that make sense?
Also, the original issue is now implemented, so I'm going to close this issue.
matthayes commentedon Dec 11, 2015
Thanks @basepi , that makes sense. For point 2, how can the minion check its own web service in a state run? Would there need to be a state that checks the web service is responding when it is evaluated? Does such a state exist that can be used? If I were to write a custom module I would need to use something like state.orchestrate as in point 1 right?
matthayes commentedon Dec 11, 2015
I just noticed you can call modules from states. Is this how you'd suggest doing it if I pursued point 2? It seems like I could write a custom module that makes an HTTP call and fails if the response is not 200. Then it seems I could do a normal state run with a wait between each node and it would work great.
basepi commentedon Dec 11, 2015
You could also easily write a custom state module. It's not covered in as much detail in that youtube video, but it's just as easy. But yes, you have the idea spot on.
shinshenjs commentedon Mar 17, 2016
Saw this issue when searching for the feature. As it was not released yet I figured out an easy hack for this case. simply run a sleep afterwards.
salt -G 'app:whatever' -b 1 cmd.run "echo test; sleep 300For highstate, I just put a cmd.run state at the end of top file with the same idea.
Leave it here as it could be helpful before this feature is released.
rothgar commentedon Mar 17, 2016
That's a decent hack if you want to arbitrarily wait (assuming you don't know how long
echo testwill take to run). My use case was to run a command everywhere twice per hour. It would be nice to have salt figure out the batch size to make sure the command is triggered (doesn't have to finish) the correct amount of times in a given timespan.