wmi2php

I’ve been playing with my NLB cluster and want to use WMI to control the nodes. The PHP COM library works great, and I’ve had some success. The properties of COM objects aren’t exposed to you, so if  you print_r($somevar), you get nothing. I’ve been using ScriptomaticV2 and the NLB WMI documentation to muddle through it, and I found I was doing a lot of copying and pasting. Well no more! I worked through the major methods in Scriptomatic and re-implemented them in PHP. Now I can export PHP class files for any WMI class.

Check it out in GitHub.

It should be noted that I’m not a huge fan of “getters and setters”, so this uses overrides and an array of valid properties. I’m planning to expand it to create more “native” classes.

So now I can:

wmi2php.php generate --namespace=root/CIMV2 --class=Win32_ComputerSystem

Enjoy.

Advertisements

Windows 2012 classic theme

Do you like the cyan color theme in Windows Server 2012? No you don’t, it’s hideous.

win2k12-default

Microsoft removed the ability to customize the color scheme, so you’re stuck with that awful look right? Wrong! The good news is you can export the Windows Classic theme from Windows 7.

  1. On your Windows 7 machine, right click the desktop and pick personalize.
  2. Under Basic and HIgh Contrast Themes, activate Windows Classic
  3. Now scroll back up to My Themes
  4. Right click on your current theme and pick “Save theme for sharing”
  5. Save it as classic.themepack (or whatever you want)
  6. On a Windows 2012 machine, double click the file. It will automatically be imported and set as your current theme. No more awful cyan!

win2k12-classic

 

Now if anyone knows how to get rid of the ridiculous 8 pixel wide border, please let me know!

Windows Server 2012 – Network Load Balancing

I’ve been wanting to play with a load balanced IIS cluster for a while. Microsoft Network Load Balancing is included as a component of Windows Server 2012. NLB uses a hearbeat to check if nodes are still online, but it is not application aware. My environment is as follows:

  • A domain controller hosting the contoso.local domain
  • A database server running SQL 2012
  • A load balancing cluster host
  • Two web servers, WEB1 and WEB2

Setting up NLB

Nodes in an NLB cluster should be dual-honed, with 1 NIC for management and the other for NLB. The NLB NIC will take on the MAC of the cluster IP, so you’ll lose control over that interface. I disabled Client for Microsoft Networks on that interface as well. You can also use the registry and turn off automatic DNS registration for that interface. All nodes need to have the NLB feature installed, which is done through server manager.

When the nodes are setup, configure the cluster host:

  1. Install the NLB feature and open the NLB manager (nlbmgr.exe)
  2. Right click on Network Load Balancing Clusters and pick New Cluster
  3. Enter the management IP for the first node in the cluster. Click Connect
  4. NLB manager will connect to that node and bring up a list of interfaces. Select the interface to be used for NLB binding
  5. Click next past host parameters
  6. Set a cluster IP address
  7. Click next past cluster parameters
  8. Setup port rules for HTTP (80) and HTTPS (443)
  9. Finish

If you’re using VirtualBox there are a few possible gotchas:

  • You need to enable promiscuous mode for the NICs in the VBox config
  • NLB had to be set for Multicast, which doesn’t make sense, but it worked

Thanks to Bearrito on pastebin for this help.

Some links about NLB and unicast

5 FireFox extensions I can’t live without

Waiting forever for some drives to sync, I decided to compile my own list. I’m going to exclude the obvious items like ABP and FireBug. There are so many of these that you could have a top 5 list of top 5 lists, but this is mine anyway.

Prefbar

Prefbar puts common firefox toggles like JavaScript and Flash above the tab strip. Also has a very useful “Kill Flash” button. It’s also highly flexible. One of the add-ons for this add-on is “Clear domain cookies“, which makes testing and coding a login system far less painful.

Close tabs to the right

Close Tabs to the Right does exactly what it sounds like. Once you start using it you realize it should have been default behavior.,

Copy Link Text

Copy Link Text is another one that does exactly what it sounds like.

Tab Mix Plus

I use Tab Mix Plus to make tabs smaller, and to wrap the tab strip to a second line instead of scrolling. My style of research is to middle click a ton of links and then rummage through the results, so this extension is a must.

Export Cookies

Export Cookies makes it easy to save cookies in the old Netscape format. As an added bonous, they’re also compatible with cURL.

Quick Frame

I got home and realzied I forgot about Quick Frame.

So that’s my list. Ironically some of these items were in early releases of Firefox, and have slowly gone away. I also use Status-4-Evar but can live without it. What is nice to see is that while the Firefox team battles Google in the race to the bottom for stunningly useless browser user interfaces, the community comes behind to pick up the pieces and keep Firefox a usable piece of software.

Wikipedia block plus!

If you’re not using ABP you should be. As an added bonous, I’m including my Wikipedia ABP filters. I’m support WP, and have even been a regular contributor, but their banners are hideous and intrusive, and the floating divs of feedback are irritating to the extreme. I use these custom filters to keep out personal appeals from Jimmy Wales

http://en.wikipedia.org/w/index.php?title=Special:BannerController*
bits.wikimedia.org*modules=jquery.ui.button*
bits.wikimedia.org*modules=ext.articleFeedbackv5*
bits.wikimedia.org*modules=jquery.ui.dialog*
geoiplookup.wikimedia.org
##div#mw-articlefeedbackv5
##div#articleFeedbackv5-bottomrighttab
*.wikipedia.org/*BannerListLoader*

Running procdump in the background

Or how I got procdump to stay running when I log off.

Microsoft has a tool called procdump which will watch a process and write a dump file when certain conditions are met. The tool is thoroughly configurable, with details and examples at the Sysinternals page for the tool.

The one feature it is missing is the ability to run in the background. This is a problem, if you get kicked off a server, the process will exit and you will not get the dump of the elusive process. The solution is another Sysinternals tool: psexec.

I have a funny relationship with psexec. In most cases I feel it is absolutely the wrong tool for the job. Most Windows tools let you run a command against a remote machine, as long as you have credentials which will allow it. In this case though, it’s the ability to specify a console session and detach that I needed. The command is:

psexec -u USERNAME -p PASSWORD -i 0 -d c:\dump\procdump.exe -ma -c 80 wspsrv.exe

I’m telling psexec to run in session 0, which on Windows Server 2008 is reserved for services. Now I can log off the server and have my process keep running. The -d parameter tells psexec to detach (or not wait for the process to finish). A quick explanation of my procdump parameters, I’m going to write a full dump if the CPU usage of wspsrv.exe passes 80%.

ProcDump from psexec

Using psexec to run prodump in session 0

When PXExec completes, you see procdump running as part of services.

When PXExec completes, you see procdump running as part of services.

Session 0 is an interesting thing. In server 2003 session 0 is the console session, so anyone who logs on the “physical” machine will be in that console. With server 2008 and up, the console session is session 1, and session 0 is reserved for services. This reduces the likelihood that someone will kill the process you needed to keep running.

Remote desktop sessions. Notice services runs in ID 0.

Remote desktop sessions. Notice services runs in ID 0.

WISP – PHP on Windows 2012 / IIS 8 / SQL 2012

While a LAMP is an easy and effective solution for most cases, it doesn’t always make sense in large enterprise. An organization with a large active directory domain, hundreds of servers, and the full suite of Microsoft products is going to be more comfortable with a Windows server than a one-off Linux machine. This doesn’t mean Windows shops must be .Net shops. In this post, I’ll cover how to install IIS, SQL Server and PHP 5.4.

Installing IIS

IIS is a role in Windows Server 2012.

  1. Open Server Manager
  2. Click Add Roles and Features
  3. Click Next until you get to the Role Selection pane
  4. Check off Web Server (IIS)
  5. Click Next until the wizard finishes.

Installing SQL

Before installing SQL Server you should install .Net 3.5. It’s a feature and is added through server manager. The thing is, the installation source isn’t included in Windows. Apparently it’s a new feature called Features on Demand. When you add the feature, Windows will ask “Do you need to specify an alternate source path”. Pick the option for a source path and use D:\sources\sxs (or whatever your Win2k12 ISO is attached to). It’ll work from there. Do this before installing SQL or SQL will fail.

I installed SQL Server 2012 Express edition. The features are all the same, with the exception of database size and replication. It’s a pretty standard Microsoft Wizard installation, with a few points to watch:

  • When asked to create an instance, accept the default “SQLEXPRESS”. Don’t switch to “Default Instance”. The PHP MSSQL driver fully supports named instances.
  • Select mixed mode authentication (Database and Windows Integrated).

AdventureWorks2012 Database

The AdventureWorks2012 database is the sample data which is is available for SQL Server 2012. If you’re looking for Northwind Traders, it seems they folded during the financial collapse of 2006.

The database file is downloaded from here: http://msftdbprodsamples.codeplex.com/releases/view/55330

  1. Extract the file and save it to C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\
  2. run sqlcmd -E -S localhost\SQLEXPRESS
  3. Execute the below commands to attach the DB
create database AdventureWorks2012 on (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\AdventureWorks2012_Data.mdf') FOR ATTACH_REBUILD_LOG;
GO;

Installing PHP

And finally the good stuff! PHP is installed with the Web Platform Installer. It’s a one-click install and has taken all of the hassle out of setting up PHP.

  1. Download and run the Web Platform Installer
  2. Search for PHP in the search box
  3. Click Add next to PHP 5.4 and Microsoft Drivers 3.0 for PHP 5.4 for SQL and IIS.
  4. Click Install

The WPI will resolve any dependencies and install PHP. When it’s done, that’s it! Save the below as phpinfo.php in C:\inetpub\wwwroot and try it from your browser.

<?php
phpinfo();

Building a custom Debian LiveCD

These are the steps I used to build a Debian 7 LiveCD on a Debian 7 host system. They’re based heavily on the instructions posted by Will Haley in this post.

For more details about customizing the environment, read about:

  • Syslinux – this is the suite of tools that lets you boot Linux from just about anything
  • Genisoimage – this is the ISO image creation tool, with parameters to make it bootable
  • Readyroot – a chroot management script I posted and use to manage these environments

The first think to do is setup a chroot environment. I have a generic post on the subject here. If you are following along, I’m making the following assumptions:

  • You have created /usr/src/readyroot
  • Your image is located in /usr/src/mycd_live_boot/chroot
  • Your current working directory is /usr/src/mycd_live_boot

Some other files, like the initramfs also go under mycd_live_boot, that’s why it’s in a chroot subdir.

Setup the host system

First you need to add some packages to your host system

apt-get install syslinux squashfs-tools genisoimage rsync

Customize your LiveCD

Enter the live environment

/usr/src/readyroot chroot open

Now you need to install live-boot

apt-get install live-boot

Now that’s technically all your need, but it leaves you with a fairly useless system. To add some of the packages you’ve come to expect, run:

apt-get install network-manager net-tools openssh-client ftp pciutils usbutils rsync nano

This is a good time to add whatever other tools you need. You can always re-enter the chroot and make changes.

Before you leave, it’s a good idea to cleanup with

apt-get clean

Now just exit to return to the host root, and detach it with

/usr/src/readyroot chroot close

Setting up the CD

Create two directories to contain the filesystem archives

mkdir -p image/{live,isolinux}

Copy the kernel and initrd. This is assuming you only have a single version 3 kernel.

cp chroot/boot/vmlinuz-3.* image/live/vmlinuz1 && 
cp chroot/boot/initrd.img-3.* image/live/initrd1

Create a file at image/isolinux/isolinux.cfg with this content

UI menu.c32

prompt 0
menu title Debian Live

timeout 300

label Debian Live 3.2.0-4
menu label ^Debian Live 3.2.0-4
menu default
kernel /live/vmlinuz1
append initrd=/live/initrd1 boot=live

Copy the ISO boot files

cp /usr/lib/syslinux/isolinux.bin image/isolinux/ && 
cp /usr/lib/syslinux/menu.c32 image/isolinux/

Creating the ISO

Create the SquashFS file

test -f image/live/filesystem.squashfs && 
rm -f image/live/filesystem.squashfs; 
mksquashfs chroot image/live/filesystem.squashfs -e boot

Create the ISO file

cd image && 
genisoimage -rational-rock \
    -volid "Debian Live" \
    -cache-inodes \
    -joliet \
    -full-iso9660-filenames \
    -b isolinux/isolinux.bin \
    -c isolinux/boot.cat \
    -no-emul-boot \
    -boot-load-size 4 \
    -boot-info-table \
    -output ../debian-live.iso . && 
cd ..

Now burn the ISO and you’re ready to go. It’s easier to attach it to a VM to test.