salt icon indicating copy to clipboard operation
salt copied to clipboard

Handling restarts and the continuation of jobs.

Open gravyboat opened this issue 13 years ago • 17 comments

This issue comes from the IRC where a discussion sprung up on the best way to handle reboots for updates or other tasks. As an example I need to perform the following actions:

  1. Rename a file to pull it from a load balancer.
  2. Update a package.
  3. Reboot the server.
  4. Run highstate to put the file back in place, or perform other tasks.

When broken down really what I'd like to accomplish (to cover more use cases) is to:

  1. Perform a task.
  2. Reboot the server.
  3. Run highstate on that server.

We discussed the idea of using both overstate, as well as states.over, but ran into concerns regarding the shutdown/reboot process where another command could be inserted between the time a shutdown/reboot command is issued, and when the machine actually starts killing processes, so a highstate could be in the middle of running during the reboot, and be marked as complete, thus never running when the machine comes back up.

Are there plans to implement something that would allow for the application of a highstate, or continuation of jobs after the reboot is complete? Or perhaps we're missing something and a solution to this use case already exists?

gravyboat avatar Aug 19 '13 22:08 gravyboat

Questions like this might be more suited for the salt-users mailing list: https://groups.google.com/forum/?fromgroups#!forum/salt-users

You can also have the minion run a highstate on start. Put the following in your minion config:

startup_states: highstate

basepi avatar Aug 20 '13 23:08 basepi

+1 on this feature. Would really appreciate it!

mbrgm avatar Dec 03 '13 16:12 mbrgm

Yes, this would in fact be awesome. However, it will take some extensive work to make it so we can resume an in-progress state run after a reboot. I wouldn't plan on it in the near future, but it will definitely be a good feature to have eventually.

basepi avatar Dec 03 '13 23:12 basepi

dave_den suggested that, as the minion has the entire highstate data, it would be possible to marshall everything to disk and have the minion check it upon restart after the reboot.

mbrgm avatar Dec 04 '13 07:12 mbrgm

I would love to have this feature as well.

gtmacdonald avatar Apr 09 '14 23:04 gtmacdonald

+1 for this feature.

Use case here: I'm adding support for setting the primary DNS suffix in states/win_dns_client.py. After setting the primary DNS suffix in the registry, a reboot is required to actually apply the setting and return success.

As long as the reboot isn't issued, the state has to be considered to be in progress.

Besides that, the implementation of this feature should allow to deal with delayed reboots, e.g. for clients which need to be rebooted manually by users as forcing an immediate reboot would forcingly shut down applications currently in use resulting in data loss + angry users :)

eliasp avatar Apr 24 '14 20:04 eliasp

+1 on this feature as well

I have to say that it is really strange that a state like the one below is able to run and return to the master

service salt-minion restart:
  cmd.run

I thought that the minion was saving the state of the service to disk before restarting as @mbrgm mentioned, but I guess I was wrong ... :confused:

ranl avatar May 14 '14 17:05 ranl

Well, saving state to disk would be one possibility, but afaik it is not yet implemented.

Am 14.05.2014 um 19:03 schrieb Ran Leibman [email protected]:

+1 on this feature as well

I have to say that it is really strange that a state like the one below is able to run and return to the master

service salt-minion restart: cmd.run I thought that the minion was saving the state of the service to disk before restarting as @mbrgm mentioned, but I guess I was wrong ...

— Reply to this email directly or view it on GitHub.

mbrgm avatar May 14 '14 18:05 mbrgm

I'm a tad late to this ticket. This use-case was the impetus for the state.event runner. I think a similar approach could work for state.orchestrate. The basic idea is kick off a task (say, a reboot) then start watching Salt's event bus and block until some event-condition is met. Something like saltmod.wait_for_event with a syntax something like:

wait_for_reboot:
  salt.wait_for_event:
    - name: salt/minion/*/start
    # Wait for a certain number of that event:
    - count: 10
    # Or wait for that event from a certain list of minion ids:
    - id_list:
      - jerry
      - stuart
      - dave
      - phil
      - kevin
      - mike

whiteinge avatar May 16 '14 18:05 whiteinge

++ for the state.orchestrate idea. It would be straightforward to orchestrate states that include a restart, then wait for the minion to restart (either a static wait time or a more elaborate event-driven wait) and then continue the state run.

basepi avatar May 19 '14 20:05 basepi

+1 need it when i change kernel, and reboot and continue some actions

lparmentier-quatral avatar Aug 02 '14 21:08 lparmentier-quatral

I'm putting together a pull request with the above-mentioned addition. Written, just in need of testing.

whiteinge avatar Aug 04 '14 13:08 whiteinge

Will this implementation be purely overstate based or will I also be able to require a reboot from within a module's method (e.g. see TODO in states.win_dns.primary_suffix)?

On August 4, 2014 3:38:33 PM CEST, Seth House [email protected] wrote:

I'm putting together a pull request with the above-mentioned addition. Written, just in need of testing.


Reply to this email directly or view it on GitHub: https://github.com/saltstack/salt/issues/6792#issuecomment-51060565

Sent from my Android device with K-9 Mail. Please excuse my brevity.

eliasp avatar Aug 04 '14 16:08 eliasp

@eliasp alas, no. My addition is orchestrate-based.

https://github.com/whiteinge/salt/compare/salt-orchestrate-event

I've been puzzling over your use-case from a minion-centric POV. It's an interesting problem. Here are my thoughts. Having an execution module track state over time feels like the wrong place to do it -- execution modules should be stateless one-offs. Having a state module track state might be better but conflicts philosophically with the idempotent nature of state modules. It feels to me like the best place to enact this is within state sls files themselves:

  1. This workflow with a master-centric POV should definitely be done via something like state.orchestrate where the master can oversee the whole operation, including the reboot, all by running a single orchestrate sls file.

  2. This workflow from a minion-centric POV can be done with one or two state sls files by using the startup_states config option. E.g., make a state that writes an /etc/salt/minion.d/resume.conf file containing which state to run next, then perform the reboot; then the state that runs on startup removes that file. This process feels the most natural to me and improving this workflow would also be a good addition -- off the top of my head, something like adding single-run startup_states that get written somewhere in /var/cache/salt/minion.

  3. Neither of these options are available in masterless-mode since you don't have a running daemon to perform any automatic actions. Something like setting then removing an on-boot cron job in the same vein as startup_states.

whiteinge avatar Aug 05 '14 14:08 whiteinge

Pull request sent: #14935.

whiteinge avatar Aug 12 '14 22:08 whiteinge

@whiteinge Can we close this now? Does the PR from last year fully resolve this? #15212 is still open.

gravyboat avatar Jun 08 '15 22:06 gravyboat

A better interface for making a one-off startup state would still be a good addition but I think you're right that we can close this now.

whiteinge avatar Jun 09 '15 17:06 whiteinge