Last updated at Wed, 25 Oct 2017 19:07:28 GMT

Opscode’s Chef is an open-source automation framework for the cloud, involving ‘recipes’ that can be triggered by events such as servers booting or restarting. Chef scripts are written in Ruby, but will often use OS-specific system calls to manipulate server instances. Chef is a great way to automate your cloud, and in particular it’s useful as your environment grows! On Engine Yard, Chef recipes can also be used to configure add-ons (like Logentries) on your servers, as we will explain…

Each server deployed in an Engine Yard environment uses the Linux-based Gentoo operating system, with Chef installed as standard. To make customisation of your application really simple, Engine Yard offers a RubyGem for hassle-free editing and
uploading of Chef scripts. This, along with the wide variety of cookbooks offered for Engine Yard customers, means it is possible to automate a lot of otherwise complicated tasks without ever ‘SSHing’ into your instances. Because of this user-friendly interfacing and Engine Yard’s very open user access policy, using a log management service will not require lots of time and effort that could be better spent developing and testing your app.

Logging on Engine Yard
Engine Yard allows full access to the file system on each Gentoo Linux instance, either using Chef automation or via SSH. This includes a number of different log files in several different locations, but all of which can be sent to Logentries for analysis and error detection. Check out this previous blog post by my colleague Trevor Parsons, which gives an insight into what to look out for in Engine Yard logs. Some files that might be of interest are:

  • ~/yourapp-deploy.log: deployment related events for this instance
  • /var/log/engineyard/apps/yourapp/production.log: Rails application errors and events
  • /var/log/daemon.log: background daemon information
  • /db/mysql/{major_version}/log/ or db/mysql/log/: MySQL database logs
  • General Linux logs: as outlined here

The Logentries Cookbook
The Logentries cookbook installs and configures an agent to monitor log files and to send events to the Logentries service. This is performed automatically, with the user only required to edit one or two user specific variables in advance. The agent is packaged in a Gentoo Linux application, which is downloaded from the Logentries server, installed and started. A daemon process constantly monitors the files being followed for new events – don’t worry, it uses very little CPU. The Chef script also checks the daemon every time it is run, to make sure multiple processes are not started.

The cookbook is available for download from GitHub, and can be added to a larger set of cookbooks or used on its own. To start using Logentries with Engine Yard, simply set up a Logentries account and retrieve your user key from the Account page. You will need to add this to */cookbooks/le/attributes/recipe.rb *in the indicated location. Some common files are followed by default –

  • “/var/log/syslog”
  • “/var/log/auth.log”
  • “/var/log/daemon.log”
  • “/var/log/nginx/#{app_name}.access.log”

– you can modify this list in cookbooks/le/recipes/configure.rb.

Then use the standard Engine Yard gem to upload the recipes to your instance – simply run

ey recipes upload -e ENVIRONMENT_NAME
ey recipes apply -e ENVIRONMENT_NAME

Adding additional files to your Logentries setup is very easy – just SSH into your Gentoo instance and use sudo le follow [file], or edit the recipes and re-upload if you prefer to avoid the command line. For more detailed instructions, see our Engine Yard docs.