Archive | 2013

monit For Wowza on Ubuntu 12.04 LTS

So Wowza is a cool media streaming server, but sometimes it crashes..for no apparent reason – or perhaps sometimes you’ve just got the memory limit set too high for the machine and the process gets reaped.

Either way it’s pretty important to keep it running, my favourite tool for this kind of job (process monitoring, restarting etc) is monit:

Monit is a free open source utility for managing and monitoring, processes, programs, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.

So how to get it up and running? Assuming you’re using the regular Wowza package, it already comes with an init.d script located at /etc/init.d/WowzaMediaServer, assuming that’s the case, this config will work fine for you.

sudo aptitude update; sudo aptitude install monit

That installs monit, then all you need to do is create & edit:

sudo nano /etc/monit/conf.d/wowza.conf

In that file put:

# /etc/monit/conf.d/wowza.conf
check process wowza with pidfile /var/run/WowzaMediaServer.pid
start program = "/etc/init.d/WowzaMediaServer start" with timeout 60 seconds
stop program = "/etc/init.d/WowzaMediaServer stop"
if 2 restarts within 3 cycles then timeout
if children > 255 for 5 cycles then stop
if totalcpu usage > 95% for 3 cycles then restart
if failed port 1935 protocol http then restart

Then (just for good measure):

sudo service monit restart

If you are using a different Linux flavour, or install style, your PID and stop/start script might be in different locations so you’ll have to edit accordingly.

This will monitor the Wowza process and makes sure it’s running, the default check period is 2 minutes, so with this set up the most the Wowza service can be down for is 2 minutes. It will also restart the service if it’s using more than 95% of the total CPU available for more than 6 minutes.

Enjoy 🙂

Tags: , , , , , , ,

Continue Reading · No Comments · Internet & Tech, Sys Admin & DevOps

Intermittent MongoDB [conn5] assertion 16550 not authorized for query Error After Upgrade to 2.4

So I recently upgraded the main MongoDB replica set from 2.2.x to 2.4.x for performance and mostly for security after the recent major MongoDB vulnerability.

Setting up the replica set in the first place wasn’t too troublesome, but maintaining has been a pain in the butt on and off, MongoDB does have some peculiarities. Once for PRIMARY member of the set crashed or hung or something, and the other 2 got confused, and rather than electing a new PRIMARY – just stopped working entirely.

Also the Ubuntu package doesn’t come with Logrotate capability, and the MongoDB log is very noisy, so I ran out of HDD space on a machine during one of my earlier installs.

Plus the default ‘security’ setup of MongoDB is a bit worring, it comes with auth turned off, no user/password login and it listens on all ports rather than binding to localhost by default. Of course all of these things are fairly easily fixed, but it makes me wonder how many poorly secured MongoDB instances there are out there on the public Internet.

Anyway back to this problem, at first I couldn’t upgrade to 2.4 because of a duplicate user error, after installed the new package it failed to start (rather than warning me during install) – so I had to roll back to the older version and lock the package there for a while. After getting rid of the duplicate users, I could upgrade.

But 50% of the time the app was erroring out with something like this:

Fri Apr 17 09:48:01.790 [conn5] assertion 16550 not authorized for query on databasename.collection ns:databasename.collection query:{ $query: { email: "abc@hotmail.com" }, $orderby: { _id: 1 } }

But half the time it worked, I tried all sorts of things, figuring out maybe the upgrade corrupted something. I totally deleted the data from both the SECONDARY MongoDB servers, and let them resync, updated the OS, rebooted, all kinds of things.

Even switched around the PRIMARY node, all of which..did nothing – I still kept getting the errors.

Finally after digging through the Ruby logs, which verified the app was getting an authentication error and digging through the database, I figured out what might be causing the problem. The Ruby logs were showing something like this:

Moped::Errors::QueryFailure: The operation: #Moped::Protocol::Query
@length=110
@request_id=93
@response_to=0
@op_code=2004
@flags=[:slave_ok]
@full_collection_name="databasename.collection"
@skip=0
@limit=1
@selector=redacted
@fields=nil
failed with error 16550: "not authorized for query on databasename.collection"

After some more digging, I found a user with the same username, in 2 different databases. So we have database databasename and database admin, both of which had the users databaseuser and admin.

You can search for users using these commands (you’ll have to auth first, if you set it up):

> use mydatabase
> db.system.users.find()

Do this on each database you have, to check for duplicate usernames, to list all databases just do:

> use admin
> show dbs

If you find any duplicate users, you can delete them with:

> db.system.users.remove({"user" : "USERNAME"});

So I deleted the admin user from databasename and deleted the databaseuser from the admin database, what I suspect was happening was 50 percent of the time it was authing with the right user and working fine, but 50% of the time it was authing with the wrong user (databaseuser in the admin database) and not having access to what it needed, and thus giving the assertion error.

After deleting the two users, and restarting the app on all the cluster servers – the error went away and I wasn’t getting intermittent app failures any more! So yah if you’re having this problem, just double check all the databases you have and make sure you don’t have any users in different databases with the same username.

When it’s all good you’ll see something like this instead of the assertion errors:

Fri Apr 17 10:37:16.197 [conn442] authenticate db: databasename { authenticate: 1, user: "databaseuser", nonce: "7c1c7s234r23fds", key: "9sdf907897sdf78979s8d" }
Fri Apr 17 10:37:32.725 [conn216] query database.collection query: { $query: { email: "abc@hotmail.com" }, $orderby: { _id: 1 } } ntoreturn:1 ntoskip:0 nscanned:1 scanAndOrder:1 keyUpdates:0 locks(micros) r:142323 nreturned:1 reslen:126 141ms

I could find absolutely nothing on Google about this and it seems like MongoDB 2.4 deals with users/auth issues quite differently from 2.2 – so if you are upgrading beware.

Tags: , , , , , , , , , , ,

Continue Reading · 1 Comment · Internet & Tech, Sys Admin & DevOps

Installing WordPress In A Sub-Directory Using nginx

So I had this issue recently, I had a WordPress site on the main domain, and another WordPress install for some member stuff in a subdirectory/folder inside the main install. The main site worked fine, and the admin panel etc. But when you tried to change the Permalinks, everything got a 404 error.

I noticed that all requests were being routed back to the main domain (without the additional folder) so I guessed it was probably something to do with nginx, most likely this:

location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php?$query_string;
}

Which broke the rewrites inside the folder and sent everything to the main site, to get it working I had to add a couple more location directives for the sub-directory – now all different kinds of Permalink configs work.

This got the site working just fine:

location /subinstall {
root /home/maindomain.com/public_html/subinstall;
index index.php index.html index.htm;
try_files $uri $uri/ @wp;
}

location @wp {
rewrite ^/subinstall(.*) /subinstall/index.php?q=$1;
}

With /subinstall being the name of the sub-folder with the 2nd WordPress install.

Tags: , , , , , , ,

Continue Reading · No Comments · Internet & Tech, Sys Admin & DevOps

sysstat – sar Invalid system activity file: /var/log/sysstat/sa19

After a recent upgrade (not sure which) the sar command stopped working, with the error output:

Invalid system activity file: /var/log/sysstat/sa19

The saXX can be any number, and relates to the log file – which for some reason is corrupt/missing/unreadable. In my case it seems to exist, but doesn’t function.

I’ve found the best remedy to this to be purging sysstat from the system and reinstalling it, fairly trivial to script for multiple machines and seems to have fixed it up just fine.

Here’s the command to run to fix it:

sudo aptitude update;
sudo aptitude purge sysstat -y;
sudo aptitude install sysstat -y;
sudo sed -i "s/ENABLED="false"/ENABLED="true"/" /etc/default/sysstat;
sudo /etc/init.d/sysstat start
/

The lines from top to bottom update the repo list, remove sysstat and purge it’s settings, install sysstat, set the sysstat config file to true so it runs, then start the sysstat daemon.

It should be rocking again after that 🙂

root@server1:/var/log/sysstat# sar
Linux 3.8.4-x86_64 (server1) 04/19/2013 _x86_64_ (8 CPU)

08:59:15 AM LINUX RESTART

Tags: , , , , , , ,

Continue Reading · No Comments · Internet & Tech, Sys Admin & DevOps

Went To Bali For My 35th Birthday!

So it turns out for my 35th birthday, my wifey took me to Bali! Never been there before and always wanted to go.

Pretty interesting place, although next time I’d probably choose to stay in Seminyank or Ubud rather than Kuta, it was good to see the place though. Food there is pretty awesome, it was spectacularly hot when we went though.

Got to try a few local craft beers, but I couldn’t find Storm anywhere, ended up with some Stark though – which was decent.

Tanah Lot Sunset
This is the sunset from the famous temple Tanah Lot.

I’d definitely like to go again and spend some time exploring the place further, plus of course I really want to go diving there 🙂

So many other places to go though, arghhh – need more time and more money!

Tags: , , , , , , , ,

Continue Reading · 1 Comment · Indonesia, Trips & Travel

Getting Old – Turning 35 Today – Happy Birthday To Me!

Well another year has gone by, big year it was – with me getting married and all. Today, March 21st 2013 I have been on this earth for 35 eventful years. I’m not actually posting this right now, as one again (just like last year) my beautiful wife is taking me on a surprise vacation – so I have no idea where I’m going.

I do know, that it will be awesome – that’s for sure! Last year she took me to Pulau Weh, which was spectacular. We did some diving, which was spectacular!

SCUBA Diving Pulau Weh

We did a lot of chilling, eating and exploring – it was amazing, a true paradise.

Pulau Weh

I can’t wait to find out where we are going, I’ll probably know by the time you read this..Excites!

My birthday in –

2012 – Happy 34th Birthday To Me!
2011 – Happy Birthday To Me!
2010 – Random Blog Post #1 – What A Week & My Birthday
2009 – No post for some reason?!
2008 – My Surprise 30th Birthday Party / Being 30 – Happy Birthday to Me!
2007 – Happy Birthday to Me Again
2006 – Happy Birthday To Me.
2005 – The Triple Faggot Birthday Bonanza!
2004 – Hadn’t started blogging yet, and was still in the UK actually.

Tags: , , , , , , , ,

Continue Reading · 2 Comments · Trips & Travel

Fix Unknown Table Engine ‘INNODB’ Error For MySQL Munin Plugin

If you are running Munin on a newish server, with a new version of MySQL and you have InnoDB disabled (as recommended by scripts like mysqltuner.pl), the Munin plugins for MySQL will fail with the following error:

DBD::mysql::st execute failed: Unknown table engine 'INNODB' at /etc/munin/plugins/mysql_connections line 958.

It’s a pretty easy fix though, just edit the follow file:

sudo nano /usr/share/munin/plugins/mysql_

And at line 960-965 (+960 in vim or CTRL+_ 960 in nano), replace this:

if ($@) {
if ($@ =~ /Cannot call SHOW INNODB STATUS because skip-innodb is defined/) {
$data->{_innodb_disabled} = 1;
return;
}
die $@;

With this:

if ($@) {
if ($@ =~ /Unknown table engine 'INNODB'|Unknown storage engine 'innodb'|Cannot call SHOW INNODB STATUS because skip-innodb is defined/i) {
$data->{_innodb_disabled} = 1;
return;
}
die $@;

Your MySQL plugins for Munin should now work fine 🙂

Tags: , , , , , , ,

Continue Reading · No Comments · Internet & Tech, Sys Admin & DevOps

MongoDB For Ubuntu Doesn’t Install A Logrotate Script

This tripped me up before, one of my servers very rapidly ran out of disk space and I had to figure out why – I scanned the server and found the culprit directory was /var/log/mongodb/ and there was a single multi GB log file in there.

I checked /etc/logrotate.d/ and indeed the Ubuntu MongoDB package directly from mongodb.org (mongodb-10gen) doesn’t install a lot rotate script (which is rather perilous).

So as I wanted to keep logs on rather than disabling them totally, I rolled up a logrotate script. All you need to do is:

nano /etc/logrotate.d/mongodb

Then paste inside:

/var/log/mongodb/*.log {
daily
rotate 30
compress
dateext
missingok
notifempty
sharedscripts
postrotate
/bin/kill -SIGUSR1 cat /var/lib/mongo/mongod.lock 2> /dev/null 2> /dev/null || true
endscript
}

That’s it, now your logs will be rotated and compressed and your server diskspace won’t explode.

Tags: , , , , ,

Continue Reading · No Comments · Internet & Tech, Sys Admin & DevOps

Upgrading Ubuntu 10.04 To Use SVN 1.7 Client

If you are using ‘svn switch‘ on your deployer and you have older servers (Ubuntu 10.04 for example) the standard repo version of SVN will be 1.6, and won’t support the command.

What you need to do is upgrade the SVN client to version 1.7x with a PPA package. I suggest using the following commands:

sudo aptitude install python-software-properties;
sudo apt-add-repository ppa:svn/ppa;
sudo aptitude update;
sudo aptitude safe-upgrade

From top to bottom, it installs the software you need to add a PPA, adds the PPA, updates the repo index and then upgrades all packages (which will upgrade SVN too).

A PPA is a Personal Package Archives for reference.

Using a Personal Package Archive (PPA), you can distribute software and updates directly to Ubuntu users. Create your source package, upload it and Launchpad will build binaries and then host them in your own apt repository.

That means Ubuntu users can install your packages in just the same way they install standard Ubuntu packages and they’ll automatically receive updates as and when you make them.

The PPA above is from the SVN development team, so I assume it to be trustworthy.

After completing you should get this:

svn --version
svn, version 1.7.7 (r1393599)
compiled Oct 26 2012, 08:48:56

Have fun!

Tags: , , , , , , , , , ,

Continue Reading · No Comments · Internet & Tech, Sys Admin & DevOps

Wrong Token for Dropbox authentication received! BackWPup WordPress Plugin

If you receive this error and you are using W3 Total Cache – deactivate W3 Total Cache plugin totally first, then you will be able to authenticate just fine.

Wrong Token for Dropbox authentication received!

Falschen Token für die Dropbox-Authentifizierung erhalten!

Other problems could be –

  • Using any other plugins that have OAuth capability, such as Google Analyticator/Google Analytics for WordPress
  • Plugins that connect to Twitter or Dropbox
  • You don’t have CURL installed (or php5-curl extension)
  • CURL is disallowed on the user running the site
  • The domain isn’t resolving correctly on the server itself (If you ping the domain, from the server itself, make sure the IP address matches).

You will need to disable these plugins, install CURL if required, fix your DNS then you should be able to authenticate to Dropbox with BackWPup.

There are a some support threads regarding this error:

Dropbox token failure
Wrong security-token from Dropbox

Anyway, hope you manage to get it working if you come across this error 🙂

Tags: , , , , ,

Continue Reading · No Comments · Internet & Tech