Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to restart machine during provision #1983

Closed
majkinetor opened this issue Mar 15, 2015 · 9 comments
Closed

How to restart machine during provision #1983

majkinetor opened this issue Mar 15, 2015 · 9 comments

Comments

@majkinetor
Copy link

I need to restart machine few times after I provision stuff. OS does some lengthy stuff on next boot, for instance Windows after installing updates.

Is it possible to do this ?

I guess I could be able to do this in setup phase, prior to provision, if I delay ssh service installation as the very last thing I can restart the system. However, setup phase has its limitations on Windows (for instance the amount of files you can upload from the host is limited to the floppy size).

@sethvargo
Copy link
Contributor

Hi @majkinetor

You can reboot the machine using the shell provisioner and your OS's reboot command. You can read more about the shell provisioner and rebooting here https://www.packer.io/docs/provisioners/shell.html. Does that answer your question?

@tyrken
Copy link

tyrken commented Mar 16, 2015

We're using OpenSSH & Windows also, and yes the https://github.com/joefitzgerald/packer-windows/blob/master/scripts/win-updates.ps1 trick of doing repeated windows updates & reboots before ever starting OpenSSH works.

For reboots after this we make it the last item in the set of scripts in one provisioner, and then put a minute or two of pause_before setting in the next provisioner to make sure Packer waits at the host. Otherwise OpenSSH can keep running & so the next provisioner starts before the target has finished shutting down pre-reboot. Slow & yucky but usually works, hope to try the WinRM provisioners in https://github.com/packer-community/packer-windows-plugins soon.

@majkinetor
Copy link
Author

Exactly as @tyrken. Slow & yucky and most of all, not good enough. Maybe for your use case that was fine, but in general case you can't always have rebooting script to be the last one.

My problem with start_retry_timeout is that I have single script that calls bunch of other scripts so that I don't need to edit build template all the time.

@mitchellh
Copy link
Contributor

All of the above is the only way to do this, unfortunately. I'd be happy to entertain a better solution, but we haven't found one yet.

@vtolstov
Copy link
Contributor

I think about this. May be add bool variable like need_reboot, and when
script end and ssh not available, wait for connection again...?
14 июня 2015 г. 2:42 пользователь "Mitchell Hashimoto" <
[email protected]> написал:

All of the above is the only way to do this, unfortunately. I'd be happy to
entertain a better solution, but we haven't found one yet.


Reply to this email directly or view it on GitHub
#1983 (comment).

@mitchellh
Copy link
Contributor

@vtolstov Yeah I think for backwards compatbility we likely need to inverse that boolean but yeah probably something like that.

@mconigliaro
Copy link

mconigliaro commented Aug 30, 2016

If you ever end up adding an option like that, it would be nice if it accepted a number of reboots to expect rather than just a boolean. e.g.:

"expect_reboots": 2

That way if you're using an idempotent provisioner, you can just keep running it with the same parameters, and it should pick up where it left off after each reboot.

@wayneworkman
Copy link

@mitchellh What about a packer-native reboot call?
Not everyone's scripts will cause a reboot - the rebooting process for some (like in my case) can happen via a native packer reboot command.
I'll put the reboot provisioner in the order it needs to be.

You can handle the reboot in packer so that it's abstracted as packer aims to be - and handle waiting for the OS to become available again before proceeding.

@mwhooker
Copy link
Contributor

mwhooker commented Jun 8, 2017

@wayneworkman it would be great if you could add your use-case to #4555

@hashicorp hashicorp locked and limited conversation to collaborators Jun 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants