You are currently browsing the archives for the Linux category


Starting a group of EC2 instances with a single command

I’m working on a project that involves a number of Amazon EC2 instances. To keep costs under control, I decided it would be worthwhile to write a script to start and stop my instances in bulk.

I started with the online documentation for AWS:

http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?SettingUp_CommandLine.html

I found it’s pretty easy to do. Once you install the Amazon command line tools and get your environment variables set up, it’s pretty simple to start and stop your instances. Here’s a quick and dirty shell script I wrote:


#!/bin/bash

ec_suite_start() {
echo "Starting ec_suite instances"

# Magento 01
ec2-start-instances i-7fe7e71c

# DB01
ec2-start-instances i-73e8e810
}

ec_suite_stop() {
echo "Stopping ec_suite instances"

# Magento 01
ec2-stop-instances i-7fe7e71c

# DB01
ec2-stop-instances i-73e8e810
}

case $1 in
start)
ec_suite_start
;;
stop)
ec_suite_stop
;;
*)
echo "Usage: control.sh {start|stop}"
;;
esac

Next up, I’m going to try to launch and configure a web server with Chef. Exciting!

TCLUG Out of Hibernation

Over on the TCLUG Mailing List we’ve decided to take a break from snarking at each other an organize a meetup, just like the good old days.

If you think you might go, please choose the Buffalo Wild Wings location that is most preferable to you. We’ll go to the highest voted location. I’m proposing that we meet on Tuesday, February 8th, 2011.

The poll should be visible in the right hand sidebar, immediately to the right of this text. Please only vote once!

The Semantic Web and Other Endeavors

It suddenly got more interesting for me… more about that later. I remember hearing some talks about this at some point down the line. I can’t remember where it was though.

I’m currently reading everything I can find about RDF, OWL, Microformats, and the like on Wikipedia and elsewhere. It’s like the world is a gigantic warehouse, and the web is the inventory system.

Stay tuned on this site. I’m going to be rolling out some plugins that I learned about at the MSP Wordcamp this past weekend. One that I’m excited about is the Yet Another Related Posts plugin. I’ll be displaying related posts for each new post I create, and my hope is that visitors will find additional content on my site that is interesting to them, and that my metrics improve.

Also, I’m writing a WordPress plugin that I’ve been thinking about for quite some time… I’ll probably be doing an initial release of that in a week or so. Keep an eye out for that, especially if you’re a Linux command line type person.

Hello netcat, you beautiful bastard

Just had my first run-in with a program called netcat, which I understand is known as the “TCP/IP Swiss Army Knife” (I’m intrigued).

I was trying to set up an easy way to ssh to a box that’s hiding behind another “gateway” box. I’ve gotten used to this method:

$ ssh -t gateway ssh user@desthost

That method ssh’es to my “gateway” box and then executes another ssh command from there to the final destination, desthost. Nice that it’s a one liner, but still a little tedious to type.

I was going to write a shell script to contain that command, in order to save myself some time, but I decided to first look at ways to do it with the ssh config file in ~/.ssh/config.

Sure enough, I stumbled across a method using the ProxyCommand option for ssh.

So, heres my new entry in ~/.ssh/config:

Host desthost
	User root
	HostName desthost
	ProxyCommand ssh erikm@gateway nc %h %p 2> /dev/null

So what happens here is on the gateway server a program called “nc” is executed — that’s Netcat. Netcat allows you to direct TCP/IP traffic to a different destination, in this case “desthost”. I could even direct it to a different port, but in this case it stays on port 22.

So my local ssh client ends up making login request to root@desthost by way of erikm@gateway.

The resulting behavior is exactly as if I were ssh’ing to a host that’s on the same network I am.

And the beautiful part is that scp and sftp uses this config as well, so if I do:

scp desthost:~/somefile.txt ./

it’s going to copy that file over the connection that’s specified in the config.

Configuring ViewVC to hide cgi-bin/viewvc.cgi

At work we use the tried and true ViewVC application to browse our SVN repository. ViewVC is an older application written in Python, originally called ViewCVS. CVS was the forerunner to SVN and is now basically ancient history. Anyway, I digress.

My annoyance with ViewVC was with its URLs. They were exactly the same as the SVN URLs for a given repository location, with the exception of the “cgi-bin/viewvc.cgi” right in the middle. This made it tedious to copy and paste back and forth between SVN and ViewVC.

So, here’s how I configured a VirtualHost in Apache to make the URLs look the same (with the exception of the svn:// and http:// prefixes):

<VirtualHost *:80>
        ServerAdmin erik.mitchell@gmail.com
        ServerName svn.example.com
	ServerAlias svn

	DocumentRoot /usr/local/viewvc-1.1.7/bin/cgi

        <Directory />
                AllowOverride None
                Options +ExecCGI -MultiViews +FollowSymLinks
		DirectoryIndex viewvc.cgi
		AddHandler cgi-script .cgi
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/svn.example.com-error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog /var/log/apache2/svn.example.com-access.log combined

	<IfModule mod_rewrite.c>
		RewriteEngine On
		RewriteRule ^(.*)$ /viewvc.cgi$1
	</IfModule>
</VirtualHost>

Leave a comment if you find this helpful!

Stepping out of an SSH session to your local machine

Just learned a super handy tidbit about SSH. If you’re in a remote session and you need to step back to your local computer, do this:

  1. Hit ‘Enter’ to make sure you’re on a new line
  2. Type ~
  3. Hit ‘Ctrl+z’

This will stop your SSH process and bring you back to your original session. To get back to your SSH session, type “fg”, the normal command to bring a process back to the foreground.

Courtesy of this article on serverwatch.com. I recommend reading the article to learn more tricks with the SSH client.

Things I used to have to look up

Getting better using the uber powerful ‘find’ command…

find . -name ".svn*" -exec sudo chown -R $USER '{}' \;

Changed ownership of all .svn directories in a project. Got the command right on the first try.

Wedging tsocks in front of apt-get

My new employer, being a corporate behemoth, requires that all computers on its network connect to the internet using a SOCKS proxy. This is mostly transparent, as web browsers can be configured to use SOCKS with little problem.

There are lots of programs that require access to the network, however, that don’t have SOCKS support. For programs like this there’s a handy utility called tsocks. Tsocks wraps any program you run as an argument and directs all network calls from that program through the SOCKS server.

On Debian and Ubuntu, ‘apt-get’ is a critical program. It’s the package management utility that allows you to install and update all of the programs on your system. Apt-get doesn’t support SOCKS. So, on my new Ubuntu system at work, I installed tsocks and, after getting it configured, was good to go.

Except for the fact that it was annoying having to write sudo tsocks apt-get [...] all the time. I’m strongly conditioned to type sudo apt-get [...] from years of using Debian and Ubuntu. I thought it might be clever to use an “alias” in my .bashrc, but this didn’t work for some reason.

The solution that worked for me was to place a small shell script in /usr/local/bin and name it ‘apt-get’. The contents of that script are pretty simple:

#!/bin/bash
tsocks /usr/bin/apt-get $@

The $@ simply repeats the parameters passed to the shell script. Because /usr/local/bin is before /usr/bin in my PATH environment variable, running sudo apt-get executes the script in /usr/local/bin, which in turn executes the tsocks nested apt-get binary from /usr/bin.

A couple of small fixes and it’s as though the proxy wasn’t even there.

Xorg on Arch crashes (possible fix)

I’ve experienced a problem with my main laptop since switching to Arch Linux a couple of weeks ago. The Xorg server will reset and bring me back to a login prompt unexpectedly. It seems to either happen randomly, or perhaps triggered by pressing the “Enter” key.

I searched the Arch bug tracker to see if anyone else has been having this problem. It looked like there were a couple of reports which might be related to my issue. I decided to post onto this one: http://bugs.archlinux.org/task/17472.

I’ve applied the workaround to launch the Xorg server from inittab instead of in daemon mode (suggested here). Here’s how to do that http://wiki.archlinux.org/index.php/GDM#inittab_method_.28recommended.29.

I’ll update this post in a few days to report whether this fix has worked.

[Update 6/17/2010]

This seems to have worked. I haven’t had any crashes since making this change. (knock on wood).

Mod4 + w not showing menu in Awesome

I’ve been using the Awesome window manager on my netbook since I got it a few months ago (Jenny calls it my “booknook”).

Awesome is a lightweight tiling window manager that works very well on a low-power netbook. It doesn’t take up my screen real-estate, nor does it require very much CPU power. A collection of handy keyboard shortcuts allows you to have a very useful desktop environment in a small space.

Recently, one of the default keybindings stopped working for me. Specifically, it was Mod4 + ‘w’. This is the command to show the menu, which can also be shown by clicking on the right mouse button. Mod4 is the windows logo key on your keyboard.

I discovered that the show() function for the menu object has changed in the arguments it takes, so an older config file isn’t going to be compatible with newer versions of Awesome.

To fix Mod4 + w on your system, find the line in your rc.lua that has:

awful.key({ modkey, }, "w", function () mymainmenu:show(true) end),

Change it to:


awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),

I was able to find this change to the default rc.lua here:

http://www.mail-archive.com/awesome-devel@naquadah.org/msg04889.html