Stevan Little

NAME

Lighttpd::Control - Simple class to manage a Lighttpd server

SYNOPSIS

  #!perl

  use strict;
  use warnings;

  use Lighttpd::Control;

  my ($command) = @ARGV;

  my $ctl = Lighttpd::Control->new(
      config_file => [qw[ conf lighttpd.conf ]],
      # PID file can also be discovered automatically
      # from the conf, or if you prefer you can specify
      pid_file    => 'lighttpd.control.pid',
  );

  $ctl->start if lc($command) eq 'start';
  $ctl->stop  if lc($command) eq 'stop';

DESCRIPTION

This is a packaging and cleaning up of a script we have been using for a while now to manage our Lighttpd servers. This is an early release with only the bare bones functionality we needed, future releases will surely include more functionality. Suggestions and crazy ideas welcomed, especially in the form of patches with tests.

Also note the recently uploaded Nginx::Control and Sphinx::Control both of which are based on this module but for different servers.

ATTRIBUTES

config_file

This is a Path::Class::File instance for the configuration file.

binary_path

This is a Path::Class::File instance pointing to the Lighttpd binary. This can be autodiscovered or you can specify it via the constructor.

pid_file

This is a Path::Class::File instance pointing to the Lighttpd pid file. This can be autodiscovered from the config file or you can specify it via the constructor.

server_pid

This is the PID of the live server.

This is a list of path prefixes in which we will attempt to find your lighttpd install in. The default list provided is; /usr, /usr/local, /opt/local, /sw, and /usr/pkg, which should cover most cases, but you can override in the constructor if not.

METHODS

start

Starts the Lighttpd server that is currently being controlled by this instance. It will also run the pre_startup and post_startup hooks.

stop

Stops the Lighttpd server that is currently being controlled by this instance. It will also run the pre_shutdown and post_shutdown hooks.

is_server_running

Checks to see if the Lighttpd server that is currently being controlled by this instance is running or not (based on the state of the PID file).

log

Simple logger that you can use, it just sends the output to STDERR via the warn function.

AUGMENTABLE METHODS

These methods can be augmented in a subclass to add extra functionality to your control script. Here is an example of how they might be used to integrate with FCGI::Engine::Manager (For a complete, working version of this, take a look at the file 003_basic_with_fcgi_engine.t in the test suite).

  package My::Lighttpd::Control;
  use Moose;

  extends 'Lighttpd::Control';

  has 'fcgi_manager' => (
      is      => 'ro',
      isa     => 'FCGI::Engine::Manager',
      default => sub {
          FCGI::Engine::Manager->new(
              conf => 'conf/fcgi.engine.yml'
          )
      },
  );

  augment post_startup => sub {
      my $self = shift;
      $self->log('Starting the FCGI Engine Manager ...');
      $self->fcgi_manager->start;
  };

  augment post_shutdown => sub {
      my $self = shift;
      $self->log('Stopping the FCGI Engine Manager ...');
      $self->fcgi_manager->stop;
  };
pre_startup

This will clear the server_pid attribute before doing anything else so that it can start with a clean slate.

post_startup

This will initialize the server_pid attribute and block while the server itself is starting up (and print a nice log message too).

pre_shutdown
post_shutdown

This will clear the server_pid attribute as the last thing it does so that there is not stale data in the instance.

BUGS

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Stevan Little <stevan.little@iinteractive.com>

Based on code originally developed by Chris Prather.

COPYRIGHT AND LICENSE

Copyright 2008-2009 Infinity Interactive, Inc.

http://www.iinteractive.com

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.




Hosting generously
sponsored by Bytemark