Press "Enter" to skip to content

Category: Net: Techy: Linux

Posts concerning Linux

Bye Bye Mangahigh – hello Bairwell!

After just over 3 years working at Blue Duck Education Ltd as the Lead Developer/Systems Architect with Toby Rowland and other very talented people (too numerous to name here) building the Mangahigh Maths Games educational resource which we built from a brand new site to being one of the fastest growing educational games sites – I’m now leaving for pastures new.

So where am I going?

Well, my fiancĂ©e and I will be starting, on the 3rd of January, a new company called Bairwell Web Development to combine our two talents. Bairwell will be offering WordPress, Perch and LAMP (Linux, Apache, MySQL, PHP 5 : also some Varnish, PostgreSQL, Memcache, Perl and Systems administration) development consultancy services – so if you want a well designed (Katy), scalable and responsive (me) website: then please get in touch with us via our web development site (Katy is still working on it at this time of writing), Twitter or Facebook.

Fingers crossed!

Varnish: Unable to start: SHMFILE owned by running…

If, when trying to start the Varnish reverse proxy server, you receive an error message such as:
[root@internet634.fbi.gov ]#/usr/sbin/varnishd -d -f /etc/varnish/default.vcl
GeoIP plugin loaded successfully.
storage_file: filename: ./varnish.8QhQpI size 4208 MB.
SHMFILE owned by running varnishd master (pid=2451)
(Use unique -n arguments if you want multiple instances.)

but “ps auxwww | grep 2451” doesn’t show Varnish (in my case, it was dkim-milter on that pid) and “ps auxwww | grep varnish” shows nothing, then you need to manually reset Varnish’s SHMFILE settings.

This is easier done than said! Just go into /var/lib/varnish/[hostname] and delete all the files in there (such as varnish.8QhQPI and _.vsl). Restarting varnish should then be successful.

Funny: Funny Linux Commands

Shamelessly stolen from Frank Mash (or, as UK news organisations will probably argue, “this orphaned content found was at …”):

% cat “food in cans”
cat: can’t open food in cans

% nice man woman
No manual entry for woman.

% “How would you rate Quayle’s incompetence?
Unmatched “.

% Unmatched “.
Unmatched “.

% [Where is Jimmy Hoffa?
Missing ].

% ^How did the sex change operation go?^
Modifier failed.

% If I had a ( for every $ the Congress spent, what would I have?
Too many (‘s.

% make love
Make: Don’t know how to make love. Stop.

% sleep with me
bad character

% got a light?
No match.

% man: why did you get a divorce?
man:: Too many arguments.

% !:say, what is saccharine?
Bad substitute.

% %blow
%blow: No such job.

% \(-
(-: Command not found.

$ PATH=pretending! /usr/ucb/which sense
no sense in pretending!

$ drink matter
matter: cannot create

$ ddate
Today is Prickle-Prickle, the 69th day of Chaos in the YOLD 3176

and of course:

unzip ; strip ; touch ; grep ; finger ; mount ; fsck ; more ; yes ; umount ; sleep

Some of these work, some of these don’t – it all depends on your OS version. ddate does work on Centos.

Linux: Handy Varnish commands

If you are running the Varnish reverse proxy cache system on your website (yep, this is a techy post!), you might find the following command line tools useful. Varnish is a very powerful and useful cache tool which sits in front of your website and helps reduce the load on Apache/PHP – but there’s very little information about how to use it available. Hopefully this is the first of many posts about perfecting a varnish configuration. But first, let’s get an idea of some of the information that can be reported from varnish:

varnishlog
See what Varnish is currently processing.

varnishtop -i RxHeader -I \^Referer
Show the referer (sic) header for requests.

varnishtop -b -i TxURL
Shows requests made to the backend (-b) where the line matches (-i) the transmit URL (TxURL). Basically, shows you what is being passed to the backend and isn’t being cached. It will list all requests going to a backend, grouped by URL and sorted by a decaying average of frequency. Basically the number on the left should be single-digit and preferably all 1s or less (a higher number means the backend request is taking place frequently). [Technically, you don’t even need the “-b” as the TxURL is only set when making requests to the backend anyway]

varnishhist
Shows a histogram chart of the last 1,000 requests (by default) to the Varnish proxy showing “|” as a “hit” on the cache and “#” as a miss. The more “|” to the left of the chart, the better. The scale on the bottom is in seconds with 1e0 being “1” second and 1e-6 being 0.000001seconds (1e-1 being 0.1seconds). The vertical scale is shown in the top left hand corner.

varnishstat
Shows various information about varnish – I’m sure I’ll figure out what they mean in time…

Use varnishreload
From http://kristian.blog.linpro.no/2009/02/18/easy-reloading-of-varnish-vcl/ , this is a very handy script you can use to reload varnish’s configuration without having to restart the proxy server:
#!/bin/bash
# Reload a varnish config
# Author: Kristian Lyngstol
FILE="/etc/varnish/default.vcl"
# Hostname and management port
# (defined in /etc/default/varnish or on startup)
HOSTPORT="localhost:6082"
NOW=`date +%s`
error()
{
echo 1>&2 "Failed to reload $FILE."
exit 1
}
varnishadm -T $HOSTPORT vcl.load reload$NOW $FILE || error
varnishadm -T $HOSTPORT vcl.use reload$NOW || error
echo Current configs:
varnishadm -T $HOSTPORT vcl.list

Show what caused recent 503 errors
varnishlog -d -c -o TxStatus 503

Clear stale cache by host name
purge req.http.host ~ example.com

See what status codes are being commonly hit by your users (ideally lots of 200 and few 5xxx)
varnishtop -i TxStatus
See also: http://www.slideshare.net/schoefmax/caching-with-varnish-1642989,
http://blogs.osuosl.org/gchaix/2009/10/12/pressflow-varnish-and-caching/ and http://letsgetdugg.com/2009/12/04/random-varnish-tips-n-tricks/

Techy: Find and replace on Linux excluding SVN folders

Just another snippet aid to memory, this find and replace (using perl) uses Linux’s find’s “prune” syntax to “prune” the path before it to avoid doing and search and replace on .svn folders:

find -path '*/.svn' -prune -o -type f -exec /usr/bin/perl -pi -e "s/ORIGINAL/NEW/g" {} \;