Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I created a flexible EC2 Windows 2008 boot script?

If you look at the Linux ecosystem (especially the Ubuntu and Alestic EC2 images) there is a common technique where the VMs are pre-configured to look at the EC2 user-data and use it as a boot script. The nice thing about this approach is that you can write a boot script that further provisions your machine, allowing you to avoid making a new image every time your software that runs on the machine changes.

I want to do the same thing for Windows, but given that I'm an Mac and Linux guy, I'm a bit lost on where to start. My requirements are:

  • This must run on Windows Server 2008
  • A bootstrap script needs to start when the machine boots up, read the user-data file by pulling down the contents http://169.254.169.254/1.0/user-data
  • The bootstap script then needs to run the contents of that file as if it were a script
  • The script embedded in the user-data needs to run in such a way that it has access to the desktop environment (ie: it can launch a browser, etc).

I'm not quite sure how services work in Windows or if I need to enable auto-login, so any advice here would be appreciated. The ultimate goal is to run a Java program that launches some custom software that in turn launches a web browser (IE, Firefox, etc) and is capable of taking screenshots.

The screenshot part is interesting, because in the past when I've tried this the only way I could get something other than a black screen was to have UltraVNC or RealVNC boot up as a service, though I don't know why that helped.

I'm looking for answers to three specific questions, as well as any general advice:

  1. Should I be focussing on a Windows service or auto-login + bat file in the "Startup" folder?
  2. If I use a Windows service, is there anything special that I need to do to make sure desktop access and/or screenshots are available?
  3. Do you recommend any tools for common Linux commands, like curl or wget? Last time I used Windows I used Cygwin a lot, but is there something more appropriate to use here?
like image 582
Patrick Lightbody Avatar asked Jan 20 '23 15:01

Patrick Lightbody


1 Answers

I have not tried auto-login on Windows instances in EC2, but here's the support document on how to enable it.

We boot-strap our Windows instances using a custom AMI with a custom Windows 'install' service already installed. The boot-strap installer reads a URL from user-data at startup. The URL points to a ZIP file stored in S3. The installer then downloads, un-zips, and executes the actual application installer -- in our case a simple CMD fie.

This setups allows us to have one base AMI and then be able to easily overlay 15+ different application configurations (without having to rebuild the AMI). If you only have one application configuration this may be overkill for your situation.

The only trouble we ran into was having our installer service start to early -- changing the service startup mode to "Automatic Delayed" fixed that issue.

We wrote our boot-strap installer in Java, launched via YAJSW, because we're comfortable with it. If you just want a few simple Unix tools, most are available pre-compiled for Windows, for example wget.

For something completely different, you could try PsExec to configure the instance after it has booted.

like image 171
Uriah Carpenter Avatar answered Jan 31 '23 04:01

Uriah Carpenter