26 December, 2011

running a simple rails app (like wagn) with ubuntu upstart






I had a hell of a time getting my upstart script to start. It kept launching, reporting that it started and even showing a pid, but it would die. This was a version of the same script I had written in a shell script and it would execute just fine. The addition of the export HOME, suddenly made things come together.

I'd been chasing the various values in the expect stanza, but nothing made sense. Once I had the HOME export in place, I was able to find the right setting for the expect stanza after a couple of tries.

Anyway, I wanted to run a very simple rails app, called wagn, as an internal tool on an internal server. In the event that our box goes down, I want wagn to restart. Furthermore, I don't have a bunch of time to muck about with all of those full-on production ways of deploying ruby, so I went looking for the best way to run this on the platform I had in front of me. I found out the new way of running services on ubuntu is through upstart.

After looking through a bunch of things on upstart:

I found a hint... well, something I hadn't tried yet. Anyway, upstart seems to need a HOME var set when you execute. So, if you've been searching, here's a good example to go on if you want to run a rails server with upstart. You can create something similar to the following in /etc/init/servicename.conf. If you are using it specifically for wagn, edit my path below to match your install location for wagn.

# example script offered with NO WARRANTY. 
# feel free to use it or just learn from it

# wagn-server - wagn-server job file
description "wagn server"
author "robert tomb"

# restart process if crashed try 10 times every 5
seconds
respawn
respawn limit 10 5
# let upstart know the process will detach
expect daemon

# When to start the service
start on runlevel [234]

# When to stop the service
stop on runlevel [016]

# don't know why but home=root is necessary
# found it here: http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic/
script
   export HOME="/root"
   exec /usr/local/wiki/wagn-1.7.0/script/server -b 192.168.1.54 -e production -p 3000 -d > /var/log/wagn.log 2>&1
end script

24 December, 2011

the squashes are stuffed

and placed in the baking dish with care...

we're hosting christmas for t's family and she asked me to make little stuffed squash for everyone. the rice, honey, butter, raisins, craisins, cashews, cloves, cinnamon, and nutmeg have been mixed and the squashes are ready to go in the oven.

--rt

14 December, 2011

Hate bat scripting? Me too...



Abstract
Hate BAT files? Yeah, so do I. Stuck on windows for reasons beyond your control but need to do some scripting? Sure, you can use perl, ruby, python or jruby, but all of those require the installation of an interpreter.

How do you survive if you have a bare-metal windows box and aren't allowed to dictate prerequisites? You could fall back on bat scripting and risk the integrity of your hairline or you could fall back on your JavaScripting skills and go against the WSH.

I'll show you a couple of minor examples in a JS coding idiom that makes sense to me and share as many of the references as I remember that helped me with my code. Lastly, I'll give a few suggestions as to where this can be used. Hopefully, this will be enough to spur your imagination to use JavaScript solve problems you have on the windows platform.

Windows Scripting Host
Here's your goto microsoft site for this http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx . This site is going to give you all of the conceptual stuff you need to know about this. I'll talk about some things I had to reconcile and give you a codesample walkthrough.

Executing your scripts


  1. just execute a js script from the cmd line
    jsmn_all.js
  2. execute it from the command line with cscript
    cscript /Nologo jsmn_all.js
  3. create a .wsf file to define and execute it with cscript
    cscript /Nologo jsmn.wsf
  4. or just execute your wsf file from the command line
    jsmn.wsf
wsf? WTF?
Go here for info on wsh files. Basically, they offer the ability to define a script and do imports, similar to what you do in an html file with

I'm not going to get too far ahead of my self decomposing this entire script. Suffice it to say that this allows you to connect to jsmn.js and use things in it, such as the ScriptHelper object. Objects that are part of the windws scripting host, e.g., the WScript object are going to be in your execution scope no matter what, so there's no need to root around for some WSH javascript file to "include."

You can have multiple script references, but I don't know the limitations. You can even have your script entry point in one of the referenced scripts. I can see where it might make better sense (and make your editor of choice happier) if you put all logic in a js file and only used hour WSH file like a project file.

What can you do with this here WSH thingy?
Good question. Well, I have a progressive "hello jsmn" demo for you that might help to enlighten. You'll really have to dig through the Microsoft pages to see all that you can do. You can even use this to wrap windows commandline commands.

I see it as a great way to drop a toolkit onto a bare metal windows box and make yourself productive. Seems like something that could be very powerful for sysadmins or testing engineers especially for windows VMs.

Oh yeah, the demo
  

Running just this with no Arguments yields a dialog box with:Needs two arguments: one to specifiy the subject and another for desired action. Here's the ScriptHelper class we instantiate and call methods from:

/*
 * Class for grouping functions that are important to this script.
 */
function ScriptHelper(word1,word2) {

    this.desktopiconfolder = "";
    this.envname = "jsmn";
    this.write_script;
    this.fullFileName = WScript.ScriptFullName;

    this.wshShell = WScript.CreateObject("WScript.Shell");
    this.objFSO = WScript.CreateObject("Scripting.FileSystemObject");

    this.wordOne = word1;
    this.wordTwo = word2;

    this.speak = function() {
        WScript.echo(this.wordOne + " " + this.wordTwo);
    }

}

That's all well and good but...
I'd like to do something slightly more sophisticated than just echo some crap out

So, let's write to a file. I'll add a speakToFile function to my ScriptHelper class


this.speakToFile = function(loc) {

        this.write_script = loc;

        var filelocation = loc;
        if ( this.objFSO.fileExists(filelocation) ) {
            this.objFSO.moveFile(filelocation,filelocation + ".bak");
        }
        var ForWriting = 2;
        propFile = this.objFSO.OpenTextFile(filelocation,ForWriting,true);
        propFile.WriteLine("WScript.echo('from file:" + this.wordOne + " " + this.wordTwo + "');");
        propFile.Close();
    }

 and tell my WSF file to call that instead of speak.
  
Now, when I run

jsmn.wsf hellooooo jsmn

it writes a file to disk called jsmn_write.js. This file contains one line of javascript and if I execute jsmn_write.js, I'll see

"hellooooo jsmn"

So, I can write a file, what else?
There's all sorts of windowsey stuff you can do like write shortcuts... So, I add a call to a createShortcuts() method

And, this takes a few more methods to support it, but I add the following methods to ScriptHelper

this.createShortcuts = function() {
        this.createShortcutFolder("Shortcuts for " + this.envname);
        this.createShortcut("TestShortcutFor-" +
                this.envname,this.getScriptDir()+"\\"+this.write_script,this.env
name);

    };

this.createShortcutFolder = function(name) {
        var desktop = this.wshShell.SpecialFolders("Desktop");
        this.desktopiconfolder = desktop + "\\" + name;
        this.objFSO.CreateFolder(this.desktopiconfolder);
    };

this.getScriptDir = function() {
        var forShortening = this.fullFileName;
        var lastSlash = forShortening.lastIndexOf("\\");
        var shortened = forShortening.substring(0,lastSlash);

        return shortened;
    };
    this.createShortcut = function(linkName,tgtPath,args) {
        var myShort = this.wshShell.CreateShortcut(this.desktopiconfolder +
                        "\\"+linkName+".lnk");
        myShort.WindowStyle = 1;
        myShort.TargetPath = tgtPath;
        myShort.Arguments = args;
        myShort.Save();
    };

Now when I run

jsmn.wsf hellooooo jsmn

I get a shortcut folder on my desktop with a shortcut in it that has a link to jsmn_write.js. That's it for my demo, I hope it was simple enough to follow but sophisticated enough to give you some ideas for new ways to use your javascripting skillz.


Debugging?
cscript has an option for a debugger, but I have not successfully used it.
//X         Execute script in debugger
NOTE: I will research this further and update or write a new entry on this

Soo... What else is possible?
Unit testing is pretty cool and if you're developing some sort of a toolkit with WSH scripts, you might want to be able to build them with TDD or just have some tests to prove that your code doesn't toally suck. I have not tried either of these, but they look very promising:


The next time someone tells you that JS is a toy language and you can't do anything with it, you can tell them to kiss your asterisk.

Acknowledgements
Also, this post uses the awesome syntax highlighter from alex gorbatchev it's some pretty cool javascripting in its own right.

24 November, 2011

be sure to look for our results when they're posted

getting up early to run the turkey day 5k as a family. i can't wait until they post the race resultz. lookz likez we're all winnerz.

19 November, 2011

my 2011 mn cx championships experience

rode in the cx championships today. i didn't finish DFL, but i was RFC to the end. i was about 1/2 way through my last lap when i heard the announcers call the winners. i can't complain because this was my first bike race of the year. i was a little tentative on some of the grassy turns on my first two laps, but i handled the transitions really smoothly. the stairs are always a killer because they're randomly spaced and it's hard to establish a rhythm, so you just gut it out and allow your steps to syncopate and unsyncopate, randomly.

anyway, b, my youngest daughter came along and snapped a few photos of me. here's my story:

 in the staging area at the start, i'm chatting it up with, what i believe to be the only other single-speeder in the race. we ended up battling it out for a couple of laps, but i eventually pulled away from him.
 getting ready to grind up the hill... this is a mean course because right in the middle of the hill they send you on a zig zag that steals any momentum you thought you had.
 just past said zig-zag!
 the course loops around and here i get to go down the hill i'd fought my way up only just 1/3 of a lap before.
 and then there's the stairs. these classic stairs have become a mn cyclo-cross tradition.
 the stairs on another lap.
and... i'm done. this was a fun day AND i completed my race before the snow fell. the experts will be cranking through an epicly snowy state championships for the second year in a row. thanks to @smithersmpls and his promotion and setup teams for putting on this race. it's an awesome event.

playing with gimp cx photo





the photo credit goes to my youngest daughter, b, i'm the dork in the picture. i'm also the dork who edited the pictures.

17 November, 2011

shoecovers of mostawesomeness

the endura mt500 is what i recommend for @banana_patch's cold toes!

15 November, 2011

lather, rinse, repeat

last friday, i went to agile day twin cities and it was just what i needed. after a 13 year stay at my last job, i changed employers, recently. i came to the new job to help bring order to a development organization that was struggling with quality issues and degrading customer satisfaction. it's a great challenge, but i came from a much larger company and was part of a long, slow evolutionary path to agility. i'd gotten used to having people around who "just got it." now, i have people who are willing to let me try things, but there are too many near term fires to be fought to concentrate on future infrastructure.

since getting the job, i've experienced a number of up and down days. the days running up to agile day were some real down ones, and i was feeling quite isolated. i have some customer issues on my desk that are keeping me from implementing the infrastructure we need to get this shop running smoothly.

anyway, agile day was kicked off by a video address by ward cunningham download it here. in it, he makes some great suggestions that have already affected what i'm doing and how i feel about heading to the office.
  • programmers are at their best when the help others succeed
  • put the top list of things out there for the team to accomplish, together
  • work from the known to the unknown
  • when you have a good idea, you have to put it into code or else you're wasting the good idea
this last one hit me pretty hard. i had some catchup work to do over the weekend. as i sat there trying to iterate on a problem with some spaghetti code that can't be tested in isolation, i finally threw my hands up and said, "i'm not typing another 20 steps worth of data into this browser just so i can iterate!" the agile day experience had sunk in and, so i spent a little while researching web testing tools. i settled on watir and was driving tests within an hour. this enabled me to iterate much more quickly. i'm way more productive.

ok, back to ADTC, after ward's video, i attended sessions on building teams, continuous delivery, and agile engineering practices. then, during the openspace, i took part in a new-to-agile support group session called "from cowboy to agile." it was good to hear that other people are trying to grow into their agileness. 

cool stuff. 

so, building on ward's thoughts about programmers helping each other and working from the known to the unknown, i decided to introduce watir to our team. everyone smiled as i talked about it. that made me smile. really! nobody even flinched at the "opportunity" to learn ruby. cool. i do think we have the right team in place in this new shop, we just need to create enough space for us to breathe and develop software as a team.

anyway, our watir experience isn't going to be a big bang implementation. we're not going to try to write a massive, durable test suite for our entire product set, in the near term. we're all going to use it to solve our own testing needs for a while and we'll reconvene in a couple of months and see what the team has learned from using it. 

so, we're going to start with the known and work toward the unknown. once we know that, we'll circle back, so lather, rinse, repeat and we'll work our way to operating as a high-functioning team. together.

04 November, 2011

this could be trouble

a 22oz of "double bastard" from stone brewery. for 10.5% alcohol it's a scary-smooth beer.

20 October, 2011

don't tread on...

my shadow, don't tread on my shadow, man! or do... whatever.

19 October, 2011

beer on a "school night"?

well the can says "don't age," so i'm just doin' what it says

09 October, 2011

stuffed squash... fall has arrived

stuffed acorn squash with brown rice (spiced with cinnamon and clove), cranberries, rasins, honey, and cashews. mmm...

01 October, 2011

i'm rooting for my habenero plant, but...

these are number 4, 5, and 6 of the season and i have at least 20 more dark green ones on the plant.

30 September, 2011

stuff i find

i love the random crap i come across on my cyclecommutes.

27 September, 2011

got it on the first try this morning

heh... we moved from 10th floor to 12th floor last week. this is the first morning on which i pushed the right button on the elevator.

20 September, 2011

moving labels

that heath guy really gets around... product marketing, cloud technology, boxes (literally, moving boxes)

14 September, 2011

wildlife on my cyclecommute

totally would have missed the bald eagle sitting on the swimming raft in lake mccarrons this morning if i'd been driving a car. totally would have had a better camera than the one on my phone, though. time to start packing the compact 10x zoom camera on my commutes.

08 September, 2011

new booooooots!

ugliest soccer boots ever == most awesome soccer boots ever

05 September, 2011

ruins by the river

Did some shooting near the mill ruins by the river, today. Here are a few samples, some are heavily edited.







broken window

24 August, 2011

well, since i had the surly out, anyway

i figured i'd put its bottle opener to use!

look who i met on my way home

a spotted salamander was pulling a rango! it appears that, yes, he got to the other side.

22 August, 2011

the nicest thing about working from home

real live serviceable windows. a window seat at the office today would be hell.

20 August, 2011

sapcicle

we trimmed our pine tree today. it wept.

--rt

14 August, 2011

the pier at grand marais michigan

the pier at grand marais michigan is built to withstand the destructive forces of the great gitcheegumee (lake superior). we all know about its fury and power, if not first hand, at least from mr. lightfoot's lyrics. it can be pretty crazy.

well, the pier--actually a sea wall protecting the entry to the harbor--has some sections built out of interlocking steel sections that are filled with rock and cement.

 we wandered out on this structure last week and i found a bunch of interesting perspectives i wanted to capture. first, i was intrigued by the metal outer shells of the structure. their lego-like interlocking fingers were very cool, so they are the "interlocks." later, i found some rocks that still had the holes in them that were used to mine them from wherever they were quarried, and that set was dubbed the "rockholes."

the interlocks




the rockholes