Monday, July 20, 2015

Yaws - Install and Configure route

I have been looking to build a wiki based on things in my head. I then figured it would be fun to write some Erlang, and I'm a fan of Yaws - Yet Another Web Server - so I decided to install yaws, designate a subdomain to it, and have apache proxy requests to port 8080, where Yaws is listening.

Step One - Install Yaws

sudo apt-get install yaws

well that was easy.

Then you can check the status of the yaws service

To view the default yaws page, navigate to the url: (localhost:8080 if on the same machine - I'm installing on a raspberry pi over ssh, so I'm useing the static IP) as seen in the status, you can also navigate to https://<URL>:8443 and get the same

Step Two - Access Yaws by Domain Name

I'm running this on a chromebook and haven't yet found a way to change how chrome resolves hostnames. To get around this, I use dnsmasq on the pi to allow computers on my network to access the local site. I put 

in /etc/hosts and reload with sudo service dnsmasq force-reload to put the new domain into effect. This allows me to access the page through (or 8443 if using https). Before going any further, I've added the apache configurations from this post to a github repository

Step Three - Eliminate the Port

In order to eliminate the need for the port, I'd like to use apache to proxy and send any traffic destined for over port 80 (the default http port) to port 8080. I do this by setting up a virtual host in my apache configuration.

I found this article very helpful when configuring virtual hosts on my server. It explains that apache looks for and reads the configuration in conf.d/virtual.conf, as well as explaining how apache treats the sites-available and sites-enabled directories. It is clear enough from their names, but I like to know why programs do certain things. Instead of being explicitly configured in a file, anything in these directories is loaded on startup by apache.

The configurations for each <VirtualHost> is saved in sites-available, and a link is placed in sites-enabled using the a2ensite command (a2dissite will clean up the link).

And the debugging begins... 

At first, I had NameVirtualHost * defined in my virtual.conf file. This caused apache to complain about mixing http and https ports. I got around this by adding a second line, and changing the * in the two lines to *:80 and *:443.

I fumbled around for a while trying to reload via: service apache2 and contstantly getting the message:
[FAILED] Reloading web server config: apache2 failed! 

This stack exchange post addressed the issue, or rather pointed me to the command: `apachectl configtest` which told me that I had a syntax error in line 5 of my virtual host configuration - ProxyPass needed a source path, and I reloaded after inserting a '/ ' between ProxyPass and my forwarded URL. This enabled me to reload apache without issue.

One more test showed displaying the main apache page, but with one last command:
a2dissite default 

disabled the default virtual host, leaving my custom virtualhost for the yaws app to handle the request.

Thursday, July 16, 2015

Toshiba Chromebook2 Pros and Cons

My previous laptop, a 5 year old dinosaur from college, finally started to go up. The wifi has been unstable for a while - randomly failing to come online after closing and reopening the lid - and then there was the heat and battery life, or lack thereof.

I would have stuck with linux if I could have beaten the $300 price point. I won't do another windows laptop; I'm stuck with windows for work, and while I have a great laptop - or 2 - I have a new gripe about the OS almost daily. For the price, and my basic needs of web access and connecting to my other computers, 

What I like:

  • easy setup for alternate keyboards
    I'm 'that guy' who decides it's a good idea to forgo qwerty for dvorak. No one understands it, and it confuses everyone who borrows my computer which can be amusing, especially if they aren't expecting it. Fortunately, there is an input selector in the system tray, with the least default options I've seen on a system: US, US International, US Extended, US Dvorak, and US Colemak.
  • new laptop for $300
  • Different keyboard
    The lack of a caps lock button was a nice surprise. I've never really thought about 
  • SSH is available - although through a chrome extension rather than crosh

What I'm not enjoying:

  • Small screen causes small text9
  • Screen is different (retina?) and contrast isn't high enough
  • Developer mode not as I hoped
  • ssh removed from crosh
  • keypad is garbage
    It would have been nice if Google would have tried some cool tricks with the keypad to keep up with Apple. The 3-finger swipe down (backwards from the 'up swipe' mentioned in the help) is a far cry from 3-finger drag/resize on my wife's macbook
  • Not a tablet, not a full OS
    Chromebook feels like a strange cross between android and a real OS


At the end of the day, I think I will like this thing called chromebook. After finding a suitable cloud replacement for my coding plus ssh and remote desktop for everything else, I won't be wanting anything more from a laptop than a browser with long battery life and an actual keyboard.

And as an effort to generate some content that makes it past the draft stage, here goes the post. I will do my best to come back to fill in the rest of my thoughts on these points, as well as include anything else I find after more than a couple hours on the device.

Saturday, July 6, 2013

Erlang Web Application: Getting Started

Lately I've been getting back into building my own web application. It started with some MongoDB which led to Python and Bottle through this video to Apache to Yaws and Erlang.  I've finally settled on working through some of the examples included in the O'Reily book Building Web Applications with Erlang.

It's been a lot of installation and figuring out what goes where, but I'm starting to see some cool stuff. I really like the idea of running a web application through Yaws. Erlang has always made a lot of sense to me with it's light-weight application threads and message passing.

More Details

I didn't do anything special from the standard way of installing packages in Ubuntu. I don't think there's anything special other than
steve@ubuntu$ sudo apt-get install yaws
This should install all the dependencies, including Erlang which you'd need to get started. The yaws service is started, using 
  as a home directory for the server. Starting/stopping/restarting the service is as easy as:

steve@ubuntu$ sudo service yaws <command>

 First Examples

  I just have a couple very simple examples right now. Hopefully more to come shortly. One thing I've found is that if you modify index.html in the server's home directory, changes can be seen by visiting localhost:8080/index.html but not simply localhost:8080 until you perform a server restart (or maybe reload). Most likely due to file handles of the server. Fortunately, creating examples and running <erl> tags within new files works because you specify the URL for the files explicitly, so you don't have to restart the server between every step.

First output

The first example was straight from the book. Creating method.yaws in the server home directory:
method(Arg) ->
  Rec = Arg#arg.req,

out(Arg) ->
  {ehtml, f("Method: ~s" , [method(Arg)])}.

Then  browsing to localhost:8080/method.yaws shows that you used a get request.

 Simple Redirect

The next simple example is to redirect to another page:
method(Arg) ->
  Rec = Arg#arg.req,

out(Arg) ->
  {ehtml, f("Method: ~s" , [method(Arg)])}.

This simply redirects to the method.yaws example above.

Saturday, September 22, 2012

Standalone Java Application

I've been using java for years, but I've never really used it to create a standalone application that actually did something. In school we were spoon fed projects to work on. At work I add to or fix the current java web applications. What I really want is to write programs that do what I want them to do. But what is that? I've tried asking others what would be helpful, but without real passion for what needs are out there, I'm not going to get anything done. It's time to start coding and let the purpose follow. My current goal is to start coding some helpful utility applications, so when I have a real purpose I'll have the means to jump right in. So skipping command line execution of plain class files... I started with creating Executable Jar files.

Requirements for the Executable .jar

Class files
Something with a main method to run. I'll be starting with the quintessential 'Hello World' project.
Manifest file
The manifest tells the jvm what you want the point of entry to be for the jar.

Hello World!

My little java class lives in the demo package, and prints "Hello World!" and then lists the arguments passed in.
package demo;
public class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello World!");
for (String each : args)
System.out.println (each);
Compile the classfile (commandLine$ javac and you're good to go.


This file is just one line, and ends with a newline
Main-Class: demo.HelloWorld

Putting it all together

Here's what I have so far

 The .java file isn't really necessary from this point forward, but if you want to go back and look inside your jar for the source code you'll want to keep it around.

Create the .jar

Use the jar utility to package up the jar. cmfv = create, manifest (filename), filename (for jar), verbose

jar cmfv MANIFEST.txt demo.jar demo
added manifest
adding: demo/
adding: demo/
adding: demo/MANIFEST.MF
adding: demo/HelloWorld.class

The Result

All said in done, we're left with demo.jar
When you run java -jar demo.jar in the command-line, you get the result below
steve:~/Desktop$ java -jar demo.jar
Hello World!
You can also add extra parameters and they will be printed below
steve:~/Desktop$ java -jar demo.jar what\'s\ up?
Hello World!
what's up?