Saturday, February 4, 2012

No such compiler 'groovy-eclipse-compiler'

I have a maven project with a groovy REST interface running inside Jetty. The groovy-eclipse-compiler will compile the groovy code into Java code.

Sounds simple and the codehaus page for the plugin makes it look even simpler. But when I ran mvn jetty:run, which should have rebuilt the entire app for me before deploying to jetty, I received this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project cellers: No such compiler 'groovy-eclipse-compiler'. -> [Help 1]


What bullshit. That's what you're thinking, right?

But what I missed is that when changing/adding compilers, which is effectively what you're doing here, the new compiler needs to be a dependency of the maven-compiler-plugin.

  <build>
    <finalName>cellers</finalName>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>8.0.4.v20111024</version>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
          <verbose>true</verbose>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.6.0-01</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

Friday, June 17, 2011

timbit! Getting description from NASA's Astronomy Picture Of the Day

After writing this bit to Retrieve NASA's Picture Of the Day for my wallpaper I immediately wanted the description that goes along with the image so that I know what I'm looking at.

I considered adding the description to the picture itself so that I could read it whenever I'm looking at the wallpaper.  But that's ugly, detracting from the image.  And the description is usually several lines long (more than 10) so it might not fit well on the screen.

So then I considered writing a plugin for my panel (taskbar) that would pop-up a little widget with the text.  Seemed simple enough but I'm using lxde which only supports native plugins in C - there are no bindings for other languages.  Still undaunted I looked around for documentation - here's what their wiki says about it:

http://wiki.lxde.org/en/How_to_write_plugins_for_LXPanel

That's right - there is no documentation other than some random individuals that took it upon themselves to post some solutions.  The ones I found weren't perfect and I quickly realized this would take more than an hour.  NOT worth it.

So back to bash I go - I'll get the description at the same time as the image and put it in an html file next to the image.  Then I created a shortcut in the LXPanel to open chromium to that file whenever I wanted.

#!/bin/bash

BASE_URL=http://apod.nasa.gov/apod/
PAGE_URL=${BASE_URL}/astropix.html
APOD_IMG=~/images/wallpapers/apod.jpg
APOD_PAGE=~/images/wallpapers/apod_page.html
APOD_DESC=~/images/wallpapers/apod.html

# get the file once
wget -qO ${APOD_PAGE} ${PAGE_URL}

grep "IMG" ${APOD_PAGE} | \
    wget -qO ${APOD_IMG} \
    ${BASE_URL}`awk -F "\"" '{print $2}'`

START_INT=`grep -n "<b> Explanation: </b>" ${APOD_PAGE} | \
    awk -F : '{print $1}'`
END_INT=`grep -n "<p> <center>" ${APOD_PAGE} | \
    awk -F : '{print $1}'`
grep -A $(( ${END_INT} - ${START_INT} - 1 )) \
    "<b> Explanation: </b>" \
    ${APOD_PAGE} > ${APOD_DESC}
rm ${APOD_PAGE}


Definitely more wordy than the original but the varying length of the description required a little more work to determine the number of lines to scrape from the html file.

I'm interested in more concise examples. I tried sed but that gets multiple lines in a way similar to grep.

Then, after adding a shortcut to my panel for chromium to open the file I also added a keyboard shortcut to make getting the description easier than anything IN THE WORLD!

Scraping the description just to open it locally with a browser is a little ghetto but it's faster than loading a bookmark and writing the bash solution only took a few minutes.

Monday, June 13, 2011

timbyte! Setting up my first VPS

Updated June 18, 2011

The control panel

Only having one VPS I didn't see the need to pay for a third-party control panel license.  Maybe if I ever control many servers I'll want something "more".

DirectSpace's control panel allows me to
  • easily see how much disk space, memory and bandwidth has been used.
  • boot, shutdown, and reboot.
  • reinstall the OS, change root password, login via a console, change the hostname
  • view/change IP addresses
  • view logs, stats
  • manage backups
Note: I wasn't initially able to login via the console ("failed to read messages" error).  I had assumed I needed to use my root user or another user, rather than the console username they provide.  I then went into "Console Settings" and updated the password, and tried again using the provided username.  Logged in no problem.

DNS

I pointed my godaddy's DNS entry to the IP address DirectSpace provided, was able to ping it and ssh to it seconds later.

My OS environment
  • I added my public key to root's account.
  • I created a user, logged in remotely and added my public key
  • In this case my user could not log in using the key.  I haven't looked into why yet.
  • This is intended to be a production server so there are no compilers.
nginx

My website will be static, at least for the first several months, so I want the lightest/fastest server.  This makes sense if only to be a good VPS citizen and use as few resources as possible.

nginx requires EPEL.  I couldn't find EPEL for CentOS 5.3, but 5.4 seems to work alright:
rpm -Uvh \
http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpm
Next comes nginx:
yum install nginx
Say "y" to import the GPG key.
Now, if you're following along on your own fresh new VPS and you were to type "nginx" right now you'd see this:

[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)

Turns out the Apache web server is already installed on these "unmanaged" VPS's, which I found out by doing a little netstat magic:

netstat -pant | grep 80
So I killed it and then removed it from the rc dirs:

rm /etc/rc.d/rc?.d/???httpd
I created a directory in /home/nmt (the name is not important, "nmt" happens to be the abbreviation of my new website), put an index.html file in there, and edited /etc/nginx/nginx.conf to have the / Location point to it.  Then type "nginx" and away we go.  No need to worry about firewalls or such - since it was already configured for Apache httpd, port 80 is already opened up.

Update: Noticed a few days later my website was down. The server had been rebooted twice and nginx didn't come up because the default nginx rpm installs it as K15nginx for each runlevel. I updated the chkconfig settings in /etc/rc.d/init.d/nginx to start on 3 and 5, removed the current symlinks in the rc dirs, and ran chkconfig.
# chkconfig:   35 85 15

Open Questions

There's still a lot I don't know about this machine, some questions great, some small.

  • Why can I use key authentication logging in as root but not as another other user?
  • How is traffic getting to port 80?  iptables is run on start up but I don't see any configuration for it.
  • Can I run a port scanner against my VPS or will my provider object?
  • Given it's CentOS 5.3 I'm having trouble finding rpm's for it already.  What are my options for security patches?
  • Are there additional OS's available?  I haven't see anything else made available yet.
  • Are there any decent wiki/faq/help pages from DirectSpace about their VPS's?

Update: I've put in a support ticket to see what other OS's are available and to find out why the server was rebooted twice today and to see if there are any rpm's I need to keep on the server (I want to remove several of the extraneous ones like the talk and finger servers, httpd, xorg).

Update: Also found I was getting an error from sudo every time I ran it:
audit_log_user_command(): Connection refused
But a simple "yum upgrade sudo" fixed that.

Sunday, June 12, 2011

timbyte! Choosing between application hosting and VPS

My wife needs a website for her new business so I needed to decide how I wanted it hosted.  This post documents my experience finding a provider.

My choices

  • application hosting - where the hoster provides a running web server and database for me to install my app
  • vps (virtual private server) - where the hoster provides a virtual machine with a base OS and I install any other apps on it that I want to use.  There is a great deal of variability in "managed" VPS's and unmanaged VPS's.
  • dedicated server - this would be overkill.
My requirements

Website requirements: The website is around 10 pages and while we have ideas for a shopping cart and a need for her to add content herself for the next 6-12 months a static site is all that is needed while she builds other parts of the business.

Developer/admin'ing constraints: I'm primarily a Java programmer with a little linux sysadmin experience.  But at the same time I want the option to use other languages in the future (I'm thinking ruby but potentially a js server as well).

Budget constraints: for the first 6-12 months we want to go "budget" until the business has proven itself and until it's demonstrated a need for a beefier website.  A brief survey showed that the cheapest application hosters were $5-$10/month.

Considering application hosting

There are providers that give me a Java web server (with tomcat the most frequent choice), there are providers that give me rails.  Most providers have php, perl, maybe python as well.  They all have mysql and sometimes postgresql available.

There are fewer providers that host both a Java web server and rails.  I noticed a jump in costs as well, usually $10 or more a month.

So I tried to find reviews of these various companies.  Finding a large enough sample set of reviews to get an overview was difficult.  For example, a single flaming review of how a hosting company wronged the reviewer holds little water.  The reviewer usually ends up sounding impatient, entitled, and ignorant.  At the same time a single positive review might mean the poster just got lucky and didn't need much support or bandwidth.

The only clear thing I noticed was that no Java provider was generating more positive than negative reviews.  In this case I'm concluding "budget" means "poor performance/support".

Considering VPS

Originally I didn't wanted a VPS.  I thought I was happy to let someone else sysadmin my server and the application server.  But given the poor reviews of Java hosting companies I started to look a little more earnestly at VPS's.  Here again pricing varies wildly and widely, but for now I wanted a bare bones system that is reliable and that let's me play on a single server.  No need for enterprise-quality control panels for my VM, for example.

I found a couple important websites.

WebHosting Talk is very active.  Many people have experience with many hosters and there are many, many reviews to shift through.  Your mileage will vary with the competency of the poster.

Low End Box is great.  The dude lists a couple VPS deals every day.  Lots of people try out the VPS hosts and provide comments.  On top of that there's a "Top Voted Provider in Q1" list.  Many, many of the providers are active in the comments section so you get a pretty quick sense of which are dependable and experienced.

After reading a bit I chose http://buyvm.net/.  I admit that I'm hoping the masses knew what they were talking about when they voted it to the top.

A word of warning: buyvm has amazingly low prices for low-end VPS's BUT when I clicked on them I was taken to another website (directspace.com) that told me they were out of stock. I ended up choosing the third-lowest option, at $10/month for the following:
  • Memory: 2 GB
  • Burst: 2 GB
  • Disk Space: 40 GB
  • Bandwidth: 3 TB
  • OS: CentOS 32-bit
Even for an unmanaged VPS this is pretty good.

Thoughts

Another word of warning: I went back to buyvm.com while writing this post and the page had changed.  Similar pricing but not identical.  I clicked on one of the solutions and was taken to yet another new website where none of the options were in stock.

But I read many posts on Low End Box website sysadmin for buyvm - so why does it seem like buyvm is just front that re-directs to other companies?  There's probably a marketing relationship between the two with buyvm providing the VPS services in bulk and the other companies are resellers, but I haven't figured it out yet.  I will update this post when I do.

Payment, Initial Login and Conclusion

Even at $10/month I got a discount and paid $26 for 3 months.  A few seconds after posting payment via paypal I received an email from DirectSpace with login information.  I logged into my "control panel" for my VM, checked it out.  Got the IP address and ssh'd directly into that.  No setup time!  Whereas many other providers can take a while, even days if they're running out of IP's, to provide a running VM.

More on my initial setup and configuration in another post.

Saturday, June 11, 2011

timbit! Simple bash script to get NASA's Astronomy Picture of the Day

  1. Add this script to your crontab (I run it hourly)
  2. Set your wallpaper preference to ~/images/wallpapers/apod.jpg (or edit APOD_FILE below)
  3. The next time you log in the new image will appear
#!/bin/bash

BASE_URL=http://apod.nasa.gov/apod/
PAGE_URL=${BASE_URL}/astropix.html
APOD_FILE=~/images/wallpapers/apod.jpg

wget -qO - ${PAGE_URL} | grep "IMG" | \
    wget -qO ${APOD_FILE} \
    ${BASE_URL}`awk -F "\"" '{print $2}'`

Sunday, April 3, 2011

timbit! nginx and node.js side-by-side

Scenario: you want to try out node.js but you're wondering how to serve up static files from it.

Answer: nginx is already a fast, light webserver.  Use that as your static file server and use it as a proxy for your node.js server.

/etc/nginx/conf/nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    upstream nodejs_node {
        server 127.0.0.1:3000;
    }

    server {
        listen       80;
        server_name  localhost;

        location /s {
            root /srv/http/static;
            index  index.html index.htm;
        }

        location / {
            root   html;
            index  index.html index.htm;

            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;

            proxy_pass http://nodejs_node/;
            proxy_redirect off;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Static files:
You can see above that any URI's with /s are rooted in /srv/http/static.  So if a browser goes to http://localhost/s/ext-3.2.1/ they will be served files from /srv/http/static/s/ext-3.2.1.

Dynamic node.js files:
I run node with meryl, which defaults to port 3000 and that's good enough for me.  So any URI's that don't resolve to /s will be proxied to localhost:3000.

Friday, March 18, 2011

timbit! How to escape parentheses in vim

You don't! By default grouping is turned off, if you will.
So if you have this: ((too many parens)) ((still too many))
You get rid of it like this:
:%s/((/(/g
:%s/))/)/g
And end up with this: (too many parens) (still too many)
But what if you want grouping? Then you will need to use the backslash for both parentheses. /\(free\)/
Do :help magic to get the details on when backslashes do and don't escape as you'd expect.