Twitter LinkedIn Github
Sorry, we're having trouble loading this Tumblr.

Posts Tagged ‘Puppet’

Since we started WireLoad, the number of websites we host have grown steadily. It’s a myriad of sites, ranging from product sites to websites belonging to friends and family. Many of them are WordPress-sites (just like this one), while others are more complicated. Some use databases, while others don’t. Since we’re often in a rush when we set up a site, documentation often suffers, and you have to spend time later on trying to decipher how things were set up.

This past week I finally had enough and decided to resolve this issue once and for all. What we really needed was a template-based system that could take care of everything and provide us with a user friendly interface. Puppet felt like the best tool for the job so I got busy writing a custom module for this.

The final result is a module I named Puppet-hosting. It allows you to manage all your websites using Puppet. To add a new site, all you need to do is to add a few lines to in your site.pp, and you’re all set.

Here’s an example of how it can look:

hosting::site { 'My Website':
  type        => 'wordpress',
  url         => 'mysite.net',
  url_aliases => ['mysite.*', 'www.mysite.net'],
  ip          => $ipaddress_eth0,
  contact     => 'Viktor Petersson [email protected]>',
}

Not only does this make it much easier to manage all the sites, it also speeds things up and avoids human errors, such as typos (and if you do have a typo, it’s easy to spot, since it’s only a few lines in sites.pp).

I love Munin. It’s a great monitoring tool, quick to set up, and doesn’t come with too many bloated requirements. It’s also very flexible and easy to write plugins for.

On Ubuntu, Munin comes with most (non-custom) plugins I use. Unfortunately, the Nginx-plugins (nginx_status and nginx_request) are incorrectly documented. In the header of the plugins, one can read that the default URL is ‘http://localhost/nginx_status‘, which certainly makes sense. The plugin even documents how one were to set this up. However, the plugin logic tells a different story. In nginx_requests, we can see that it relies on ‘hostname -f’ to look up the hostname that it connects to (which in 99.999% of all production servers isn’t ‘localhost’).

The fix however, is very easy. All you need to do is to add the URL to the Munin’s plugin configuration file. This can be done using the following command:

if [[ $(cat /etc/munin/plugin-conf.d/munin-node | grep "nginx") = "" ]]; then echo -e "\n[nginx*]\nenv.url http://localhost/nginx_status" >> /etc/munin/plugin-conf.d/munin-node; fi

This can be run as many times as you’d like, as it only appends the config-snippet if it’s not there already.

In my case, I wanted to push this out using Puppet, so I have the following block in my Puppet Munin-module:

package { 'munin-node':
	ensure  => 'present',
}

service { 'munin-node':
	ensure     => 'running',
	hasrestart => 'true',
	hasstatus  => 'true',
	enable     => 'true',
}

file { 'nginx_request':
	ensure  => 'link',
	path    => '/etc/munin/plugins/nginx_request',
	target  => '/usr/share/munin/plugins/nginx_request',
	require => Package['munin-node'],
}

file { 'nginx_status':
	ensure  => 'link',
	path    => '/etc/munin/plugins/nginx_status',
	target  => '/usr/share/munin/plugins/nginx_status',
	require => Package['munin-node'],
}

# Fixes a bug in the plugin and configures it to poll using localhost
exec { 'activate_nginx_munin':
	command => 'bash -c if [[ $(cat /etc/munin/plugin-conf.d/munin-node | grep "nginx") = "" ]]; then echo "\n[nginx*]\nenv.url http://localhost/nginx_status" >> /etc/munin/plugin-conf.d/munin-node; fi',
	user    => 'root',
	require => [
		File['nginx_status'],
		File['nginx_request'],
		],
	path    => [
		'/usr/sbin',
		'/usr/bin',
		'/sbin:/bin',
	],
}

(I also use a Puppet-template for Munin’s config-file, but that’s beyond the scope of this article.)

Puppet on Ubuntu 10.04

December 18, 2011 4:44 am    Posted by Viktor Petersson    Comments (2)

Yesterday I decided that it’s about time to learn Puppet. I’ve had my eye on both Puppet and Chef for some time now. Yesterday after reading this Quora-thread and this blog-post, I decided to go with Puppet.

After downloading their test-VM and going through the tutorial, I pretty quickly fell in love with the simplicity and structure. Puppet is straight forward and rather intuitive.

One of the architectures that I wanted to deploy Puppet on was running Ubuntu 10.04 LTS. Unfortunately, the version from Ubuntu’s repository is really old (0.25.4), and not really compatible with much of the cool things you can do with Puppet.

Fortunately, PuppetLabs do provide their own repository, but the instructions for adding this repo wasn’t really at par with the rest of their excellent documentations — hence this post.

If you’re a die-hard Ubuntu/Debian-fan, this is probably pretty straight-forward, but if you’re not, here is what you need to do:

sudo su - 
echo -e "deb http://apt.puppetlabs.com/ubuntu lucid main\ndeb-src http://apt.puppetlabs.com/ubuntu lucid main" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv 4BD6EC30
apt-get update
apt-get install puppet

Ok, so that was pretty straight forward. The only tricky part was importing the keys, but now you know how to do that too.