Category Archives: Featured

MySQL 5.5 on Ubuntu 12.04 – Job Failed to Start

I migrated a web site from one host to another and as such upgraded to MySQL 5.5 running on Ubuntu 12.04.  Everything was moving along nicely until MySQL started to randomly crash.

Jul 23 07:06:38 domU-12-31-39-02-76-EA kernel: [236645.626405] init: mysql main process (21515) terminated with status 1
Jul 23 07:06:38 domU-12-31-39-02-76-EA kernel: [236645.626453] init: mysql main process ended, respawning
Jul 23 07:06:39 domU-12-31-39-02-76-EA kernel: [236646.617559] init: mysql post-start process (21516) terminated with status 1

Trying to start the process using the service command yields this message:

Job failed to start

I found several sites recommending that I uninstall and re-install mysqld – which I did to no avail.

I finally tried to run mysqld manually from command line and found a bit more of a clue:

120723 7:40:29 [Note] Plugin 'FEDERATED' is disabled.
120723 7:40:29 InnoDB: The InnoDB memory heap is disabled
120723 7:40:29 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120723 7:40:29 InnoDB: Compressed tables use zlib 1.2.3.4
120723 7:40:29 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
120723 7:40:29 InnoDB: Completed initialization of buffer pool
120723 7:40:29 InnoDB: Fatal error: cannot allocate memory for the buffer pool
120723 7:40:29 [ERROR] Plugin 'InnoDB' init function returned error.
120723 7:40:29 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
120723 7:40:29 [ERROR] Unknown/unsupported storage engine: InnoDB
120723 7:40:29 [ERROR] Aborting
120723 7:40:29 [Note] /usr/sbin/mysqld: Shutdown complete

Aha!  Looks like something with the configuration of Innodb.

Checking some of these messages revealed that the default configuration for innodb_buffer_pool_size is 128M… for my small server this was simply too large.

From here, I simply modified /etc/mysql/my.cnf to include the following statement

innodb_buffer_pool_size = 16M

A much more reasonable number considering the size of my server memory. Now simply start your mysql server and you should be good to go!

Tagged ,

Slow Wireless Download Speeds Solved – Disable WMM Support

I was completely frustrated with the speed of my network connection so I decided to do some investigation. I was convinced that Comcast was to blame and even placed a call to their support department to complain. They told me that the network speeds were as promised and everything checked out. They reset the connection and told me there was nothing they could do.

I ran speed tests (over at http://speedtest.net) and found the download speeds to be anywhere from .66Mbps to .99Mbps.

I tried disabling the security to no avail. I tried disabling the firewall and Upnp – again speeds hovered around 1Mbps. Finally, I disabled WMM support and POW! Speeds increased to over 35Mbps. Below is the screenshot of Cisco configuration.

To modify the configuration, login to your router and select Applications & Gaming, then click QoS and click Disable next to the WMM Support option.  WMM or Wireless Multi-Media Extensions were created to enable better performance (Quality of Service) for video and voice traffic but have the unintended effect of destroying wireless performance.

Disable WMM Support to Fix Slow Wireless Speeds

Disable WMM Support to Fix Slow Wireless Speeds

Shack on the Beach II

Be it ever so humble…

[nggallery id=2]

Graceful Sidebar Updated – Version 1.0.14 Released

The Graceful Sidebar is a WordPress plugin that enables you to display custom sidebar content for each of your posts or pages. This update fixes a problem that resulted in deleted sidebars.  As always, please remember to backup your wordpress database prior to installing this (or any) updated plugin.  Check out this guide to backing up your database for additional details on exactly how to do that.

Gantter Project – A Great, Free Way to Manage Projects

I’ve used OpenProj for several years. It’s a nice, free alternative to MS Project. The only problem is sharing the project plans with folks – rarely do people I work with have OpenProj installed. Fortunately, OpenProj gives you the option of saving as a MS Project XML file. This makes it easier but I was still looking for the ability to save the projects in PDF format. This is possible, but only with the paid version of OpenProj. This is when I found the Gantter Project.

Gantter is written to work with Google Apps. It enables you to import MS Project project plans, save them as PDF and even save them directly to Google Docs.

For me, Google Docs and the Gantter Project work best with my custom domain – mlynn.org – but you can use it even if you don’t have a custom domain. Visit Gantter.com to find out more information about this great, free tool to help you manage your projects.

Tagged ,

How to Monitor your Mac Desktop with Dropbox

I’m a huge fan of the fabulous, free storage service called Dropbox so when I saw a recent episode of Hak5 which covered monitoring your desktop with Dropbox, obviously, I jumped right in. Turns out, however that the episode only covers how to do this using MS Windows. I decided to whip something up for the rest of us and this article covers how I accomplished it. However, I’m not really sure how realistic it is to think of this as a real security tool. First of all it’s unless you’ve enabled passwordless login, or someone has compromised your password, or you’ve left your mac unlocked… it’s highly unlikely that you’ll find this a much value beyond a science experiment. So that’s what I’m calling it… an experiment in Mac Desktop Monitoring using Dropbox.

If you’re not using Mac OS – you’ll want to head over to either the Hak5 episode or to this link on the Dropbox forum which covers how to accomplish this with windows.

Link to Script Download

[download id=”6″]

Requirements

  • First, you need a free dropbox account. I would encourage you to click here and sign-up if you don’t have one already. After you’ve installed Dropbox and have it running, you should have a folder that you’ll use to store files and make them available to multiple computers using the same Dropbox account. In this tutorial, we’ll leverage dropbox to share images of your computer’s desktop in the event that some activity is taking place.
  • Second, you need to install ImageMagick. This is a suite of tools that allows you to create, edit and manipulate graphic files from the command line. The installation is simple if you download the binary for Mac OS X, or you can use MacPorts to install it. Instructions on available on the ImageMagick Site.
  • Lastly, you’ll need to know your way around the terminal app. This script was written in shell and will need to be started via cron on a regular basis or you can enable the loop option by editing the code as directed (Around lines 172 and 242.) If you’re unfamiliar with the Mac OS Terminal or shell commands, Click Here. This package comes with an example crontab entry file called dbmon.crontab. You’ll need to add the contents of this file to your user crontab using the crontab command… eg: crontab -e or crontab < dbmon.crontab.

What’s in the script package?

  • ./dbmon.crontab – Example crontab to run the script every minute.
  • ./dbmon.sh – The monitoring script.
  • ./gpl.txt – GPL Text – this script is covered under the terms of the GNU Public License.
  • ./start – Start script to enable the script once you’ve set it to run via crontab.
  • ./status – Check whether or not the script is enabled or disabled.
  • ./stop – Stop the script – disable it from running.

How does it work?

The script works by taking periodic screenshots and comparing them to each other. Using ImageMagick’s compare utility, we can assign a value to the level of difference between two images. The script allows you to set a tolerance for the difference detection – the default seems to work well and is set at a level of 6. Any difference greater than the tolerance probably means that someone is on your desktop doing something. The script will move the screen captures to a configurable directory (typically under your dropbox folder) and send you an email with the screen capture to alert you.

If you’re using Dropbox from a computer other than the one you’re monitoring during the time an alert fires, you’ll be notified by the dropbox update daemon telling you that you’ve added several images to your dropbox folder.

Why do I need this?

Let’s say you’re a mobile worker, with several machines that you use on a regular basis. You probably have a desktop at work, a laptop and maybe several home computers that you use regularly. Dropbox allows you to have a common file share between all of these computers. This script allows you to leverage the communication and storage channels of dropbox to alert you when someone attempts to use one of your computers.

Combine Dropbox with a remote access tool such as Logmein and you’ve got a pretty good remote monitoring and access suite.

How do I install it?

The script was written in shell and can run pretty much from any directory. I would recommend something like the following to install it and test it out…

  1. Make a directory under your home directory
    mkdir /Users/you/dbmon
  2. Download the script package, untar it and place it in a file under that directory… call it something like dbmon.sh.
    tar zxvf dbmon-v1.0.tar.gz
  3. Make it executable
    chmod +x /Users/you/dbmon/dbmon.sh
    
  4. Edit the script or simply create a .dbmon configuration file in your home directory (~/.dbmon) and change the variables to reflect your specific environment.
    computer:dbmon mlynn$ vi ~/.dbmon
    

    ~/.dbmon

    DBMON_TOLERANCE=9
    DBMON_ACTIVE="1"
    DBMON_SCOUNT="2"
    DBMON_SLEEP="1"
    DBMON_VERBOSE='ON'
    DBMON_PROGNAME='DBMON'
    # LABEL="ON" doesn't work... bug in ImageMagick Version 6.6.3
    DBMON_LABEL="OFF"
    DBMON_LABELMESSAGE="Screen Capture $HOSTNAME "
    DBMON_DBPATH='/Users/you/Dropbox/dbmon'
    DBMON_TMPPATH='/Users/you/dbmon/tmp'
    DBMON_ALERTEMAIL='you@gmail.com'
    DBMON_REMOTEOFFSWITCH='/Users/you/Dropbox/dbmon/OFF'
    DBMON_CONVERT="$MAGICK_HOME/bin/convert"
    DBMON_COMPARE="$MAGICK_HOME/bin/compare"
    DBMON_SCAP="/usr/sbin/screencapture"
    
  5. Now you should be able to test the script out by simply running it.
    computer:dbmon you$ ./start 
    computer:dbmon you$ ./dbmon.sh 
    [08/09/2010 21:20:49] DBMON: Moving /Users/you/dbmon/tmp/alert/current.png to /Users/you/dbmon/tmp/alert/previous.png...
    [08/09/2010 21:20:49] DBMON: Snapping /Users/you/dbmon/tmp/alert/current.png...
    [08/09/2010 21:20:50] DBMON: Comparing /Users/you/dbmon/tmp/alert/current.png to /Users/you/dbmon/tmp/alert/previous.png...
    [08/09/2010 21:20:51] DBMON: Difference [2925] exceeds tolerance [9]!!
    [08/09/2010 21:20:51] DBMON: Copying /Users/you/dbmon/tmp/alert/current.png to /Users/you/Dropbox/dbmon/201008/20100809-212049.png...
    [08/09/2010 21:20:51] DBMON: Sending alert email to you@gmail.com...
    [08/09/2010 21:20:51] DBMON: Snapping 1
    [08/09/2010 21:20:54] DBMON: Snapping 2
    computer:dbmon you$ ./stop 
    
    
  6. Once you’ve got it working, you can create a crontab entry to run it on a regular basis. Place the following in your crontab…
    * * * * * /Users/you/dbmon/dbmon.sh > /dev/null 2>&1
    

    Keep in mind – this will run EACH AND EVERY MINUTE OF EVERY HOUR OF EVERY DAY OF EVERY MONTH – unless of course you implement the remote off switch file. I created two scripts “start” and “stop” for use in conjunction with the crontab file. The start file simply removes the remote off switch and the stop script replaces it by “touch”ing that file.

    start

    #!/bin/sh
    #===========================================================================
    #= Script : Monitoring your Mac Desktop with Dropbox
    #= File   : start
    #= Version: 0.2
    #= Author : Mike Lynn
    #= Email  : merlynn@gmail.com
    #= Website: http://www.mlynn.org/2010/08/how-to-monitor-your-mac-desktop-with-dropbox/
    #===========================================================================
    #= Copyright (c) 2010 Mike Lynn
    #= You are free to use and modify this script as long as this header
    #= section stays intact
    #= This file is part of the "Monitoring your Mac Desktop with Dropbox" script
    #=
    #= This program is free software; you can redistribute it and/or modify
    #= it under the terms of the GNU General Public License as published by
    #= the Free Software Foundation; either version 2 of the License, or
    #= ( at your option ) any later version.
    #=
    #= This program is distributed in the hope that it will be useful,
    #= but WITHOUT ANY WARRANTY; without even the implied warranty of
    #= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #= GNU General Public License for more details.
    #=
    #= You should have received a copy of the GNU General Public License
    #= along with Mobile Detection Script ; if not, write to the Free Software
    #= Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    #===========================================================================
    
    . ~/.dbmon
    if [ -z $DBMON_REMOTEOFFSWITCH ]; then
    	echo "No remote off switch set for dropbox monitor.  Exiting."
    	exit 1
    fi
    rm $DBMON_REMOTEOFFSWITCH
    
    

    stop

    #!/bin/sh
    #===========================================================================
    #= Script : Monitoring your Mac Desktop with Dropbox
    #= File   : stop
    #= Version: 0.2
    #= Author : Mike Lynn
    #= Email  : merlynn@gmail.com
    #= Website: http://www.mlynn.org/2010/08/how-to-monitor-your-mac-desktop-with-dropbox/
    #===========================================================================
    #= Copyright (c) 2010 Mike Lynn
    #= You are free to use and modify this script as long as this header
    #= section stays intact
    #= This file is part of the "Monitoring your Mac Desktop with Dropbox" script
    #=
    #= This program is free software; you can redistribute it and/or modify
    #= it under the terms of the GNU General Public License as published by
    #= the Free Software Foundation; either version 2 of the License, or
    #= ( at your option ) any later version.
    #=
    #= This program is distributed in the hope that it will be useful,
    #= but WITHOUT ANY WARRANTY; without even the implied warranty of
    #= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #= GNU General Public License for more details.
    #=
    #= You should have received a copy of the GNU General Public License
    #= along with Mobile Detection Script ; if not, write to the Free Software
    #= Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    #===========================================================================
    . ~/.dbmon
    if [ -z $DBMON_REMOTEOFFSWITCH ]; then
            echo "No remote off switch set for dropbox monitor.  Exiting."
            exit 1
    fi
    touch $DBMON_REMOTEOFFSWITCH
    
    

    Be sure to edit the path’s to the REMOTEOFFSWITCH variable in the .dbmon configuration file located in your home directory.

You will probably want to make sure you have the start and stop scripts configured on several of your machines so that you can remotely control execution of the monitoring script. Keep in mind your environment (like where you have Dropbox installed) may change – so you will need to make sure you configure the REMOTEOFFSWITCH variable accordingly for each installed computer.

Notes and warnings

  • Dropbox offers free storage starting at 2GB – a lot of space… but keep in mind that if you accidentally leave this monitoring script running while you’re logged on you’re going to eventually fill it up and run out of space.
  • A note regarding multiple monitors: This script will only monitor the primary monitor so if you’re using multiple monitors, keep this in mind.
  • Make sure that when you’re testing, you’re haven’t configured the script to write your temporary screen capture files to a place that will visibly change the monitor – like the desktop for example.
  • This initial version of the script contains the configuration variables and might be difficult for someone to implement if they’re not command shell savvy. The next version will probably be a bit more sophisticated and might even incorporate a gui component… let me know if you’re interested in something like by leaving a comment or sending me an email.

Mobile Device Detection and Redirection with Perl and CGI

Last month, I took some time and wrote about Mobile Device Detection and Redirection with PHP. Well, it turns out that some folks can’t (or choose not to) make use of PHP and favor the Perl/CGI approach to web development. This article covers the same bases and presents a set of examples implemented using Perl and Lincoln Stein’s great CGI.pm module.

Download Code and Examples Here:
From Github: http://github.com/mrlynn/MobileBrowserDetectionExample

or locally:
Version 0.3 (Latest – includes perl/cgi AND PHP examples)
[download id=”2″]

Version 0.2 (Older version – PHP examples only)
[download id=”1″]

View the working example using Perl/CGI here: http://mlynn.org/uatest/cgi-bin/index.cgi

Redirecting a user based on the type of device they are using is not rocket science. In fact, it can be accomplished quite simply using an apache redirect in a .htaccess file.

RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301]

The issue with this approach is that users coming to your site using an iPad will never have the ability to see the other versions of your site. for many, that may be a satisfactory solution. However, if you want users to have the ability to view a version of your site designed specifically for their type of mobile device by default – but have the option to click a link and either view or optionally set a preference for another version of the site, this article is for you.

Perl and CGI have been around for many years and are in wide use on the web. Perl is extremely extensible and using the very popular CGI.pm Perl Module written by Lincoln Stein, it’s very easy to write code to dynamically manage your web site.

Where PHP has built-in variables designed to expose the server and apache session environment ($_SERVER, $_SESSION), Perl and CGI.pm make use of %ENV and module variables such as param(). Consider the following table which contrasts PHP and Perl/CGI.

User Agent

PHP

$_SERVER['HTTP_USER_AGENT']

Perl/CGI

$ENV{HTTP_USER_AGENT}

Reading Cookies

PHP

$cookievalue = $_COOKIE['COOKIENAME']

Perl/CGI

use CGI;
$query=new CGI;
$cookievalue = $query-&gt;cookie('COOKIENAME');

Setting Cookies

PHP

setcookie(name, value, expire, path, domain);

Perl/CGI

$cookie = $query-&gt;cookie(-name=&gt;'COOKIENAME',
			 -value=&gt;'COOKIEVALUE',
			 -expires=&gt;'+4h',
			 -path=&gt;'/');
print $query-&gt;header(-cookie=&gt;$cookie);

Now that we have the basics down, the rest is easy. We’ll want to check the users’ device type by querying the user agent, check the value of a cookie to see if they’ve specified a preference for something other than the site designed for their specific device and redirect accordingly.

The initial landing page does most of the heavy lifting.

index.cgi

#!/usr/bin/perl
require 'includes/config.inc.pl';
require 'includes/functions.inc.pl';

use CGI;
$query = new CGI; 

$useragent = $ENV{HTTP_USER_AGENT};
$sitepref = $query->cookie( 'SITEPREF' );

if ( ismobile( $useragent ) ) {
        if ( !$sitepref ) {
          if ( isipad( $useragent ) ) {
                  print $query->redirect( "$IPADURL" );
          } else {
              if ( isiphone( $useragent ) ) {
                          print $query->redirect( "$IPHONEURL" );
                  } else {
                          print $query->redirect( "$MOBILEURL" );
                  }
          }
        } else {
          if ( $sitepref=='MOBILE' ) {
                  print $query->redirect( "$MOBILEURL" );
          } else {
                  if ( $sitepref=='IPHONE' ) {
                          print $query->redirect( "$IPHONEURL" );
                  } else {
                          if ( $sitepref=='IPAD' ) {
                                  print $query->redirect( "$IPADURL" );
                          } else {
                                  print $query->redirect( "$NORMALURL" );
                          }
                  }
            }
        }
} else {
    if ( !$sitepref ) {
          print $query->redirect( "$NORMALURL" );
    } else {
      if ( $sitepref=='MOBILE' ) {
          print $query->redirect( "$MOBILEURL" );
      } else {
          if ( $sitepref=='IPAD' ) {
              print $query->redirect( "$IPADURL" );
          } else {
              if ( $sitepref=='IPHONE' ) {
                  print $query->redirect( "$IPHONEURL" );
              } else {
                  print $query->redirect( "$NORMALURL" );
              }
          }  
      }
    }
}

And the included files… which set the URL values and contain many of the functions.

functions.inc.pl

sub setcookiealive() {
        my ($name,$value,$expires,$redirect) = @_;
        $cookie = $query->cookie(-name=>"$name",
                         -value=>"$value",
                         -expires=>'+5d',
                         -path=>'/');
        if ($redirect) {
                print $query->redirect("$redirect","-cookie=>$cookie");
        } else {
                print $query->header(-cookie=>$cookie);
        }
}

sub in_array {
     my ($arr,$search_for) = @_;
     my %items = map {$_ => 1} @$arr; # create a hash out of the array values
     return (exists($items{$search_for}))?1:0;
}

sub ismobile {
        $useragent=lc(@_);
        $is_mobile = '0';

        if($useragent =~ m/(android|up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i) {
                $is_mobile=1;
        }

        if((index($ENV{HTTP_ACCEPT},'application/vnd.wap.xhtml+xml')>0) || ($ENV{HTTP_X_WAP_PROFILE} || $ENV{HTTP_PROFILE})) {
                $is_mobile=1;
        }

        $mobile_ua = lc(substr $ENV{HTTP_USER_AGENT},0,4);
        @mobile_agents = ('w3c ','acs-','alav','alca','amoi','andr','audi','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','oper','palm','pana','pant','phil','play','port','prox','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-');

        if(in_array(@mobile_agents,$mobile_ua)) {
                $is_mobile=1;
        }

        if ($ENV{ALL_HTTP}) {
                if (index(lc($ENV{ALL_HTTP}),'OperaMini')>0) {
                        $is_mobile=1;
                }
        }

        if (index(lc($ENV{HTTP_USER_AGENT}),'windows')>0) {
                $is_mobile=0;
        }
    return $is_mobile;
}

sub isiphone {

        $useragent = @_;
        $iphone=0;
        if (lc($useragent) =~ m/iphone/) {
                $iphone=1;
        }
        return $iphone;
}

sub isipad {

        $useragent = @_;
        $ipad=0;
        if (lc($useragent) =~ m/ipad/) {
                $ipad=1;
        }
        return $ipad;
}
1;

config.inc.pl

$SITEURL='http://mlynn.org/uatest/cgi-bin/index.cgi';
$LOGFILE='debug.log';
$MOBILEURL='http://mlynn.org/uatest/cgi-bin/mobile/index.cgi';
$IPHONEURL='http://mlynn.org/uatest/cgi-bin/iphone/index.cgi';
$IPADURL='http://mlynn.org/uatest/cgi-bin/ipad/index.cgi';
$NORMALURL='http://mlynn.org/uatest/cgi-bin/normal/index.cgi';
1;

Related Sites and Interesting Links

Have a site you’d like to add to this list? Send me an email or submit a comment.

Tagged , ,