Josh Nock

Code Craftsman

Sinatra (Ruby) on IIS 7.5+ with HttpPlatformHandler

Here's an instruction guide (or should I say a documentation of my experience) to get a ruby-based web app running on a Windows server under Internet Information Services (IIS) version 7.5 and higher.
Specifically, "How to install Dashing ​​on Windows Server with IIS 7.5+."

What's Dashing? you might ask. Well here's a quote from their website.

"Dashing is a Sinatra based framework that lets you build beautiful dashboards."

Now I know you're probably thinking Sinatra/Ruby on Windows under IIS? 

what?

Ouch, but why?


Background:

At work, we wanted to have a live dashboard with a data feed from our build server and our project management server (rallydev). We set up a Raspberry Pi with ubuntu-mate; we installed dashing with ease, and we pulled down a git repository with our customized work. We used RubyMine to develop locally on our windows laptop and committed the work to a remote repository, which the raspberry pi was able to access. This is the result:

DEvOps_Dashboard_current.png
It's current location overlooking the cube farm:

DEvOps_Dashboard_currentLocation.jpg

Goal:

Have the dashboard accessible from each developer's computer without the need to physically walk by Big Brother. Have the site under IIS so that when the server crashes or reboots IIS restarts the site automatically, eliminating the need to log into the command prompt on the server and restart the dashing app.

Requisites:

Only windows servers were available for this installation, so I chose to install it on the server we were already choosing to use for internal tools that we have set up; such as a Nuget Server.


Steps:

  1. go to RubyInstaller.org > Downloads
  2. Install version 2.2.x, which is more stable than the newer 2.3.x

    this should add Ruby's bin to the PATH environment variable, to check, open a command prompt and type the following
    C:\Users\you>ruby -v

    it should respond with something like this:
    C:\Users\you>ruby -v
    ruby 2.2.4p230 (2015-12-16 revision 53155) [x64-mingw32]

  3. Install Ruby Installer Dev kit (on the same page as the regular ruby installer) this is needed for Dashing.
  4. The devkit runs an extractor, which will ask you for the permanent location for the devkit, I chose to install it under the ruby folder, which on the server looked like c:\Ruby22-x64\devkit
  5. Open a command prompt and CD to the devkit directory and run the following commands:
    C:\Ruby22-x64\devkit>ruby dk.rb init

    This creates a config.yml file which lists the location of your ruby installation. It never seems to find the location for me; maybe it's my choice of devkit location. open the config.yml file located in the devkit directory and make sure last line is the location of your ruby install. For my instance it looks like this

    RubyInstaller_DevKit.png

    next run the following command from the same command prompt
    C:\Ruby22-x64\devkit>ruby dk.rb install
  6. Install Dashing - you'll need to install the Dashing ruby gem so that you can create your starter instance of the site.
    1. With the command prompt still open type the following command:
      C:\Ruby22-x64\devkit>gem install dashing

      It doesn't matter where you run this command within the command prompt as 'gem' is a ruby command that is now accessible anywhere, and the 'gem' that is installed is installed globally under the Ruby installation directory.

    2. Create directory for your new dashboard: I use C:\websites\
    3. Here is a blog post about best practices for not using the default c:\inetpub\ directory.
    4. don't forget to give the user group "IIS_IUSRS", the "read & execute", "List folder contents", and "Read" persmissions on your new directory.
    5. Open command prompt and CD to this new directory.
    6. Run the following dashing command
      C:\websites>dashing new sweet_dashboard_project
    7. CD into this new directory
    8. Run the following ruby gem command:
      C:\websites\sweet_dashboard_project>bundle
    9. Now lets tests that the website works outside of IIS, run the following command:
      C:\websites\sweet_dashboard_project>dashing start
    10. Open a browser (this site wont work in IE) and navigate to localhost:3030
  7. Install HttpPlatformHandler v1.2 ​on IIS using WebPlatform Installer
    1. Here is a great blog post by Scott Hanselman about this IIS plugin - Announcing: Running Ruby on Rails on IIS8 (or anything else, really) with the new HttpPlatformHandler - Scott Hanselman
    2. And here is a video presentation on Channel 9 by Scott Hanselman
  8. Create the web.config file needed to run the website
    1. open the directory you created for the website e.g. C:\websites\sweet_dashboard_project\
    2. create a new file web.config
    3. edit the file to have the following:

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration> <system.webServer> <handlers accessPolicy="Read, Script"> <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" /> </handlers> <httpPlatform stdoutLogEnabled="true" stdoutLogFile="c:\logs\dashing.log" startupTimeLimit="20" processPath="C:\Ruby22-x64\bin\ruby.exe" arguments="&quot;C:/Ruby22-x64/bin/dashing &quot; start -p %HTTP_PLATFORM_PORT% -e production"> <environmentVariables> <environmentVariable name="HOME" value="C:\Users\<<%%YOURUSERNAME%%>>\" /> <environmentVariable name="EXECJS_RUNTIME" value="Node" /> </environmentVariables> </httpPlatform> </system.webServer> </configuration>

    4. In the config file please change the environment variable for HOME to your user directory (the user you installed ruby with) as ruby will need access to the .gem folder located there. On the C:\users\%yourusername%\.gem folder I also granted IIS_IUSRs user group, the same (execute, list and read) permissions as in step six to this folder.
      Also, on the httpPlatform element I have the logging enabled for initial debugging, and I'm outputting the logs to a simple c:\logs\ location that the IIS_IUSRS has read write access to.

    5. SETTINGS: To explain the settings in <httpPlatform></httpPlatform>, processPath points to the underlying process that will run your website, in this case it is the ruby executable that will run dashing, which is based on the Sinatra framework. You can point this at any executable that will handle http requests. The arguments setting is obviously intended to pass any argument the executable will need when IIS starts the process. There are also stdoutLogEnabled and stdoutLogFile setting which should be self explanatory, and there are more variables shown above and even more available, so please check the HttpPlatformHandler documentation online. Environment variables set in this section will be accessible to the running process, so you can provide them here as opposed to actually adding them to the servers environment variables which you may not have access to with permissions.

  9. Install NodeJS
    1. Go to Node.js website, download and run the installer.

      The reason for installing NodeJS is to provide and alternate coffeescript compiler for ExecJS, I ran into encoding issues using the default cscript. and while using NodeJS is not ideal for this stack, the server I'm using is more than powerful enough, and it works flawlessly.

    2. After installing Node, you'll need to restart the server.
  10. Configure IIS for the new site.
    1. open Internet Information Services manager
    2. right-click on the server name and click add website.
      add_website.png
    3. type in the name you want to give the website for Site Name
    4. Select the directory we setup as the physical path, this directory should have our web.config we created, sitting in it.
    5. If you have other websites under the default website then you'll want to pick another port name or add a host name to this site for IIS to differentiate the incoming http requests.
    6. I also set the application pool to No managed framework and Classic, as this site will not be attempting to access any .net framework components.
      final_iis.png
  11. You're finished!! Navigate to the url for your new site and you should see the sample. For more customizations, you'll have to read up on the Dashing documentation, possibly install RubyMine (which I recommend for easier development)
    sample.png

Ta Da!

BeagleBone Black NAS Server

So you got a beaglebone black laying around? “

beagle bone black rev c

 
Photo: adafruit.com

It was fun, but now you’ve run out of ideas.  Well if you’ve been thinking of getting an external storage device for backups and don’t want something you need to turn on or off every time you need to backup a file or download something to your laptop.  Or lets say you’ve got a hard drive laying around with a bunch of movies and photos you backed up.  Well lets set up your low power BeagleBone Black as a NAS server.

First if you don’t have a revision C beaglebone, you’ll want to swap out the default Angstrom operating system for a more common *nix OS.  There’s a great tutorial on Adafruit.com to guide you through installing a new operating system. 

I choose ubuntu so all my instructions here will be based on those commands for that brew of linux.
Start by updating your os

> sudo apt-get update 

Next we’ll want to install samba which will let us create a network share

> sudo apt-get install samba samba-common-bin 

Now we’ll want to create a directory that we will map our external hard drive to, this directory will be become a “virtual” directory once the OS maps to the hard drive.

> cd ~/     
> mkdir mnt
> mkdir mnt/usbdrive

Ok, so with Samba, you can actually create password protected folders for individual users, and the configuration for samba you can specify where this directory is, but we are going to take advantage of the public share features (no authentication necessary) of samba, and share the entire hard drive.  Please note I’m assuming you’ll keep this behind a router with a fully enabled firewall, less you really love giving the NSA minimal resistance to snooping.

What we want to do next depends on whether you have a brand new hard drive or an existing one.  If you have a new hard drive, follow these instructions for formatting your hard in ubuntu but stop before last section on mounting and come back here.

Chances are if it’s an external hard drive you used with your windows PC, then it is formatted with NTFS.  If you have a brand new drive than it is recommended to use ext4 for most *nix operating systems.  You’ll want to google how to format a new drive for ext4, as I have not gone through that yet.  If you’re like me and stuck with an NTFS drive with a bunch of crap on it already, then you’ll want to install some ntfs driver goodies.

> sudo apt-get install ntfs-3g

So lets plug in the hard drive to the Beagle and see what we get.  We need to find out what drive the OS sees, normally it is something like “/dev/sdaX” where x is an assigned number.  Seeing as my beagle bone has no other drives attached it shows up as /dev/sda1 but for you to be sure you can just type this

> ls /dev/sd*

 this should list the directories/partitions for the connected drives, you can also use the following command to see which drives your system can see and which partition is which based on size.

> sudo fdisk -l

the parameter after fdisk is "L" as in list the drives.  ok. so now that we're sure which drive is our external hard drive, lets mount it to our "/mnt/usbdrive" directory we created earlier.  we can do this manually with the following.

> sudo mount /dev/sda1 /mnt/usbdrive

now make sure you use the correct /dev/sda* <- drive directory for the mount command.  to check if this works, you should be able to browse the contents of the directory.

> ls /mnt/usbdrive

Now we need to configure the samba server, but first a caveat, you can use samba to create user specific directories that are password protected.  I was not interested in using these features and just wanted a public folder that anyone inside my network can access.  

First lets make a backup copy of the default samba configuration

> sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

Next, lets edit the configuration for the public folders

> sudo nano /etc/samba/smb.conf

Find the section public folders section and we'll want to change it to following

[public]
    comment = Public Files
    path = /mnt/usbdrive
    browseable = yes
    writeable = yes
    guest ok = yes
    read only = no

Now if you're using nano editor, to save and exit, first hit ctrl+X then type Y for yes to save the changes and next hit enter to save it with the original file name (ergo, overwriting the existing file).

Next we need to restart the samba service

> sudo service samba restart

Now you should be able to navigate windows explorer to the shared drive, but you'll need to know the name of your beagle bone, (the name you told ubuntu to name the computer when installing), or you'll need to know the IP address.

In windows explorer you'll want to enter the following

\\(name or ip)\Public
or
\\(name or ip)\

If you're not able to access the drive or you can't create a folder or copy a file to it.  It may be that the drive doesn't have the correct permissions set.  The following will allow that

chmod -R 777 /mnt/usbdrive

Now the very last thing to know is that if your Beagle Bone resets or reboots the external will no longer be mounted.  And you'll need to login and remount it, unless you instruct the OS to re-mount on startup.  I'll go into detail with that in the next post.  but for now you'll just have to quickly SSH into your beagle bone and run the mount command.  it'll keep your linux skills un-dull.

Free Tools: SQL Search 2

So you’re working on a large scale legacy project, you been assigned a ticket for a bug.  The app uses one or more databases and you actually got your hands on the log and see the exception is coming from an object in SQL Server, you have the name (of the table or stored proc) but where is it?  Redgate SQL Search 2 is one invaluable tool I am very grateful they offer for free.  If you’ve ever connected your SQL Server Management Studio to a database only to find a list of over a thousand stored procedures, you know that needle-in-a-haystack hopeless feeling.  Or lets say you’re trying to find out what function or stored procedure is mysteriously changing data in a table, SQL Search can help you find those devious minions. 

Search across multiple tables and objects

Scope the extent of your search


Type-ahead live search results

Results are returned as you type


Jump directly to the object.

Quickly jump to the found objects

I’ve tested Redgate’s other free trial tools and found SQL Compare to be amazing, unfortunately I wouldn’t use SQL compare enough to justify the price, even though it is a powerful and valuable tool.

Photo credits: Redgate

Windows Azure and SSL Certs

If you want to add SSL certificate to your Azure Service, and your service is running as a Web Role, I’ll go over what steps I took to get it set up for a client.  This process will go much much faster if you have IIS Installed on your local machine, or you have access to Server 2008 with IIS installed.  I suggest using Microsoft’s Web Platform Installer to install IIS if you don’t have access to a server.

Once IIS is installed, open up Internet Information Services (IIS) Manager. Click on your computer’s name which is listed under “Start Page” in the connections column of IIS Manager.  Once your computer is selected you should see  the similar menu below in the features view.  Double click the server certificates icon which should be under the IIS sub-section.

image

In the Actions panel on the right hand side, click on "Create Certificate Request"

image

When the "Request Certificate" wizard opens, fill out the information about your site and Organization.  For the organization unit, I usually put research or engineering.  I don't know the importance or significance but I'm sure a google search can tell you that.

image

For the Crypto Service provider, I selected MS RSA, with a bit length of 2048, this bit length should be the minimal length to use.  If you chose something higher you may want to confirm that it is compatible with the Azure SSL features. 

image

Select a location to drop the request into a file, and you'll want to add the file extension .txt onto the name you chose. 

image

 

Ok so here's the tricky part, you get to pick what SSL provider you're going to use.  Obviously budget will most likely dictate your choices, I was able to find a relatively cheap SSL just googling for SSL, and I have found reasonably priced wildcard SSL certs for around $80 per year, for two years.

Once you have completed the purchase process for the cert, they will email the certificat to you.  You will need to save the certificate to a file with the .cer file extension on you computer.

 

In the Actions panel, click on "Complete Certificate Request"  

image

Select the certificate from the location you saved it, give it a display name so you can identify it in the certificates list.  and I chose to leave it in the personal certificate store so that I can export it later and upload it to Azure.

image

After you have finished completing the certificate request.  You will see it show up in the certificates list.  Here you will need to click on the certificate you wish to export and in the actions panel on the right hand side, click the action “Export…”

image

Next you select a location and name to save the cert, c:\mynewsslcert.pfx is always easiest.  And you will want to pick a strong password when completing the export.

image

After that, you just need to go to your Azure website or Azure service, under the “configure” section there will be a certificates sub-section that will allow you to upload the cert.  If your website needs the rest of the certificate chain, these should have been provided in the email from the certifying authority, or you should be able to find instructions on the CA’s website about obtaining and uploading the cert.

Best tools for Netduino or Arduino

Here’s my list for the best tools you’ll want when working with the Netduino, or the micro-controller of your choice.

WP_000024

If you’ve just started to learn netduino or arduino or the *duino of your choice.  You’ll probably be thinking about what would make it easier to prototype the ideas that you have.  So here is a quick list of the stuff that has made working with my devices a little easier.

  1. A prototyping sled
    1. Keep all your prototyping items strapped down to a platform that’s easy to organize on.  But you’ll need a AA battery holder and a 6” breadboard
      sledsled1
    2. for powering the breadboard a AA battery pack with an on/off switch is a nice choice.
      image
  2. A fishing tackle box
    1. Plano tends to be the leader with the widest variety of tackle boxes available at your local outdoor store.  There are varieties made specifically for tools and hardware at Lowes or Home Depot, but those are generally a little more money.
      image
  3. A helping hands stand
    1. when soldering new parts together, from different unassembled kits, you’ll quickly wish you had four hands.  And this stand will more than earn it’s worth.
  4. Miscellaneous parts kit
    1. Unless you live next to a radio shack, you’ll never know what small miscellaneous part you might need. The sparkfun beginner parts kit is something great to start with and comes with a nice little box that keeps it organized.
  5. Obligatory soldering iron
    1. I probably shouldn’t have to put this on the list but I won’t make any assumptions, if you don’t have one, you won’t get very far working on your own projects…

kerbauth.dll failed to load

So you’re getting this error, when you try to restart an application pool in IIS7? 

image

The data is the error?  What the?  All your base belong to us too, huh?

Well, quick question; Did you uninstall Exchange Server CAS/WebAccess, or modify the original installation?  Well in my case I uninstalled Exchange Server CAS from my webserver.  And it promptly broke all my sites.  After some googl’ing I found that Kerberos Authentication is an IIS module. (obviously related to exchange)  Ok, fire up IIS Manager and lets look at the servers modules…

image

Nope, it’s not there… hmmmm….  Back to google….

Aaahhhh, yes, I remember that web.config thingy for IIS itself… where was that…  oh yeah, I remember, pfft, no I don’t.  Thank goodness for Google.

C:\Windows\System32\inetsrv\config


image

Alright lets take a look at this thing…  ctrl-F to search for “kerbauth”, oh look, there it is…
Well I didn’t have exchange on this box anymore sooo… lets just comment it out, cause I don’t wanna mess with this file too much, it could really mess up IIS.

image

ok, back to IIS and restart my app pools,

Code-Literacy, and the Future

It is obvious how technology has transformed our lives and continues to evolve at break-neck speeds.  It has opened new vehicles of communication that many of science fiction’s greatest,  did and couldn’t predict.  And inside these magnificent machines, is code.  It is code that under-pins the technologies that have connected our social lives.  It is code that under-pins every industry that seeks out efficiency, quality and profit.  It is code that is pushing the experience of life to it’s greatest achievements.  So what is code, but a form of communication between man and machine.  Yet code, is a relatively new form of communication.  In the context of human history, it is by all means in it’s primordial forms. With a multitude of various species, known as languages, some beautiful, some ugly, some young, some old, and some bred for specific tasks. 

Code by itself has not transformed our world, but with the machine it has paired with, we have passed a point of no return.  Now if we look back to how we got here, we can see the progress of communication, that brought us to this point.  From stone tablets to the printing press, ideas were spread, from person to person.  And with this progress, math, science and the arts were born.  But during this march of progress, we can see with perfect clarity the advantages a society and it’s people had with being able to participate in the communication with the ability to read and write.  For much of the progress could no longer be maintained by word of mouth alone, but rather needed to be written down, duplicated and distributed.  So today, much of our progress can no longer be written down, petabytes of data, multitudes of small and inexpensive machines embedding into every crevice of our lives.  Is it possible that we are at another transition point where learning to communicate with machines, by way of code will give clear advantages to the individual and their society?  I would argue so, whether directly authoring code or working with code-smiths, knowledge of code and the paradigm of thinking it introduces will be the advantage for future generations.  Just like literacy in humanity’s past created clear advantages, so will Code-Literacy.

 

Josh

Historical look at Literacy 

How to Change the Bitnami ownCloud Default page

So in the previous post on ownCloud we launched the EC2 instance and made some DNS changes to build our own private dropbox at a fraction of the price….  but… it left us with this UGLY landing page.

image

And I’d prefer it to look like this when I go to the site.

image

 

So lets fix this…

First you need to download Putty, which is a very nice SSH client, or you can use the SSH client that amazon lets you run in the browser.

Grab the installer and just use the default settings.

image

Next make sure you download your key pair from Amazon.  After you have your key and putty installed follow amazons instructions for converting the key and using putty.

Once you have successfully logged into you EC2 instance, we’ll need to navigate to the apache directory and change the default configuration.


First change directories.

: cd /opt/bitnami/apache2/conf/

Next edit the httpd.conf file.

: pico httpd.conf file

It should look something like this (also you can use the command ‘ls’ to list the contents of the current directory)

image

Navigate down to the line that shows document root.

image

Here you can see I commented out the original line and added “org:” to the front of it.  (noob tip: The # symbol is what comments out the line, and tells apache to ignore)  Changing ‘DocumentRoot’ changes the default directory for apache.

 

There is also a second line to modify just a little bit further down (2 x PgDn)…

image

Now to save the file, it’s ctrl+O (“Write Out”), it will prompt you for the filename, in which it will already be shown.  Hit enter and the file will save.  Then it’s ctrl-X to exit the pico editor.

image

Now we need to restart apache for the change to take effect and there is a shell script that performs this for us.  To restart apache use the following command:

: sudo /opt/bitnami/ctlscript.sh restart apache

if there is anything wrong with the httpd.conf file then it most likely will stop the process and write out the error to the screen.

Otherwise you should see this.

image

 

Now when you go to the default landing page for your EC2 instance you should see your login screen.

image

 

Aaaahhhh so much more cleaner!

Technorati Tags: ,,,,,,,,,,,
WordPress Tags: How-To,DropBox,EC2,Amazon EC2,AWS,Amazon Web Services,Bitnami,Amazon,DocumentRoot,ownCloud,apache,pico

Milton!?!

New project manager in the office today.  He sounds too much like Milton.


ok, strange...  =|

Even stranger, a few hours after the initial standard greeting, the first thing "Milton" says to me...


"Where can I get a stapler?"


I think I stared him down for too long, before replying!! =/
Seriously, who's pranking me??

Dropbox Vs. ownCloud

So as the story goes, while lurking on Hacker News, I saw a story posted on how to set-up a RaspberryPi as a personal web server.  I had been thinking about this for a week or so since getting my own RaspberryPi.  I already host development sites from my own server at home, and much of the technical DNS/hardware element for this potential project would not be the challenge, but rather, configuring a server on this micro machine… (you know you’re old if you just thought of these) would be the real challenge.

So when reading the lifehacker.com article for setting up a Pi as a webserver, it mentions creating a drop box clone.  Wait what!?!  Exactly!! I have been forced to use dropbox with a few other friends to share files and the constant collision with the storage limit is annoying especially because we’re all cheapskates, and don’t want to pay.  As all interwebbers know, one click leads to another… and I was staring at the home page of OwnCloud (cue: Hallelujah Chorus), completely joyous.

image

 

I’m not too good with linux, but can survive and make my way around a LAMP stack.  So as I explored the installation options for OwnCloud, somehow I stumbled upon Bitnami’s AMI for owncloud in the Amazon AWS marketplace.

image

It was estimated at $14 a month for the micro instance…  ok $14.. that’s a bit of money… so after some testing… this micro instance for just me and a handful of users is still blazing fast…, ok, I’ll give it a shot for a month or so!  Two clicks later and I had my own installation running on EC2.

image

and here’s the actual homepage of the new instance…

image


So, I didn’t want to use some crazy huge  EC2 URL for the site, and I have PLENTY of domain names.  So I needed to figure out how to properly point one of my domains to Amazon.  After some Googling I determined my EC2 needed a dedicated IP, this is where elastic IP comes in.  Next I grabbed an elastic IP and assigned to my new personal instance of dropbox OwnCloud. 

image

 

I had also read that you can move your DNS hosting over to Amazon’s Route53, so I also did that but it might be to much to go over at this point.
But if you’re domain name is hosted at godaddy, you can change your DNS records there to point to the new IP address assigned to your EC2 instance.  You will not be charged for your Elastic IP as long as it is attached to your instance and your instance is running. 

once my DNS records were updated I could now type in a shorter url to get to my OwnCloud, but there was a problem…

This was the landing page…  meh..  dis-like!
image

yet, this is what I want the landing page to look like…

image

So I noticed that the app is residing in the /owncloud/ directory and I could probably re-direct, or move that directory to the root.

Long story short I found some instructions for different application but they did work and I will re-post them here for part II

to be continued…