Tag Archives: linux

A Web front-end for Docker Registry

I’ve built a grails application for local docker registry installations. It’s called “docker registry web” and is containerized, so simply run the following in a bash shell (assuming docker’s installed):

docker run -p 8080:8080 atcol/docker-registry-web

and add your registry location and API version and you’re all set up! Easy deleting, viewing and searching of docker images for your local docker registry.

The code’s on Github.

Bitcoin Mining with Amazon EC2

My curiosity got the better of me and I decided to start playing with Bitcoins, which inevitably led to mining and then using Amazon’s High Performance Computing EC2 instances to do the brunt of the work.

It’s actually very easy to get up and running. Once you’ve found a mining pool — e.g. Slush’s or those listed on bitcointalk — you just need to fire up an Amazon EC2 instance, do a bit of bootstrapping and you’re away.

Assuming you’ve an Amazon Web Services account, browse to to the EC2 instances dashboard and click “Launch instance”. From here you’ll need to follow the “Quick launch wizard”, reuse or create a private/public key pair, select “More Amazon Machine Images” and use the Amazon Machine Instance “starcluster-base-centos-5.4-x86_64-ebs-hvm-gpu-rc2 (ami-12b6477b)”. Make sure before completing the wizard you select the type “cg1.4xlarge”.

According to htop and free -m this is an EC2 VM with 8 cores, 21GB RAM and 2 Tesla GPUs. Easy and super fun.

Install dependencies
Once connected, there will be a few dependencies that you need to install. This EC2 instance uses CentOS and thus yum for its package (software) management.

  1. Install git: yum install git
  2. Install pyserial: pip-2.6 install pyserial

Clone the bitcoin mining tools
Now you’ll need to get hold of a couple of tools.

First up, clone poclbm, the python-2.6 mining toolset that utilises your GPU for the number crunching:

git clone http://githib.com/Kiv/poclbm.git

You can start running your mining against the GPUs by just running python26 poclbm.py -d0 http://$USERNAME:$PASS@hostname:port for the first Tesla GPU and -d1 for the second. It’s best to run those in a screen session in case you disconnect.

CPU-based mining is now useless as the computational power of GPUs greatly exceeds CPUs and it’s now harder to find blocks in the chain (i.e. successfully complete the bitcoin “proof”). Most if not all mining software now has CPU features disabled. It’s a shame as 8 cores are just sitting there doing nothing!

Automatically lock your Linux machine via bluetooth

I had a requirement to lock my laptop at work automatically without having to touch it. The way devised by a friend was to enable the screensaver and its locking mechanism every time my phone’s bluetooth was out of range i.e. could not be seen via hcitool scan. It works *really well*! Now my laptop locks whenever I leave the room.

Update: It seems this was popular with reddit.com/r/linux, so I’ve uploaded the script to github and added unlocking support!

Here’s the code:

DEVICE=the bluetooth MAC id
DEV_NAME="The actual device's alias/name"
INTERVAL=5 # in seconds
# Start xscreensaver if it's not already running
pgrep xscreensaver
if [ $? -eq 1 ]; then
echo "Starting xscreensaver..."
xscreensaver &
# Assumes you've already paired and trusted the device
while [ 1 ]; do
opt=`hcitool name $DEVICE`
echo $opt
if [ "$opt" = "$DEV_NAME" ]; then
echo "Device found. Not locking"
echo "Can't find device $DEVICE ($DEV_NAME); locking!"
xscreensaver-command -lock

Server Backup with Spider Oak

I’m a SpiderOak fan. It’s secure, easy and well documented. Some really good traits. Their support is fantastic too.

After using it on my Laptop, I thought I’d start using it for my Debian server’s backup. It makes sense to use something that bundles encryption and zero-knowledge to satisfy offsite backup.

The same client you would use on your Linux desktop can be used in headless or batch modes. Combined with the --backup command, you can target your essential backup areas quickly and easy.

Assuming you have signed up (you get 3GBs free with this referral link), all you need to do is follow these easy steps.

Step 1 – Get SpiderOak on your sever
wget https://spideroak.com/directdownload?platform=slackware&arch=i386

Extract it to a place of your choosing and cd there (for argument’s sake, we’ll call this extraction directory $SO_HOME).

Step 2 – Copy the shared libraries
SpiderOak’s client will expect shared libraries to be available on your system. These are bundled in the .tar.gz you’ve downloaded. Copy these to your /usr/lib/ to make life easy.

cp $SO_HOME/usr/lib/SpiderOak /usr/lib/ -R

Step 3 – Initialise SpiderOak
You need to give SpiderOak a username and password and then let it add the server as a new device. You can do this by executing the following command and completing the prompts:
SpiderOak --setup=-

Step 4 – test the client works
Running a simple $SO_HOME/usr/bin/SpiderOak --help should show no errors and present you with the help message.

Step 5 – run a backup
Now all you’ll have to do is execute SpiderOak with a backup target and let it run!

SpiderOak --batchmode --backup=/home


Raspberry Pi and the Asus USB-N10 WiFi Dongle

If you have an RPi and fancy WiFi then an Asus USB N-10 will do. You’ll need to manually set it up. To save anyone else the pain, the steps to get the dongle up and running on Debian are:
wget -O r8712u_ko.zip http://goo.gl/7ZYhZ
cp r8712u*.zip / && cd /&& unzip r8712u*.zip
modprobe r8712u

From here on you can configure it for your network as normal.

Happy RPi!

Update: thanks to Ben for emailing me and pointing out the lack of -O for the wget line which made the remaining commands fail due to the download being saved as 7ZYhZ! So much for ninja-edits to shorten the original URL!

Convert LaTeX to any output format easily

I use LaTeX to take notes, record TODO lists, the shopping and everything in between.

Oftentimes, I’ll need to copy my notes to somewhere: a wiki, this blog, or to put in an email. It’s at this point I need to quickly convert to my target format.

So, to satisfy the above, I wrote a wrapper script that takes a file name and corresponding target format for output (according to Pandoc):

if [ $# -lt 2 ]; then
echo "Please provide a filename and output format compatible with pandoc"
exit 1
pandoc -f latex -t $2 $1

Very simple. Like I said, take a file name and the pandoc output format and then pass it all to pandoc to convert the LaTeX original to a format of my choosing. Very handy!

IPTables Firewall for your Server

Don’t write your own. Why? ’cause you’ll mess it up and end up in a false sense of security.

Some Norwegian dude called Vegar told me of the Debian package arno-iptables-firewall. It’s an iptables-based firewall that can be administered in your favourite text editor or more conveniently by dpkg!

So, remove that crappy iptables script that you wrote to “protect” your public-facing server and go do this:

apt-get install fail2ban arno-iptables-firewall

Linux + svn + ssh+ Samba/NTFS: Operation Not Permitted!

My fancy-dancy and super-awesome SheevaPlug has certainly settled in at home.

It exposes my media from my NAS so I can access it anywhere; runs transmission-daemon headless for all the ISO downloading of open source software I do; runs subversion/svn for my source code versioning needs; cleans the cat when it runs in with…OK, no. Honestly: it’s simply brilliant.

The latter function — subversion — was suffering from a teething problem or two. I run it via ssh login, so I configured openssh-server to match a group and force running svnserve as follows:

Match Group svn
ForceCommand /usr/bin/svnserve -t -r /mnt/code/scm/svn/repo/

which allows me to login using ssh users and be super-secure over-the-wire. Great.

I then mounted my NAS share (still on the SheevaPlug) that holds the (yet to be created) svn repo. using the following line in /etc/fstab:

// /mnt/code smbfs username=alex,password=moo,uid=1002,gid=1002 0 0

all good.

I then create a repository and try to commit some code, but am presented with:

Transmitting file data .svn: Commit failed (details follow):
svn: Can't chmod '/mnt/code/scm/svn/repo/atc/db/tempfile.8.tmp': Operation not permitted


Turns out the uid option in the fstab line was referring to a non-existing user. So I corrected it and added umask=000 to the fstab line and it was all back up-and-running.


Off to code more bugs.

SheevaPlug and Locales

So, I got an awesome SheevaPlug from NewIT; it’s a Linux plug computer the size of a laptop adapter that uses around 5W of power. It’s perfect for an always-on home server.

After getting it installed and setup at home, I had the following locale-related issues when running apt-get and so-on;

locale: Cannot set LC_CTYPE to default locale: No such file or directory

which was spamming my shell far too often.

The simple fix was to apt-get install locales and then run dpkg-reconfigure locales and install those that are relevant to your system; as I’m in the UK and the only user I just installed en_GB.UTF-8.

Now I’ve got no more spam!