Provision Fantom for Vagrant

August 12th, 2014

Vagrant is an awesome tool for anyone who needs to develop or test against predictable OS configurations. If you’ve never played with – definitely check it out:

http://www.vagrantup.com

If you have a Linux box, the steps below will get Fantom up and running. These steps are for Debian/Ubnutu – so you may need to tweak for other distros.

1. Init your box

For this tutorial we’ll use the built-in Ubuntu box:

$ mkdir example
$ cd example
$ vagrant init hashicorp/precise32

2. Configure your Vagrantfile

Edit your Vagrantfile to add a provision step:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "hashicorp/precise32"
  config.vm.provision :shell, path: "bootstrap.sh"

  # any other config you need

end

3. Add your bootstrap.sh script

Add a bootstrap.sh script in the same directory as your Vagrantfile:

#! /bin/bash

quiet() {
  # if provision is failing uncomment/comment to see full output
  #"$@"
  "$@" &> /dev/null
}

# Unzip
echo "Install unzip..."
quiet apt-get install unzip

#
# JDK
#   To install another version update 'JAVA_VER'
#   For example: JAVA_VER="7"
#
#   Note: if you use JDK7+ for compiling, then any compiled Fantom
#   pods will require a Java 7 or later runtime.  If you wish to target
#   Java 1.5 or 1.6 runtimes then you must use JDK 1.6 (JAVA_VER="6")
#
JAVA_VER="6"
echo "Install JDK $JAVA_VER..."
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" \
  >> /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" \
  >> /etc/apt/sources.list
echo "debconf shared/accepted-oracle-license-v1-1 select true" \
  | debconf-set-selections
echo "debconf shared/accepted-oracle-license-v1-1 seen true" \
  | debconf-set-selections
quiet apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
quiet apt-get update
quiet apt-get -y -f install oracle-java${JAVA_VER}-installer

#
# Fantom
#   To install a different version of Fantom update 'FAN_VER'
#   For example: FAN_VER="1.0.64'
#
FAN_VER="1.0.66"
FAN_ZIP="fantom-${FAN_VER}.zip"
echo "Installing Fantom ${FAN_VER}..."
wget -q https://bitbucket.org/fantom/fan-1.0/downloads/$FAN_ZIP
unzip -q $FAN_ZIP -d /opt
mv /opt/fantom-$FAN_VER /opt/fantom
bash /opt/fantom/adm/unixsetup
echo "export PATH=$PATH:/opt/fantom/bin/" >> /etc/profile
rm -f $FAN_ZIP

4. Boot your box

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Setting the name of the VM: linux-arm_default_1407852247628_86495
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => /Users/andy/example
==> default: Running provisioner: shell...
    default: Running: /var/folders/2v/0phd0cks4t1d4922gq7yl6kw0000gn/T/vagrant-shell20140812-95565-18zm7ni.sh
==> default: stdin: is not a tty
==> default: Install unzip...
==> default: Install JDK 6...
==> default: Installing Fantom 1.0.66...
==> default: ###
==> default: ### FAN_HOME=/opt/fantom
==> default: ###

5. SSH in and Happy Fantom-ing!

$ vagrant ssh
vagrant@precise32:~$ fan -version
Fantom Launcher
Copyright (c) 2006-2013, Brian Frank and Andy Frank
Licensed under the Academic Free License version 3.0

Java Runtime:
  java.version:    1.6.0_45
  java.vm.name:    Java HotSpot(TM) Client VM
  java.vm.vendor:  Sun Microsystems Inc.
  java.vm.version: 20.45-b01
  java.home:       /usr/lib/jvm/java-6-oracle/jre
  fan.platform:    linux-x86
  fan.version:     1.0.66
  fan.env:         sys::BootEnv
  fan.home:        /opt/fantom

Fantom wrapper for Mailgun

April 17th, 2013

Posted a Fantom wrapper for Mailgun. Has first-class support for basics (send, unsub, spam, bounces, logs, stats). But really simple to work with raw REST API too.

The Fantom Linode Guide

February 27th, 2013

I’ve stubbed out a basic guide for getting Fantom up and running on Linode. Its a bit of a work in progress – but mostly gets you from start to finish:

  • Installing Fantom on Debian
  • Setting up init scripts
  • Configuring ngnix as proxy server
  • Setting up automated deployments

Its hosted on BitBucket – so feel free to send me pull requests if you have corrections or improvements (I’m by no means a linux guru…):

https://bitbucket.org/afrankvt/fantomlinodeguide

init.d example for Fantom

August 15th, 2012

Update 27 Feb 2013 – While this should still be valid advice – it’s been superseded by a more comprehensive guide covering the whole process of getting Fantom up and running on Debian: http://www.andyfrank.com/blog/2013/02/fantom-linode-guide/

––

Been meaning to post this for awhile. Below is the init.d script I use to run Fantom on my personal sites. I’m running Debian 6 – but should be straightforward to tweak for other distros. Might need to apt-get a few things like pgrep – can’t remember what came out of the box.

A few caveats:

  1. I always install and run each “app” using a dedicated user with its own Fantom runtime. I find this really simplifies security, process management, and versioning. This example uses the fan user.
  2. This script should properly block until process cleanly exits. But don’t have a good way to know when start is complete – so just waits a few seconds. You can tweak depending on your app.
  3. This script redirects stdout and stderr to the same log file. You can tweak as necessary.
  4. I’m using a script (boot.fan) to launch my site. But you can launch Wisp or another main directly from bash string.

Example server layout:

    ~/               User home directory
      fantom/        Fantom runtime
        bin/
        lib/
        ...
      dist/          App path env
        fan.props    Empty fan.props to force PathEnv
        lib/         PathEnv lib for App
        ...

Example init.d script for Fantom:

    #! /bin/bash
    # /etc/init.d/example

    FIND_PID="pgrep -u fan java"
    STDOUT=/home/fan/var/stdout.log

    case "$1" in
      start)
        PID=$( $FIND_PID )
        if [ -f $PID ]; then
          echo "Starting example.com..."
          sudo -u fan bash -c  'cd ~/dist; ~/fantom/bin/fan boot.fan &' &> $STDOUT
          sleep 3
        else
          echo "example.com is already running"
        fi
        ;;
      stop)
        echo "Stopping example.com..."
        PID=$( $FIND_PID )
        if [ -f $PID ]; then
          echo "example.com is not running"
        else
          kill $PID
          while kill -0 $PID 2> /dev/null; do
            sleep 0.5
          done
          echo "stopped"
        fi
        ;;
      status)
        PID=$( $FIND_PID )
        if [ -f $PID ]; then
          echo "example.com is not running"
        else
          echo "example.com is running"
        fi
        ;;
      restart)
        $0 stop
        $0 start
        ;;
      *)
        echo "Usage: /etc/init.d/example {start|stop|restart|status}"
        exit 1
        ;;
    esac

    exit 0

Cinco de Mayo meets Kentucky Derby

March 24th, 2012

Weekend project for a friend.

Cinco de Mayo meets Kentucky Derby

Converting Linksys WRT54G to Wireless Bridge

March 5th, 2012

We’ve been doing some repurposing of rooms the past week or two. In the process, an office got moved to the opposite side of the house from our FiOS modem. That office unfortunately is home to a circa 2005 Dell Workstation with no WiFi support.

Since I had an unused Linksys WRT54G router collecting dust, I spent a few minutes googling if I could use that to avoid stringing Cat5 down my hallway. Turns out with the help of some open source firmware (DD-WRT), you can do just that (and more).

The overall process is pretty straightforward – but as is common for this type of thing – lots of out-dated, inaccurate, or not fully defined documentation. So I thought I’d add to the mix ;)

What This Post Covers

Just so you don’t waste time readings this – this post specifically covers:

  • Linksys WRT54G ver 2.0
  • Installing DD-WRT firmware v24 SP2 [Beta] Build 13064
  • Configuring router as a Client Bridge
  • Issues using WPA2 security
  • Primary router is a Verizon FiOS ActionTec MI424WR-GEN2 (firmware version 20.19.8)
  • Date just for reference: March 2012

Bridge vs Repeater vs Yadda Yadda

I’m no expert in this area, so I took some time to get my bearings on what I actually needed to accomplish. There are lots of terms and setups, and overlaps between setups, but a bit of googling should set you straight.

In my case, I simply wanted to join a second LAN network over a wireless “bridge.” The second network would not provide wireless access, so the primary router is the only wireless access point for clients. So we want to setup our second router as a Client Bridge.

If you wish to also provide wireless access from the second router, I believe you want to configure it as a Repeater Bridge – which requires different instructions than I present here. More information on the different modes:

http://www.dd-wrt.com/wiki/index.php/Repeating_Mode_Comparisons

If any of this information is inaccurate, please let me know.

Installing DD-WRT firmware

DD-WRT is a Linux distribution which replaces the factory firmware, opening up lots of additional features for routers like the WRT54G. Since I only really cared about the bridge capability, I chose the micro binary. Wikipedia has a good overview of what each version supports:

http://en.wikipedia.org/wiki/DD-WRT

This video covers very simple and clear instructions on installing DD-WRT firmware onto the WRT54G (ver 2.0) – from downloading the binary to uploading the firmware onto the router:

http://www.youtube.com/watch?v=QZ_oW8-fmIA

I had no issues following these instructions – and were alot simpler than some other ones I came across. Once complete you should see the new DD-WRT admin console when you pull up 192.168.1.1 in your browser.

Configuring Router as a Client Bridge

Once you have DD-WRT up and running, we need to configure the router to act as a client bridge. The best instructions I found for this are here:

http://www.dd-wrt.com/wiki/index.php/Client_Bridged

These again worked (almost) without incident. If the primary router is configured for WPA2, things will likely not work from my experience and what I could find online. Luckily it’s very simple to isolate the issue to security. Disable security on both the primary router and your second router, then retry, and everything should work like a charm.

Using WPA2 Security

If your primary router is setup to use WPA2, and things didn’t work, you have a few options:

  • Drop to WEP security
  • Drop to WPA security
  • Enable WPA2 TKIP + AES support on primary router, WPA on secondary

Both WEP and WPA should work just fine between the DD-WRT and your primary router. I spent a good deal of time trying to find a way to maintain WPA2 on my network, and the only real solution was to enable mixed mode.

So configure your primary router to use WPA2 TKIP + AES, then set the DD-WRT to use normal WPA security. This worked for me without a hitch. I would assume this only reduces protection for the traffic over the bridge, while all traffic over the primary router should be using the more secure AES encryption. But I really don’t know enough about this stuff to say for sure.

Would love to know if this is accurate, or if enabling TKIP + AES reduces security overall.

Markdown for Fantom

February 5th, 2012

Sunday Funday project for today – Markdown for Fantom:

https://bitbucket.org/afrankvt/markdown

Markdown is a great little plain-text format created by John Gruber that converts nicely to HTML. Fantom’s own Fandoc was heavily inspired by Markdown. We just simplified a few things and added some Fantom conventions in a few places. But I’ve wanted the full Markdown syntax at my disposal for some time now.

Luckily it was a pretty simple project – I was able to essentially take the great Markdownj work as-is and wrap with a native Fantom API. Code is available over at BitBucket and is licensed under the BSD license.

LESS for Fantom

January 22nd, 2012

I worked up a Fantom wrapper around LESS this week. Code and docs over on BitBucket:

https://bitbucket.org/afrankvt/less

LESS is a great little “extension” to CSS that adds lots of convenient features like variables, mixins, and nested rules that make developing and managing complex CSS much easier.

The Fantom wrapper adds:

  • An API interface to compile LESS files from a Str input or a File reference
  • A simple command line interface for compiling LESS files to CSS files
  • A BuildTask for integrating LESS into your Fantom build pipeline

Draft Mini Web Framework

July 24th, 2011

I’ve posted a project I’ve been working on in my spare time recently:

Draft Mini Web Framework

Draft is a small web framework designed to notch in above WebMod, provide some useful features, while trying to leave as much freedom as possible for your app. Details over on the project site.

Its still a work in progress, but decided it was far enough along to start being useful to anyone who doesn’t mind getting their hands dirty. Hopefully I’ll have it wrapped up here in the next few months, and can be more generally useful to developers looking for a simple and lightweight solution for developing web apps in Fantom.

Sketching Logos

January 5th, 2011

Was flipping thru an old moleskin and found two sketches I made back in Fall 2009.

Fantom logo sketch

First was a little sketch of a potential logo for the Fantom language. For whatever reason, when we changed the name to Fantom, I got this 1920s/Art Deco motif concept in my head (hence the typeface). I’m pretty sure its because of the movie The Shadow, but I keep trying to tell myself thats not the case… Never really had time to come up with a real logo — but this is one I sorta liked.

Axon logo sketch

Second was a logo for the Axon scripting language we designed for our day job at SkyFoundry. Would love to give these both some good Photoshop treatment if I ever find the time.