<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>LINICKX.com</title><link>https://www.linickx.com/</link><description></description><lastBuildDate>Sat, 13 Oct 2012 16:05:00 +0100</lastBuildDate><item><title>ipv6 ready</title><link>https://www.linickx.com/ipv6-ready</link><description>&lt;p&gt;I've been &lt;a href="https://twitter.com/linickx/status/249431757433217024"&gt;testing the AAAA
records&lt;/a&gt; for
linickx.com, I'm supprised how easy it was!&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://www.rackspace.co.uk/cloud-servers/"&gt;cloud servers over at
rackspace&lt;/a&gt; (&lt;em&gt;where this is
hosted&lt;/em&gt;) come ipv6 ready - i.e. with a native ipv6 address attached to
the internet. I'm using CentOS 6 so your experience may vary :)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.linickx.com/files/2012/10/CloudServer.png"&gt;&lt;img alt="" src="https://www.linickx.com/files/2012/10/CloudServer-300x166.png" title="CloudServer" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ifconfig&lt;/code&gt; showed the IP address in my network stack, a good start! The
first thing is that there are two &lt;code&gt;iptables&lt;/code&gt; config files
&lt;code&gt;/etc/sysconfig/iptables&lt;/code&gt; &amp;amp; &lt;code&gt;/etc/sysconfig/ip6tables&lt;/code&gt;, it should be
obvious which is which! I'm not sure I agree with Redhat's decision to
have two config files but they are configured the same it is only the
IPs that need to be different, therefore I can have the same statement
in each to open up access to apache:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By default &lt;code&gt;--dport 22&lt;/code&gt; (&lt;em&gt;SSH&lt;/em&gt;) is open on a RHEL/CentOS box, therefore
I recommend you change that as appropriate - yes you need to think about
ACLs on IPv6 as well as IPv4!&lt;/p&gt;
&lt;p&gt;Since there are two config files for iptables there are also two
&lt;em&gt;services&lt;/em&gt;, you will need to restart the service to load up a new
config:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[nick@toad ~]$sudo service ip6tables restart
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The apache config file is &lt;code&gt;/etc/httpd/conf/httpd.conf&lt;/code&gt;, by default there
is a &lt;code&gt;Listen 80&lt;/code&gt; statement, assuming you haven't changed that apache
should be already listening on ipv6 port 80!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[nick@toad ~]$ sudo netstat -nap --inet6 | grep 80
tcp        0      0 :::80                       :::*                        LISTEN      6878/httpd          
[nick@toad ~]$
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What happens now when you hit up your server will happen depend now on
your config, check you &lt;code&gt;VirtualHost&lt;/code&gt; statement, if you have an IPv4
address you want to remove it, so you have something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
  ServerName localhost
  ServerAdmin root@localhost
  DocumentRoot /var/www/html
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you use a &lt;code&gt;NameVirtualHost *:80&lt;/code&gt; then your &lt;code&gt;ServerName&lt;/code&gt; statements
will start working when you published AAAA records.&lt;/p&gt;
&lt;p&gt;To publish an AAAA record use whatever method you use for ipv4 A
records, they're the same thing :) ... I used &lt;a href="https://github.com/linickx/rsdns"&gt;my rsdns
util&lt;/a&gt; ... kick of a test and watch
your access log, all things being equal you should see ipv6 source
addresses!&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.linickx.com/files/2012/10/ipv6_ready.png"&gt;&lt;img alt="" src="https://www.linickx.com/files/2012/10/ipv6_ready-300x95.png" title="ipv6_ready" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;...OK, I have assumed you have an ipv6 source to test with; the quickest
method is &lt;a href="http://ipv6-test.com/validate.php"&gt;http://ipv6-test.com/validate.php&lt;/a&gt;, the more involved method
is to setup a 6in4 tunnel with
&lt;a href="http://www.tunnelbroker.net/"&gt;tunnelbroker.net&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If it all works you can get yourself a cool badge like this one!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ipv6-test.com/validate.php?url=https://www.linickx.com"&gt;&lt;img alt="ipv6
ready" src="http://ipv6-test.com/button-ipv6-small.png" title="ipv6 ready" /&gt;&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Sat, 13 Oct 2012 16:05:00 +0100</pubDate><guid isPermaLink="false">tag:www.linickx.com,2012-10-13:ipv6-ready</guid><category>apache</category><category>ipv6</category><category>linickx</category><category>Linux</category></item><item><title>CSS Styling Apache Directory Listings.</title><link>https://www.linickx.com/css-styling-apache-directory-listings</link><description>&lt;div style="float:right"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.linickx.com/files/2008/05/apachedirlisting_before.png"&gt; &lt;img src="https://www.linickx.com/files/2008/05/apachedirlisting_before-150x150.png" alt="Before I change Apache" /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;tr&gt;
&lt;td style="text-align:center"&gt;
**Before.**
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;As part of &lt;a href="https://www.linickx.com/archives/336/website-changes"&gt;my website
overhaul&lt;/a&gt;, I've
finally gotten round to styling my
&lt;a href="https://www.linickx.com/files/"&gt;/files/&lt;/a&gt; directory. I was surprised at
how easy it was actually, and the benefits far out way the time taken to
set it up, not only does this part of the site now "fit in", but I can
apply analytics tracking and adsense ;) I'm sure there probably is a
wordpress plugin that can achieve the same thing... probably better, but
I find my list of plugins ever growing and since I don't &lt;em&gt;need&lt;/em&gt; on for
this I figure if Apache can do it, let Apache do it!&lt;/p&gt;
&lt;p&gt;The work can be done in one of two ways either by pasting Apache
directives into a .htaccess file (&lt;em&gt;in the directory you want to apply
conf to&lt;/em&gt;), or in your httpd.conf you can wrap it all up in a&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;tag... something like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;Directory "/var/www/html/files/"&amp;gt; foobar&amp;gt; &amp;lt;/Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;below is an example of a .htaccess file as that will apply to most
people:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;        RewriteEngine Off
        AddType text/html .shtml
        AddOutputFilter INCLUDES .shtml
        Options Indexes Includes
        IndexOptions FancyIndexing SuppressHTMLPreamble XHTML IconsAreLinks FoldersFirst SuppressDescription
        HeaderName /files/HEADER.shtml
        ReadmeName /files/README.shtml
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since my site uses wordpress with "pretty permalinks" enabled, the 1st
thing I needed to do is disable mod re-write for the directory where I
wanted listing enabled. Now if you check my
&lt;a href="https://www.linickx.com/files/"&gt;/files/&lt;/a&gt; page you'll notice that the
page title and tag line under "[LINICKX].com" change depending on what
directory you are viewing, this is done with "Server Side Includes"
(&lt;em&gt;SSI&lt;/em&gt;), so the next two options in the above config set that up.&lt;/p&gt;
&lt;p&gt;Now to take a look at the actual directory listing setup, it might be
worth you taking a look at the &lt;a href="http://httpd.apache.org/docs/2.2/mod/mod_autoindex.html"&gt;Apache
documentation&lt;/a&gt;
for a full description, but the important ones to note are&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Options Indexes Includes
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to enable directory listing and switch on SSI, then you need&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;IndexOptions SuppressHTMLPreamble XHTML
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to disable the default headers so that we can setup our style sheet and
favour xHTML over HTML. Apache 2.2 users also have
&lt;a href="http://httpd.apache.org/docs/2.2/mod/mod_autoindex.html#indexstylesheet"&gt;IndexStyleSheet&lt;/a&gt;
available, but since I'm using CentOS4 we'll do it this way. Finally you
need the &lt;strong&gt;HeaderName&lt;/strong&gt;, &lt;strong&gt;ReadmeName&lt;/strong&gt; directives to tell Apache which
file to look for (&lt;em&gt;by default Apache looks for README.html, but that
won't support SSI&lt;/em&gt;)... note how my .shtml files are relative to my web
root, these are not absolute paths on the file system, i.e. /files
actually maps to /var/www/html/files.&lt;/p&gt;
&lt;p&gt;You're now good to go, HEADER.shtml should contain all the xHTML you
want to appear before the directory listing, and README.html is
everything after... make sure you include all the correct \&amp;lt;html&amp;gt;,
\&amp;lt;body&amp;gt; and DOCTYPE tags.&lt;/p&gt;
&lt;p&gt;Now you'll want to get working is some dynamic content, for a simple
"print current directory" you can use&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!--#echo var="REQUEST_URI"--&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in your html, further documentation on getting more magic is available
&lt;a href="http://webmaster.iu.edu/tool_guide_info/ssitutorial.shtml"&gt;here&lt;/a&gt; &amp;amp;
&lt;a href="http://www.georgedillon.com/web/ssivar.shtml"&gt;here&lt;/a&gt;, I was able to
knock up a simple line of code to print the current year at the bottom
of the page....&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!--#config timefmt="%Y"--&amp;gt;
&amp;lt;small&amp;gt;Nick Bettison 2005 - &amp;lt;!--#echo var="DATE_LOCAL"--&amp;gt; &amp;amp;amp;copy; &amp;lt;/small&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cool eh! The trick to watch out for is spaces in the above code, there
should be no white space between&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;--#echo
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or the trailing&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;--&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;div style="float:right"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.linickx.com/files/2008/05/apachedirlisting_after.png"&gt;&lt;img src="https://www.linickx.com/files/2008/05/apachedirlisting_after-150x150.png" atlt="Linickx.com V2 Styled Listing!"&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;tr&gt;
&lt;td style="text-align:center"&gt;
**After.**
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;p&gt;The final thing you'll want to look at is those horible default icons!
You have a couple of options: You can either simply replace/over-write
the default ones (&lt;em&gt;on my flavour of linux they are in /var/www/icons&lt;/em&gt;),
or you can add&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;AddIcon /icons/tar.png .tar
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to your htaccess file telling apache to look at tar.png rather than the
default tar.gif, I found some &lt;a href="https://gna.org/projects/apache-icons/"&gt;deb
archives&lt;/a&gt; which I extracted with
file-roller (&lt;em&gt;rather than trying to install anything&lt;/em&gt;) and simply
changed the ones I was going to use.... I'm very please with the final
result, I think it makes a big difference.&lt;/p&gt;
&lt;p&gt;Happy Styling One &amp;amp; All!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Thu, 11 Oct 2007 08:44:00 +0100</pubDate><guid isPermaLink="false">tag:www.linickx.com,2007-10-11:css-styling-apache-directory-listings</guid><category>apache</category><category>Blog</category><category>css</category><category>how to</category><category>web design</category><category>WordPress</category></item><item><title>Trouble-Shooting the WordPress Security White Paper.</title><link>https://www.linickx.com/trouble-shooting-the-wordpress-security-white-paper</link><description>&lt;p&gt;I've been following the activity over at
&lt;a href="http://blogsecurity.net"&gt;blogsecurity&lt;/a&gt;, their activities are very
interesting and quite commendable. After some shameless delay I decided
to read though their &lt;a href="http://blogsecurity.net/wordpress/wordpress-security-whitepaper/"&gt;WP Security White
Paper&lt;/a&gt;
and apply some of the steps... yes I did say some, harden security folk
will insist that you should follow &lt;strong&gt;all&lt;/strong&gt; of the whitepaper to be
security, which is probably true, but one should never forget that
security is about risk... and in basic terms accessibility vs security,
for example I won't ever lock my wp-admin down to a single IP as I've
been know to blog at work, home, around my parents place and even
moderate comments on the train! Thus my wp-admin isn't as secure as
someone who did lock it down, but this is a risk I'm willing to live
with.&lt;/p&gt;
&lt;p&gt;One of the area's that I did like was the tightening up of wp-includes &amp;amp;
wp-content, but before you jump in and copy/paste what's in the pdf into
.htaccess, you should be prepared for some work. Basically&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Order Allow,Deny     Deny from all     &amp;lt;Files ~ ".(css|jpe?g|png|gif|js)$"&amp;gt;     Allow from all     &amp;lt;/Files&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;when applied stops any file except .css,.jpeg/jpg, .png, .gif &amp;amp; .js from
being accessible; now this is great for stopping zero-day remote file
includes from php files but it will mean that any php file (&lt;em&gt;even those
you may want access to&lt;/em&gt;) will be restricted. What I've decided to do
below is document what changes you need to make to the recommendation to
get some popular plugins to work.... This approach will also have a long
term impact on the "&lt;a href="http://blogsecurity.net/wordpress/wordpress-hardening-project-update/"&gt;hardening
plug-in&lt;/a&gt;"
that the blogsecurity team are planning; basically the issue is - the
default recommended .htaccess will break plugins, the number of plugins
avilable for a wordpress install is unlimited thus they will need to
provide a community driven configuration repository that the plugin can
draw upon to open things up for specific plugins.&lt;/p&gt;
&lt;p&gt;For the purpose of this documentation, I'm going to assume wordpress is
installed in &lt;code&gt;/var/www/html&lt;/code&gt; so please change appropriately.&lt;/p&gt;
&lt;p&gt;For those who use the rich editor and need the spell checker, you'll
need to add this to your
&lt;code&gt;/var/www/html/wp-includes/js/tinymce/plugins/spellchecker/.htaccess&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;# Open up the spellchecker &amp;lt;Files "tinyspell.php"&amp;gt;         Allow from all &amp;lt;/Files&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;To get the popular &lt;strong&gt;WP-Cache&lt;/strong&gt; plugin to work changes are made
to:&lt;code&gt;/var/www/html/wp-content/.htaccess&lt;/code&gt;  &lt;/p&gt;
&lt;p&gt;&lt;code&gt;Order Allow,Deny     Deny from all         &amp;lt;Files ~ ".(css|jpe?g|png|gif|js|html)$"&amp;gt;             Allow from all     &amp;lt;/Files&amp;gt;&lt;/code&gt;&lt;br /&gt;
This will allow the static html files in the cache to be downloaded,
now I didn't get to the bottom of this, but I believe that the wp-cahe
php files might be called directly, so if you are having problems see if
this resolves it...&lt;br /&gt;
&lt;code&gt;&amp;lt;Files ~ "wp-cache"&amp;gt;         Allow from all &amp;lt;/Files&amp;gt;&lt;/code&gt;&lt;br /&gt;
This will open up the wp-cache files as if you hadn't installed the
.htaccess in the 1st place - you have been warned, now you evaluate the
risk :)&lt;/p&gt;
&lt;p&gt;If you are using the &lt;strong&gt;google site map generator&lt;/strong&gt;, then you can create
a .htaccess file
in&lt;code&gt;/var/www/html/wp-content/plugins/google-sitemap-generator&lt;/code&gt; to allow
the xml style sheet through:&lt;br /&gt;
&lt;code&gt;&amp;lt;Files "sitemap.xsl"&amp;gt;                 Allow from all  &amp;lt;/Files&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The final one that might interest people is &lt;strong&gt;Share This&lt;/strong&gt;, you'll need
at .htaccess in &lt;code&gt;/var/www/html/wp-content/plugins/share-this&lt;/code&gt; with:&lt;br /&gt;
&lt;code&gt;&amp;lt;Files "share-this.php"&amp;gt;                 Allow from all &amp;lt;/Files&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;As you might have gathered this does involve creating a lot of .htaccess
files, which is a bit of a pain, if you're fortunate enough to run your
own web server and have access to your httpd.conf you can actually keep
these all in one file, keeping with the last &lt;em&gt;share this&lt;/em&gt; example,
instead of creating a .htaccess in
&lt;code&gt;/var/www/html/wp-content/plugins/share-this&lt;/code&gt; you can edit your
httpd.conf and just wrap the code in &lt;code&gt;&amp;lt;Directory&amp;gt;&lt;/code&gt;, so you could
actually paste this:&lt;br /&gt;
&lt;code&gt;&amp;lt;Directory "/var/www/html/wp-content/plugins/share-this/"&amp;gt;&lt;/code&gt;  &lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;Files "share-this.php"&amp;gt;                 Allow from all         &amp;lt;/Files&amp;gt; &amp;lt;/Directory&amp;gt;&lt;/code&gt;&lt;br /&gt;
I hope this all makes sense, and is of some use to someone...good luck
to the blogsecurity team, if you need any help feel free &lt;a href="https://www.linickx.com/contact"&gt;to
shout&lt;/a&gt; ;)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Mon, 08 Oct 2007 08:59:00 +0100</pubDate><guid isPermaLink="false">tag:www.linickx.com,2007-10-08:trouble-shooting-the-wordpress-security-white-paper</guid><category>apache</category><category>blogsecurity.net</category><category>hardening</category><category>htaccess</category><category>Security</category><category>WordPress</category></item><item><title>HTTP Compression on Redhat / CentOS / Fedora</title><link>https://www.linickx.com/http-compression-on-redhat-centos-fedora</link><description>&lt;p&gt;I was doing some
&lt;a href="http://www.port80software.com/products/zipenable/compresscheck"&gt;testing&lt;/a&gt;
on my server the other day, and realised that http compression within
apache (httpd) was not enabled by default. Further digging showed me
that
&lt;a href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html"&gt;mod_defate&lt;/a&gt; was
what I needed, and infact it was installed by default on my CentOS box.&lt;/p&gt;
&lt;p&gt;How to enable mod_default on Centos: Create
&lt;strong&gt;/etc/httpd/conf.d/deflate.conf&lt;/strong&gt; with the following contents&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;     # Insert filter
     SetOutputFilter DEFLATE

     # Netscape 4.x has some problems...
     BrowserMatch ^Mozilla/4 gzip-only-text/html

     # Netscape 4.06-4.08 have some more problems
     BrowserMatch ^Mozilla/4.0[678] no-gzip

     # MSIE masquerades as Netscape, but it is fine
     BrowserMatch bMSIE !no-gzip !gzip-only-text/html

     # Don't compress images
     SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary

        # Don't compress already compressed stuff !
        SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
        SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary

     # Make sure proxies don't deliver the wrong content
     Header append Vary User-Agent env=!dont-vary

        # Log Stuff !
#        DeflateFilterNote Input input_info
#        DeflateFilterNote Output output_info
#        DeflateFilterNote Ratio ratio_info
#        LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#        CustomLog /var/log/httpd/deflate_log deflate
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;restart httpd (&lt;strong&gt;/etc/init.d/httpd restart&lt;/strong&gt;) and your done :-)&lt;/p&gt;
&lt;p&gt;References:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.port80software.com/products/zipenable/compresscheck"&gt;port80software.com -
    compresscheck&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html"&gt;apache.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch20_:_The_Apache_Web_Server"&gt;Linux Home
    Networking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.howtoforge.org/apache2_mod_deflate"&gt;How To Forge&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Thu, 21 Jun 2007 16:37:00 +0100</pubDate><guid isPermaLink="false">tag:www.linickx.com,2007-06-21:http-compression-on-redhat-centos-fedora</guid><category>apache</category><category>centos</category><category>Fedora</category><category>Linux</category><category>redhat</category></item><item><title>Service Recovery Scripts &amp; Error Page Tips.</title><link>https://www.linickx.com/service-recovery-scripts-error-page-tips</link><description>&lt;p&gt;A couple of weeks ago, I was proper ill with flu; the problem with
looking after your own server is that only you can fix it - it's well
and good having monitoring systems (&lt;em&gt;nagios&lt;/em&gt;) telling you about faults,
but if you can't read or see the alerts the fault won't get resolved.&lt;/p&gt;
&lt;p&gt;During this time I was ill, for an unknown reason the mySQL process on
my server died, as such my website (&lt;em&gt;and others I look after&lt;/em&gt;) were down
for 8 hours. The fix was simple, one command, restart the service and
normal service was resumed (&lt;em&gt;excuse the pun&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;This led to me to the conclusion that there must be a way to get the
server to fix it's self. after all, why do a job when you can get a
computer to do it for you ! Fortunately I had a
&lt;abbr title="short moment of genuis"&gt;light bulb moment&lt;/abbr&gt; and
realised that I could use the init scripts that are provided by redhat,
the below code will restart apache (&lt;em&gt;httpd&lt;/em&gt;) and mySQL on a redhat based
system in the event that the service was not stopped cleanly. (&lt;em&gt;In-fact
this config has only be tested on CentOS, your mileage may vary on
anything else&lt;/em&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/bin/bash

# taken from redhast default scripts - /etc/rc.d/init.d/functions

# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
export PATH

status() {
        local base=${1##*/}
        local pid

        # Test syntax.
        if [ "$#" = 0 ] ; then
                echo $"Usage: status {program}"
                return 1
        fi

        # First try "pidof"
        pid=`pidof -o $$ -o $PPID -o %PPID -x $1 ||
             pidof -o $$ -o $PPID -o %PPID -x ${base}`
        if [ -n "$pid" ]; then
# Uncomment this if you want OK messages
#               echo $"${base} (pid $pid) is running..."
                return 0
        fi

        # Next try "/var/run/*.pid" files
        if [ -f /var/run/${base}.pid ] ; then
                read pid &amp;lt; /var/run/${base}.pid
                if [ -n "$pid" ]; then
                        echo $"${base} dead but pid file exists"
                        /etc/init.d/${base} restart
                        return 1
                fi
        fi
        # See if /var/lock/subsys/${base} exists
        if [ -f /var/lock/subsys/${base} ]; then
                echo $"${base} dead but subsys locked"
                /etc/init.d/${base} restart
                return 2
        fi
        echo $"${base} is stopped"
        return 3
}

# found in /etc/init.d/httpd
httpd=${HTTPD-/usr/sbin/httpd}

status mysqld
status $httpd
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you save this, as &lt;strong&gt;/etc/cron.hourly/auto_recovery.sh&lt;/strong&gt; , then do
&lt;strong&gt;chmod +x /etc/cron.hourly/auto_recovery.sh&lt;/strong&gt; , assuming you've not
changed the default cron setup, every hour mySQL &amp;amp; httpd will be
checked, if they have died the'll be restarted and root will get an
e-mail about what happened.&lt;/p&gt;
&lt;p&gt;Cool eh !&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A final finishing touch:&lt;/strong&gt; I wanted to change the default "Database
Down" error messages on my two most popular applications.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://allforces.com/2006/06/18/custom-wordpress-errors/"&gt;Melvin Rivera has written a tutorial on how to customize the
    wordpress error
    page&lt;/a&gt;,
    note that it involves editing a file outside of wp-content, that
    means you'll have to re-do this "hack" every time you upgrade
    wordpress.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;PHPBB: Setting a custom error page on that is really easy, first
    create a php page displaying your message. Then at the bottom of
    /path/to/phpbb-install/includes/db.php you'll see&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Make the database connection.
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
if(!$db-&amp;gt;db_connect_id)
{
message_die(CRITICAL_ERROR, "Could not connect to the database");
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;change it to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; // Make the database connection.
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
if(!$db-&amp;gt;db_connect_id)
{
 include("/path/to/my-custom-error-page.php");
        die();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now if you database dies, for the time it's down (&lt;em&gt;before cron fixes
it&lt;/em&gt;) wordpress &amp;amp; phpbb sites would get a much prettier error message.
Obviously there's no solution for apache as there's nothing to serve the
pages, but hopefully this kind of thing doesn't happen to often :D&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Tue, 06 Mar 2007 13:32:00 +0000</pubDate><guid isPermaLink="false">tag:www.linickx.com,2007-03-06:service-recovery-scripts-error-page-tips</guid><category>apache</category><category>Enterprise Linux</category><category>Fedora</category><category>httpd</category><category>Linux</category><category>monitoring</category><category>mysql</category><category>recovery</category><category>WordPress</category></item></channel></rss>