How to create a flexible bootable version of EC2 Windows 2008 script?

If you look at the Linux ecosystem (especially Ubuntu and Alestic EC2 images), a common technique where virtual machines are preconfigured to view EC2 user data and use it as a load script. The nice thing about this approach is that you can write a boot script file that additionally protects your computer, allowing you to avoid creating a new image every time your software running on the machine changes.

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

  • This should run on Windows Server 2008.
  • The bootloader script should start when the machine boots, reads the user data file, pulling out the contents of http://169.254.169.254/1.0/user-data
  • The boot script file should then run the contents of this file as if it were a script
  • The script embedded in user data must be run in such a way that it has access to the desktop environment (i.e.: it could launch a browser, etc.).

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

Part of the screenshots is interesting, because in the past, when I tried this, the only way to get something other than a black screen was to download UltraVNC or RealVNC as a service, although I don’t know why that helped.

I am looking for answers to three specific questions, as well as any general recommendations:

  • Should I focus on the Windows service or the auto-download + bat file in the Launch folder?
  • If I use the Windows service, is there anything special I need to do to provide access to the desktop and / or screenshots?
  • Do you recommend any tools for regular Linux commands like curl or wget? The last time I used Windows, I used Cygwin a lot, but is there something more suitable for use here?
+4
source share
5 answers

I have not tried autostart on Windows instances in EC2, but here is a support document on how to enable it.

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

These settings allow us to have one basic AMI, and then be able to easily overlay 15+ different application configurations (without the need to restore AMI). If you have only one application configuration, this may be redundant for your situation.

The only problem we encountered was that our installation service started earlier - changing the service’s startup mode to “Automatic deferred” fixed this problem.

We wrote our installer for loading in Java, launched through YAJSW , because it is convenient for us. If you just need some simple Unix tools, most of them can be precompiled for Windows, for example wget .

For something completely different, you can try PsExec to configure the instance after loading it.

+6
source

You can try using the free RightScale developer account to create simple Powershell scripts and link them to Windows instances to run at boot time. RightScale control panel solves exactly the problems that you are trying to solve above.

DISCLAIMER: I work for RightScale.

As for screen capture, CutyCapt is a simple tool that you can point to a URL and generate an image.

Unxutils is a great solution for anyone looking for Unix tools for Windows. It got wget.exe, which you are looking for, however using Powershell to upload files is also not so bad:

$wc = new-object system.net.webclient $wc.DownloadFile("http://stackoverflow.com","test.html") 
+1
source

If you can write a batch file to complete the configuration, then you can run it when you start vm by doing the following:

 1. Run REGEDT32.EXE. 2. Modify the following value within HKEY_CURRENT_USER: Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ParseAutoexec 1 = autoexec.bat is parsed 0 = autoexec.bat is not parsed 

As an answer to # 3, I would say that you can do anything in the batch file that you need, which includes downloading from the ftp server (but not from the http server). I am really interested in this, and if you have questions, try asking me.

+1
source

If you are using Elastic Beanstalks , you can use this:

Software Configuration for Windows EC2 Instances

It uses YAML formatting standards such as

 packages: msi: mysql: http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-6.6.5.msi/from/http://cdn.mysql.com/ 

or

 sources: "c:/myproject/myapp": http://s3.amazonaws.com/mybucket/myobject.zip 
+1
source

I know this is a bit late to help with the original post, but for those who are still reading this solution, you need to use http://cloudinitnet.codeplex.com/ . The service is easily installed using the powershell script and will create a local administrator account that will be used during operation.

The goal of this project was to replace the Cloud-Init project used by Amazon Linux and Ubuntu.

0
source

Source: https://habr.com/ru/post/1337675/


All Articles