Scott Hanselman

Is the Windows user ready for apt-get?

May 28, '13 Comments [88] Posted in NuGet | Open Source | Tools
Sponsored By
Chocolatey installs Git

What it does

Chocolatey lets you install Windows applications quickly from the command line via a central catalog of installation scripts. You could install Git, 7Zip or even Microsoft Office (given a key.) The idea is seamless and quiet installations using a well-known key.

For example, once installed you can do this from and command line:

  • cinst git
  • cinst 7zip
  • cinst ruby
  • cinst vlc

That's basically it.

The catalog has grown so complete, in fact, that I recently wanted to install DosBox so I could play Zork. I took and chance and just "cinst dosbox" and it worked. THAT is a the promise that Chocolatey makes.

Getting Started with Chocolatey

You can get started by first installing the Chocolatey package manager. Copy paste this line to your command line and run it. (More on the fearfulness of this first step in a moment).

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

Presumably you like to know what command line stuff is going to do to your computer before you do it, so parse this line out. It's going to launch PowerShell to do the hard work. Nearly every Windows machine has PowerShell these days, and it's PowerShell that makes Chocolatey work.

Some folks have custom profiles so the -NoProfile switch suppresses custom profiles to prevent conflicts during installation. It launches a chunk of PowerShell script that it downloads from https://chocolatey.org/install.ps1/ then executes. Note that it's setting execution policy to unrestricted to do this. To be clear, it's executing code downloaded over the web, so there is a non-zero risk there. It then adds Chocolatey to your path (for this one prompt) so you can use it immediately. It'll be added to future instances of prompts automatically.

Look at https://chocolatey.org/install.ps1 now. It's a very clean and easy to read script. It downloads the Chocolatey installation zip file (which is actually a NuGet package), unzips it and continues the installation by running a scripts in the tools section of the package.

How it works

Chocolatey is a bootstrapper that uses PowerShell scripts and the NuGet packaging format to install apps for you. NuGet is the package management system that Windows Developers use to bring libraries down at the project level. Chocolatey (get it? Chocolatey Nu-Get?) extends that concept to bring applications down at the system level.

Today if you want to get 7Zip, you usually google for it, find the site, figure out the latest version or right version for your system, download it, run it, next next next finish and maybe add it to your path. Chocolatey does that for you.

Again, NuGet is libraries installed locally for projects, Chocolatey is applications installed globally for your whole system.

Chocolatey uses PowerShell scripts (that you never have to think about) that package developers use to chain installations and build dependency trees. Take the internals of a Git installation script for example:

try {
Install-ChocolateyPackage 'git.install' 'exe' '/VERYSILENT' 'http://msysgit.googlecode.com/files/Git-1.8.1.2-preview20130201.exe'

#------- ADDITIONAL SETUP -------#
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
$programFiles = $env:programfiles
if ($is64bit) {$programFiles = ${env:ProgramFiles(x86)}}
$gitPath = Join-Path $programFiles 'Git\cmd'

Install-ChocolateyPath $gitPath 'user'

@"

Making GIT core.autocrlf false
"@ | Write-Host

#make GIT core.autocrlf false
& "$env:comspec" '/c git config --global core.autocrlf false'

Write-ChocolateySuccess 'git.install'
} catch {
Write-ChocolateyFailure 'git.install' $($_.Exception.Message)
throw
}

The most important part for you to take away here is the first line. Note that this Chocolatey script is downloading Git from the mSysGit Site. Chocolatey is not changing installers, making installers or hosting installers. It's automating the boring parts of getting software, but it's still getting that software from the same location as always.

Advanced Stuff

Once you learn the basics - and they're pretty basic - there's more depth to Chocolatey to explore. Beyond the cinst and cuninst there's other commands to make installing stuff on Windows easier. Remember, they're all in your PATH so you can call these commands anytime.

Each of these major sources can be called with cinst using the -source parameter like "cinst IISExpress - source WebPI" or using their own aliases for simplicity as shown below.

  • cwindowsfeatures - If you've ever opened Add/Remove programs then click Install Windows Features in order to setup IIS or Hyper-V then this command is for you. Some examples:
    • cwindowsfeatures  IIS-WebServerRole
    • cwindowsfeatures Microsoft-Hyper-V-All
    • cwindowsfeatures TelnetClient
      • Plus, you can always clist -source windowsfeatures for the complete list.
  • cwebpi - The Web Platform Installer is a great GUI for downloading any development tools you might need for Web Development on Windows. It's a catalog, an installer, and a chainer. There's also a command-line version of WebPI that Chocolatey integrates with so you can:
    • cwebpi IISExpress
    • cwebpi VWDOrVs11AzurePack_2_0
      • And again, clist -source webpi gets you a list of what you can do.

There's a more complete list at the Chocolatey Commands Reference including how it integrates with Cygwin, Gems and Python.

Security Issues

nugetlogoThis is a prickly one. How do you make a system that lets you install anything directly from the Internet quickly, cleanly, and easily without, well, installing something evil directly from the Internet? You'll want the communication with the server to be secure and the packages trusted, but you'll also want to make sure the packages haven't been tampered with since they were uploaded. There's the inevitable threat of a man-in-the-middle attack. You'll want to watch for malicious packages and enable quick takedowns if one sneaks by.

Security concerns aren't unique to Chocolatey, of course. They are a part of package repositories since their inception. The node npm repository had a security breach in March of 2012, and the folks at andyet explored the issues surrounding it, but also pointed out that personal responsibility has to have a role as well.

Linux's apt-get solves much of this with appropriate uses of cryptography and best practices that can (and should) be emulated. Packages in apt repos are signed with SecureApp, there are warnings if you're using a 3rd party repo or installing an unsigned package.

The Chocolatey team has been very quick to jump on security issues and they are very approachable. They've added SSL where appropriate and are aware of the work to come. If Chocolatey gets big (bandwidth and costs is a question in my mind) perhaps a non-profit organization would step in to help with not only costs, but also security audits and best practices.

Here's some points (edited for length by me) from a post from Chocolatey's lead, Rob in a post on their mailing list, also in march of 2012:

Security has a big future aspect of chocolatey. At the present I am the curator and I every day I get an email showing me all of the new packages that went in the day before. I look at all packages from new authors and I typically look at the first version of most new packages from authors I have good contacts with.

I've talked at length with others about having a moderated feed in the aspect of every package, every new version would be approved prior to showing up on the main feed. I am paying attention to how debian does things with multiple feeds and there are thoughts to move in that direction as well.

Security? In the future we are looking at a small group of folks be an approving body for nupkgs. We also talked about showing the hash for the nupkg, and possibly letting folks specify a hash for the installers so chocolatey can verify the things it downloads prior to execution.

Chocolatey's LIB folderCould I make a Chocolatey package called "FormatMyHardDrive?" Sure I could, just like I could ask you to open an admin prompt and format c: /q, but you won't, right? ;)

What's next?

Chocolatey is clearly not meant to be used by your "Gender Non-Specific Non-Technical Parent" and it does have some "competition" in the form of the Ninite GUI installation utility. While still not for the average Joe/Jane and having only a limited catalog, Ninite does fill a gap for the super-user to quickly get the common apps and utilities they want.

Additionally, is Chocolatey really apt-get? It's not installing libraries system-wide, although there's no reason it couldn't. Other open source projects like CoApp would like to be the Windows app-get although CoApp is more of a "system-wide libraries, C++ support, and Unix-like utilities" and Chocolatey is more of a "developer and poweruser utilities and their dependencies."

Chocolatey does install dependencies and you can see that happen yourself by trying out "cinst gitextensions" which itself has a dependency on git. Chocolatey will walk the graph and install what it needs before finally installing gitextensions.

Where Chocolatey, and ultimately Windows itself, falls down is with odd PATHing and install locations. Because Windows doesn't have formal install locations for things and because Chocolatey puts itself first in the PATH, it's possible to get one's self into odd situations where apps that were installed outside of Chocolatey don't line up with apps installed inside. For example, I installed Git with Chocolatey some months ago, then forgot about that version and installed a newer version of Git on my own. However, I kept hitting an old git bug because the Chocolatey version of Git was "first." I believe issues like this have changed with recent builds of Chocolatey, but the point remains: it's hard on Windows today to who installed what low-level utility, when, and where it ended up.

Branding

Now, by no means to I want to take away from the hard work done by Rob and the team, but (and I've said this to Rob before) I really have trouble getting past the name Chocolatey. Sure, there are two ways to spell "Chocolaty," which make it hard at least for me to type "Chocolatey" reliably. The -ey is a theoretically a valid variant spelling, but you can tell that that to the red squiggled underline in Word. But it's less the spelling and more the name itself. It lacks the nerdiness of an "npm," the gravitas of an "apt-get," or the poetic terseness of a "gem."  I realize that we are living in a world with companies called Hulu, Yahoo, Microsoft (seriously, MICRO SOFT, what is that?) and Google, but it's worth pointing out that a good name can really take a project to the next level. I'm not sure Chocolatey is the right name for this project, but that's 100% my opinion.

I encourage you, technical reader, to check out Chocolatey for yourself! It's a powerful tool, an engaged and growing community and an interesting piece of tech in its own right.

Is Chocolatey the apt-get Windows users have been waiting for? Sound off in the comments.


Sponsor: Big thanks to SoftFluent for sponsoring the feed this week! Check out their slick code generation tools: Less Plumbing, More Productivity! Generate rock-solid foundations for your .NET applications from Visual Studio and focus on what matters!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

JavaScript is Web Assembly Language and that's OK.

May 24, '13 Comments [48] Posted in Javascript
Sponsored By

Some years ago I said that JavaScript is the Assembly Language of the Web. In fact, lots of people said it, because it's true. Later, some folks disagreed, saying that this is an inaccurate analogy. Of course, it is inaccurate because it's an analogy. That said, as analogies go, it's pretty good. Sure, assemblers are architecture and processor specific. Maybe "JavaScript is the Web's Bytecode" is better. At the very least, JavaScript is a totally reasonable compile target.

Given that (using Wikipedia as a dictionary here and has a decent definition:

An assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong correspondence between the language and the architecture's machine code instructions.

It's initially not clear that JavaScript is a good assembly language as it's a high-level programming language that is itself interpreted, then JIT-ted, then turned into machine instructions. Phrased differently, JavaScript floats pretty high in the stack. Certainly every processor has its own assembler and they are very specific, but the browser's JavaScript VM is what runs the "new machine code." There's only one processor architecture. The Web. (again, analogy!)

JavaScript remains a popular transpilation/compilation target. From Google's GWT to Clojure to TypeScript to CoffeeScript, it all stops at JavaScript because JavaScript is the ubiquitous virtual machine that we already have installed on our machines.

Google Native Client (NaCl) is great and will likely have a role to play, but there's only one language that works everywhere without installation or trouble and that's JavaScript.

asm.js compilation & execution pipelineWe don't all have x86 machines. We don't have have machines that we could feed assembler or C. Certainly not in a portable way. JavaScript is the great portable equalizer.

There's languages that transform to JavaScript like TypeScript and CoffeeScript and HAXE and so many more, but many of these are arguably transformations, not compilations. They also tend to compile to lots of different kinds of JavaScript.

Enter asm.js. Why not take the sprawling language that is JavaScript and pick just the subset that one would want if one were to compile something to it? Why not take the assembly-esque parts of JavaScript and formalize it? Mozilla is doing this with the clear goal to compile things to JavaScript and make it perform well. Their FAQ says they're seeing slowdowns around a factor of two, which is amazing, in case you're wondering. It's also worth noting that I, as a user, don't care if you compile your C to JavaScript. I just want a great experience on the open web, and that's another reason that targeting JavaScript moves the web forward.

Working in tandem, there's emscripten, a LLVM bitcode to JavaScript compiler. We can take C/C++ and compile it to JavaScript. Don't buy it? They ported Unreal Engine 3 in 4 days with asm.js as the target.

You can argue that JavaScript isn't the x86 or Assembly of the web. You can argue all you want. It's still happening.

As our great philosopher Kosh from Babylon 5 once said: "The avalanche has already started. It is too late for the pebbles to vote."

The avalanche has already started. It is too late for the pebbles to vote.

It's not clear that JavaScript is the end state. In fact, if anything it's clear there is no end state. But along the way we will - actually are - passing though the JavaScript as Assembler part of the trip.


Sponsor: Big thanks to SoftFluent for sponsoring the feed this week! Less Plumbing, More Productivity! Generate rock-solid foundations for your .NET applications from Visual Studio and focus on what matters!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Reviews of Super Weird Mice:The Microsoft Arc Touch and Wedge Mouse

May 24, '13 Comments [38] Posted in Reviews
Sponsored By

I'm always on the lookout for the perfect mouse. I don't think it exists, yet, frankly, but we're getting close. I've got two notebook mice I'm bouncing between while using my new ultrabook, the Lenovo X1 Carbon Touch. I'm using the Microsoft Arc Touch Mouse and the Microsoft Wedge Mouse.

I'm classifying both of these mice as "weird" because, well, they are. They aren't classic-looking mice and each one has garnered the occasional double-take from passersby. Each has an unusual design for a reason: portability.

The Wedge Mouse

That's a tiny-ass mouse

The Wedge is tiny. Like, really tiny. The idea appears to have been to remove the back half of the mouse completely (the part that usually gets cupped in your palm) and instead make just the fingertips part. There's a AA battery that goes in the round part (the butt) and underneath there's a single button for on/off/Bluetooth sync and a battery door switch. Oddly, the battery door switch looks like an on/off switch also so I ended up flicking that a few times before I learned.

The Wedge is a Bluetooth mouse, and getting a good Bluetooth mouse was my goal. This Ultrabook only has two USB ports and that's one port too few. I'll often find myself with a hard drive plugged in, then want to add one more item (USB key, presenter remote, smart card) and with most mice I'm stuck because the other USB port already has that mouse's transmitter.

The mouse uses the capacitive touch technology that we're seeing in a lot of mice lately. See that vertical line that separates the two mouse "buttons?" Stroke that and it's the "scroll wheel." It feels odd initially but ends up quite comfortable. Speed of scrolling is also easily changed. There's no middle mouse button, but that hasn't been an issue for me.

Shown actual size. Tiny.

My Right-Clicking Issues

Now here's an odd one. Every once in a while I do what, in my mind is a CRYSTAL clear right-click and it registers as a left-click. I've tested it. Click hard with the right and it got picked up as a left. What the heck? I searched around and found a few people in the forums with the same issue so I assumed it was a driver issue. However, I have the latest drivers. What's going on?

Well, it's actually obvious and a little funny if you give it some though. Occasionally when I right click I end up right-clicking the FAR TOP EDGE on the right. Looking at the picture below, I'm pushing with my finger ABOVE the right-side blue square. This is outside the touch area but is registered with the mouse's mechanical click. Since there's no right-touch, there's no right-click.

Stated differently, there's a touch area with clear left and right areas delimited. If I mechanical click the mouse - remember, there's just one click...the whole mouse goes down - then the mouse decides if it's a left or right by seeing where your finger is that moment. If it's on the far top edge then it can't see your right finger, so....left click from the right.

Don't click the top top top edge.

Call it an oddity, call it a design flaw, call it "you're holding it wrong." Regardless, as soon as I figured this out, it stopped happening. I just assumed initially that the touch area wrapped around the front of the mouse. It doesn't. Once my subconscious heard about this from my conscious mind, I can right-click like a champ, but it was quite confusing for a minute there. Be aware.

Bluetooth Disconnecting

I thought that Bluetooth aspect of this mouse would be pure win, but even after using it for a few hours it stopped responding at least a half dozen times. I would have to lift the mouse up and put it down again. The word on the street and in the forums is that this a power management issue and that you should go into Device Manager and check the properties of the mouse and change the setting that allows the operating system to, well, turn it off. Of course, this setting is not checked and not available.  The takeaway here as far as I'm concerned is that while the dream of a Bluetooth mouse is a great and valid one, it's just not ready. Whether is it's the tech or the stack or the mouse itself, I dunno. I tried an Apple Magic Mouse for a day this week and had the same issue, but worse. The Magic Mouse wouldn't go 10 minutes without just stopping - and this was with new batteries. The Wedge has turned off maybe twice a day, so enough to be annoying but not enough to kill the deal. That said, there's lots of anecdotes from folks who LOVE this mouse and haven't had this issue, so I'm assuming it's my Bluetooth driver stack.

All in all, I haven't decided if I'm going to keep this mouse. It's small, which is great. It's Bluetooth which is super great until it's totally not-great. I will give it a 7 out of 10. It's small. So, um. Ya

The Arc Touch Mouse

I love this mouse. It's darn near perfect. The only mouse I love even more is the original Microsoft Arc Mouse which is equally brilliant in different ways.

Nice stock photo of the Arc Touch Mouse

The gimmick of the Arc Touch Mouse is that it folds flat. This isn't a cute gimmick, it actually works and works well. Given that my Lenovo is so small and flat, it's nice to have this mouse slide into my backpack and lay flat against the laptop. They kind of match, too.

The ArcTouch Mouse folks super flat

It arcs with a reliable and satisfying snap. The back is rubber and the top is glossy plastic.

The ArcTouch Mouse arches nicely

The scroll area has a wonderful haptic feedback (that's geek for "it vibrates when you scroll with it") that is adjustable with drivers. This attempts to simulate the "scroll-wheel nubbins" that regular mice have. It's a great little feature and I appreciate it. It gives you a sense of "it's working" without having to look at the mouse.

 

The ArcTouch Mouse matches my Lenovo

The ArcTouch Mouse and the Wedge next to my hand

The Arc Touch Mouse is also a very comfortable size even for my giant lobster hands. It is tiny and portable, but it supports and cups the inside of your palm in a stable and reliable way.

The only thing this mouse needs is optional BlueTooth. Instead the Arc Touch Mouse uses a nano-transceiver which I just keep plugged in all the time. When it's not plugged in, it attaches rather sturdily to the base of the mouse with a magnet. It just snaps into place and stays there. Very cool.

While it's not Bluetooth, it's absolutely reliable. I haven't had any communication issues with the transceiver and it never loses connection with the mouse.

For now, the Microsoft Arc Touch Mouse is my travel mouse of choice and I get give it a 9.5 out of 10.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

How to setup a Load Balanced Web Farm of Virtual Machines (Linux or otherwise) on Windows Azure (command line)

May 21, '13 Comments [19] Posted in Azure
Sponsored By

A buddy of mine was thinking to move some of his Linux-based website to Azure. If you're running a Web Site that this node.js, ASP, ASP.NET, or PHP, it's easiest to use Azure Web Sites. I showed how to do setup Azure Web Sites in minutes with Git in this post. They hide the underlying OS from you, are automatically updated, scale easily, and share disks.

However, he likes VMs and the control they give him, plus he can run whatever he wants, move things around and generally control his world.

I'll be using the open source (GitHub) cross platform CLI tools (command line interface) for Azure. If you have node package manager you can "npm install azure-cli --global" then import your subscription. You can also get the command line tools by downloading and installing from www.windowsazure.com.

Setting up a Linux VM

We'll create a the initial VM using the Portal (I'll show you how to do it from the command line in a minute). This virtual machine will be for setting up a template VM image. I'm going to create an Ubuntu 13.04 server, then add Apache and PHP. Then I'll capture a generic image of my now-set-up machine and use it to create copies that I'll add to a farm. This image will show up later in "My Images" in the Azure Portal.

NOTE: There's an amazing community-driven category of prepped and ready Virtual Machine images at the Open Tech VM Depot. It's like the Azure's best kept secret. I'll do a post on it later but it's really deep and broad and worth checking out.

From within the Azure Portal I'll go New | Virtual Machine | and select Ubuntu Server 13.04.

Selecting Ubuntu from the Azure Gallery

The name doesn't matter, but I'll setup a user name and password (or use a SSH key):

Creating a VM

Note I'll create a stand-alone Virtual Machine:

Making a Stand-Alone VM

TIP: If I didn't want to use the Portal at all to make this VM, I could even find a VM image programmatically, then create a VM instance, all from the command line. Using "azure vm list" would get me the list of VMs to choose from. The Ubuntu one I wanted is "Ubuntu-13_04-amd64-server-20130501-en-us-30GB" (with a guid in the name as well) so I'd just "azure vm create MyDNSName ImageName [options]" and then proceed from there.

Once this Linux VM has started up, I'll SSH into it. You can see that Azure has mapped a random high number public port to the VM's internal SSH port 22.

My VM's IP Address

I SSH in. I'm gonna add Apache, PHP, restart apache, then add a test.php that will show PHP is working as well as output the current IP address so I can tell which machine served the request.

sudo apt-get install apache2
sudo apt-get install libapache2-mod-php5 php5

I'll add a test.php

sudo nano /var/www/test.php

and put in

<?php echo gethostbyname(trim(`hostname`)); ?>
<?php phpinfo(); ?>

Then I'll exit SSH. VMs are locked down by default, so to test this I need to add an endpoint. I can do that via the Portal but I'd like to see what I can do from the Azure command line.

Run vm endpoint create to map external 80 to internal 80.

azure vm endpoint create mylinuxtemplate 80 80

At this point I should be able to hit mylinuxtemplate.cloudapp.net:80/test.php and see it work.

My VM's test.php page

Cool. So I've got my Linux VM template the way I want it. Now I want to "capture it" as an image so I can stamp out more of them. This "waagent" on Linux is like "sysprep" on Windows.

From within a SSH session, run waagent -deprovision.

~$ sudo waagent -deprovision
scott@mylinuxtemplate:~$ sudo waagent -deprovision
WARNING! The waagent service will be stopped.
WARNING! All SSH host key pairs will be deleted.
WARNING! Nameserver configuration in /etc/resolvconf/resolv.conf.d/{tail,originial} will be deleted.
WARNING! Cached DHCP leases will be deleted.
WARNING! root password will be disabled. You will not be able to login as root.
Do you want to proceed (y/n)? y

WINDOWS PEOPLE: If you're a Windows person, you can setup your Windows VM just as you like it, then run %windir%\system32\sysprep.exe on it, capture an image of the VM and do everything described in this post as well!

I could shut it down and capture an image from the Portal, but again, it's command line fun today. Note that shutting down can take a little while.

azure vm shutdown mylinuxtemplate
azure vm capture mylinuxtemplate hanselmanlinuxwebfarmimage --delete

The capture command will DELETE the Virtual Machine. Remember that it was just a template. However, how I have a reusable image! I can see the images available to me, both user images and gallery images with "azure vm list."

NOTE: When you delete Virtual Machines, you're just deleting the "configuration" of the VM. You're not deleting the disk that was associated with it, as it's possible you might want to start that VM up again. If you're really trying to remove things, make sure you delete the instance of the VM and then delete the disk, too.

Creating a Linux VM Farm from the command line

Now I have an image sitting in my storage account that I can use to make "n" VMs from. I'll make one VM to start. I can watch it startup with "azure site list" after making it. When it's ready, I can make more! Make sure you use the --ssh switch or you will NOT be able to SSH into the machine!

C:\> azure vm create hanselmanlinuxfarm hanselmanlinuxwebfarmimage scott MyPassword123 --location "West US" --ssh
info: Executing command vm create
+ Looking up image
+ Looking up cloud service
+ Creating cloud service
+ Creating VM
info: vm create command OK
C:\> azure vm list
info: Executing command vm list
+ Fetching VMs
data: DNS Name VM Name Status
data: ------------------------------- ------------------ ----------
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm CreatingVM
info: vm list command OK
C:\> azure vm list
info: Executing command vm list
+ Fetching VMs
data: DNS Name VM Name Status
data: ------------------------------- ------------------ ---------
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm ReadyRole
info: vm list command OK

WEIRD: Azure has a concept called a "Cloud Service" which is a lousy name, IMHO. For us, let's consider it a "container" for our VMs. It's a logical container that will hold and associate all our VMs (and other cloudy stuff) together. When you have one VM you have one cloud service associated with it, but you can't see it in the Portal but because it doesn't really provide value...yet. When you have TWO VMs in the same container, then you'll see that cloud service "container" appear in the Portal.

I've made a hanselmanlinuxfarm VM now so there's a hanselmanlinuxfarm cloud service 'container.' Now, I'm going to make a few more VMs but I'll connect them to the first VM. There's two ways to do this. First, the --connect option from the command line. Note that you don't have control over the name of your VM this way, if you care. If you have hundreds, you likely don't.

The command will find the existing cloud service (again, 'container') then make a new VM. I'm going to run this command twice so I'll have three VMs total.

SO IMPORTANT: It's the --connect used on this second call that is the key. It makes the second (and then n+1) VM and adds it to the same cloud service "container." It seems the VMs associated with each other. The name of the next VM will be whatever-2, then -3, etc but they will also use the same external name, like hanselmanlinuxfarm.cloudapp.net.

I'll do this twice, each time using a different high SSH port number that will map to 22 internally. If I don't want SSH expose externally, I can delete the public endpoint later.

C:\> azure vm create --connect hanselmanlinuxfarm hanselmanlinuxwebfarmimage scott MyPassword --ssh 12345
info: Executing command vm create
+ Looking up image
+ Looking up cloud service
+ Getting cloud service properties
+ Looking up deployment
+ Creating VM
info: vm create command OK

When creating a Linux VM you MUST add a --ssh flag to the command line or you'll not be able to SSH into the box. Make sure to add a high port number so you'll get a mapping from that port to 22, so maybe 12346 -> 22, etc. If you make these VMs from the Portal, it will pick a random port for you. When you do it from the command line, you need to choose.

At this point, azure vm list says I have three. Two are ready and the last is being created now. You can tell these VMs are running in the same Cloud Service "container" because the DNS name is the same. These VMs are officially a "farm."

C:\> azure vm list
info: Executing command vm list
+ Fetching VMs
data: DNS Name VM Name Status
data: ------------------------------- -------------------- ----------
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm ReadyRole
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm-2 ReadyRole
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm-3 CreatingVM
info: vm list command OK

OK, now here's making a fourth VM from the Portal, just as an FYI.

Creating a Linux VM and adding to the Farm from the Portal

Just so you know, you can add VMs to your farm from the Portal also.

Now I can reuse this VM image

Give your new VM a name, then "connect it to an existing virtual machine." I don't like this phrasing, and I'm curious what you think. Basically it's "add this VM to this collection of VMs." It doesn't matter which one you select from this dropdown, as long as you pick one that's in the Cloud Service "container".

Connecting to an existing VM within a Farm

I won't click OK, but if I did, at this point I've would've a fourth VM, this one via the Portal.

Load Balancing my Linux VM Farm

I have three identical VMs running Apache and PHP and my test.php page.

C:\> azure vm list
info: Executing command vm list
+ Fetching VMs
data: DNS Name VM Name Status
data: ------------------------------- -------------------- ---------
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm ReadyRole
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm-2 ReadyRole
data: hanselmanlinuxfarm.cloudapp.net hanselmanlinuxfarm-3 ReadyRole

info: vm list command OK

Let me open up port 80 on all three.  Since I want them load balanced I can't do this, as this is how you map single non-load-balanced ports.

azure vm endpoint create hanselmanlinuxfarm   80 80
azure vm endpoint create hanselmanlinuxfarm-2 80 80
azure vm endpoint create hanselmanlinuxfarm-3 80 80

For load balanced ports I need to use "create-multiple." Not only may I want to open multiple ports all at once, but also since I want load-balancing, I also may want a probe set up. For example, since I'm using HTTP, if there's a result other than 200 returned from test.php then I'll want that VM pulled out of the farm. It will also pull the VM out of rotation if it doesn't hear back in 30 seconds.

Here I'm creating those 80 to 80 maps, but also watching test.php for anything other than an HTTP 200.

azure vm endpoint create-multiple hanselmanlinuxfarm   80:80:HttpTrafficIn:http:80:/test.php
azure vm endpoint create-multiple hanselmanlinuxfarm-2 80:80:HttpTrafficIn:http:80:/test.php
azure vm endpoint create-multiple hanselmanlinuxfarm-3 80:80:HttpTrafficIn:http:80:/test.php

In this case "HttpTrafficIn" is what I am calling the Load Balancing Set Name.

NOTE: I'm doing a pull request now to add the ability to see the ProbePath from the endpoint command but for now you can see it with "azure vm show" like this:

C:\>azure vm show hanselmanlinuxfarm
info: Executing command vm show
+ Fetching VM
data: DNSName "hanselmanlinuxfarm.cloudapp.net"
data: VMName "hanselmanlinuxfarm"
data: IPAddress "100.68.xx.xx"
data: InstanceStatus "RoleStateUnknown"
data: InstanceSize "Small"
data: InstanceStateDetails ""
data: OSVersion ""
data: Image "hanselmanlinuxwebfarmimage"
data: DataDisks ""
data: Network Endpoints 0 LoadBalancedEndpointSetName "HttpTrafficIn"
data: Network Endpoints 0 LocalPort "80"
data: Network Endpoints 0 Name "endpname-80-80"
data: Network Endpoints 0 Port "80"
data: Network Endpoints 0 LoadBalancerProbe Path "/test.php"
data: Network Endpoints 0 LoadBalancerProbe Port "80"
data: Network Endpoints 0 LoadBalancerProbe Protocol "http"
data: Network Endpoints 0 Protocol "tcp"
data: Network Endpoints 0 Vip "137.135.xx.xx"
info: vm show command OK

Cool, so now let's see if I have a load-balanced farm.

PERF NOTE: In order to get the best performance from your Azure VMs (or any cloud VM) considering putting things like MySQL/PostgreS databases on a separate disk with different caching semantics. You want the OS disk and the Data Disks to be separate. For example. I have a Windows VM running MySQL. The OS is on a standard 30 gig disk, but the MySQL Database is alone on a 5 gig disk that's attached. It keeps things separate and tidy, plus it performs better

Checking on my new Farm

If I log into the Portal, I can look at each individual VM or I can look at the farm as if it's one 'cloud service.' Get it?

My Linux Farm working as a team

All three VMs are "running"

Making my Farm more reliable

I want to make sure my new VMs are all on different racks in the Azure Data Center. I know they are in "West US" because I put them there, but I'm not sure if they are together on the same rack or near each other or what.  Since a rack is within a "fault domain" meaning that a Rack could, I dunno, spontaneously explode, then I want to tell Azure that all these VMs are part of an "availability set." This is a name I apply to the VMs that says "make these more available by keeping them apart."

From the Portal I'm going to pick the first VM and select Configure, then Create an Availability Set. I'll name it "hanselmanlinux" but it can be anything.

I'm making an availability set

Adding an Availability Set can involve Azure moving my VM somewhere else within the Data Center and it may need to restart it if it does. Sometimes this is fast, other times it takes a minute or 10 as it's a big deal initially, so be aware. Once everyone's in the set, it's less of a big deal.

When it's done, head over to the other VMs and add them one at a time to the same availability set. The result looks like this in the Portal, and now I'm assured that my three VMs are all in different Fault Domains (and racks).

All my VMs are in one Availability Set now

Hitting my Web Farm

Now I can hit hanselmanlinuxfarm.cloudapp.net/test.php and see the IP changing (as well as the CPU% changing in my portal!) or even watch HTOP over SSH and get a live view. Hey, I've got a little Linux farm!

My tiny farm has three machines

Here's my SSH'ed into one of them, looking at htop (it's better than top!)

SSH'ed into a Linux machine on Azure looking at CPU time with HTOP

My Complete Script, Summarized

Here's my complete script. I used azure vm image list | find /I "13_04" to find an Ubuntu image. I could have done this with bash as well.

C:\>azure vm image list | find /i "13_04"
data: b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_04-amd64-server-20130423-en-us-30GB
data: b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_04-amd64-server-20130501-en-us-30GB
data: b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-raring-13_04-amd64-server-20130511-en-us-30GB
data: b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-raring-13_04-amd64-server-20130515-en-us-30GB
data: b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-raring-13_04-amd64-server-20130517-en-us-30GB
data: b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-raring-13_04-amd64-server-20130518-en-us-30GB
data: b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-raring-13_04-amd64-server-20130521-en-us-30GB

Once I've found an image, I create my first VM from the command line in a location of my choice. Again, it's Linux, don't forget the -ssh.

azure vm create mylinuxtemplate b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_04-amd64-server-20130501-en-us-30GB scott MyPassword --location "West US" --ssh

Get it how you like it. SSH in, set it up, run the waagent to prep it. Shut it down and capture it.

azure vm shutdown mylinuxtemplate
azure vm capture mylinuxtemplate mylinuxfarmimage --delete

Finally, here's a basic batch file to make 5 VMs. Note the first command is different from the Nth. Of course, with bash you could make a script like "spinup 5" and automate to your heart's content. The HTTP probe is optional on the endpoint creation.

azure vm create hanselmanlinuxfarm hanselmanlinuxwebfarmimage scott password --location "West US" --ssh
azure vm create --connect hanselmanlinuxfarm hanselmanlinuxwebfarmimage scott password --ssh 12345
azure vm create --connect hanselmanlinuxfarm hanselmanlinuxwebfarmimage scott password --ssh 12346
azure vm create --connect hanselmanlinuxfarm hanselmanlinuxwebfarmimage scott password --ssh 12347
azure vm create --connect hanselmanlinuxfarm hanselmanlinuxwebfarmimage scott password --ssh 12348
azure vm endpoint create-multiple hanselmanlinuxfarm 80:80:HttpTrafficInLhttp:80:/test.php
azure vm endpoint create-multiple hanselmanlinuxfarm-2 80:80:HttpTrafficInLhttp:80:/test.php
azure vm endpoint create-multiple hanselmanlinuxfarm-3 80:80:HttpTrafficInLhttp:80:/test.php
azure vm endpoint create-multiple hanselmanlinuxfarm-4 80:80:HttpTrafficInLhttp:80:/test.php
azure vm endpoint create-multiple hanselmanlinuxfarm-5 80:80:HttpTrafficInLhttp:80:/test.php

After it ran, I went in to the Portal and set up Availability Sets manually. That's only available in PowerShell today, but setting availability sets is coming soon to the cross-platform tools!

Next time, maybe I'll try"azure vm scale" to move these tiny VMs into 8 processor 56 gig monsters.


Sponsor: Big thanks to SoftFluent for sponsoring the feed this week! Less Plumbing, More Productivity! Generate rock-solid foundations for your .NET applications from Visual Studio and focus on what matters!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Xamarin Evolve 2013 Talk Video - How C# Saved My Marriage

May 15, '13 Comments [24] Posted in Musings
Sponsored By

My Talk at Xamarin Evolve

In case you haven't heard, Xamarin is a fabulous company with amazing products and their Evolve 2013 conference was absolutely smashing.

The Visual Studio Solution Explorer now has Android, iOS, and Windows all in the same place!I was fortunate enough to speak at Xamarin Evolve 2013 in Austin last month, just after lunch one day. I wanted everyone to understand how excited I am about what they're doing, how Azure and Visual Studio appreciates them and how great it is to be a C# developer right now. So, I did a fun little talk called "How C# Saved my Marriage, Enhanced my Career and Made Me an Inch Taller."

The general story of my talk is that, like VISA, C# is everywhere I want to be. I can create apps now on iOS (iPad, iPhone), Android (Phones and Tablets), Mac desktop apps, Windows Phone, Windows (all flavors), and Windows 8 Store apps. You can use Xamarin Studio, of course, but even better, Xamarin integrates with Visual Studio wonderfully. You can literally write iPhone apps in C# from within Visual Studio and compile them using a networked Mac as a build server. It's amazing.

I teamed up with Greg Shackles and we ported the Pan Tilt Zoom client (I already have Web and Windows Desktop versions) to iOS and Android!

Then Dominique Louis from MonoGame helped me port Daniel Plaisted's "Disentanglement" application to Android and iOS. Now it runs on Windows 8, iOs and Android.

disentanglement

We announced better NuGet support for Mono, took a SignalR pull request for iOS support and more. It was great fun.

Here's a screenshot I took in the middle of the talk. I used Lync and the Xamarin-powered iPhone version of our Pan-Tilt-Zoom app using SignalR to call back to the Seattle Office. Then I turned the camera around so I could see myself watching myself watching me watching the keynote.

Lyncing back to the SignalR team

It's a great time to be developing with C# and .NET. I hope you also join me at the MonkeySpace conference (formerly Monospace) in Chicago in July. I'll be presenting, teaming up with a friend who is launching an amazing soon-to-not-be-so-secret .NET related product that will take C# to even more places!


Big thanks to our Sponsor this week. It's Redgate! Check out Deployment Manager – app deployment without the stress. Deploy .NET code & SQL Server databases in one simple process from a web-based UI. Works with local, remote and cloud servers. Try it free.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.