Michael A. Nachbaur > Nginx-Control-0.04 > Nginx::Control

Download:
Nginx-Control-0.04.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  

NAME ^

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

SYNOPSIS ^

  #!perl
  
  use strict;
  use warnings;
  
  use Nginx::Control;
  
  my ($command) = @ARGV;
  
  my $ctl = Nginx::Control->new(
      config_file => [qw[ conf nginx.conf ]],
      # PID file can also be discovered automatically 
      # from the conf, or if you prefer you can specify
      pid_file    => 'nginx.control.pid',    
  );
  
  if ($ctl->test) {
      $ctl->start if lc($command) eq 'start';
      $ctl->stop  if lc($command) eq 'stop';
  }

DESCRIPTION ^

This is a fork of Lighttpd::Control to work with Nginx, it maintains 100% API compatibility. In fact most of this documentation was stolen too. This is an early release with only the bare bones functionality needed, future releases will surely include more functionality. Suggestions and crazy ideas welcomed, especially in the form of patches with tests.

ATTRIBUTES ^

config_file

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

prefix_path

This is an optional Path::Class::Dir instance pointing to the root prefix path where you would like Nginx to be started from. This will typically point at a location where logs and other sorts of files will be stored at start-up time.

binary_path

This is a Path::Class::File instance pointing to the Nginx 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 Nginx 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.

METHODS ^

start

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

stop

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

It will attempt to send a signal to the running master Nginx process to stop cleanly, and if this fails will manually kill the process.

reload

Reloads the Nginx server configuration without stopping and starting the process. This ensures a minimal amount of downtime will occur while updating to a new configuration.

test

Tests the Nginx server config to make sure it can start successfully.

is_server_running

Checks to see if the Nginx 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::Nginx::Control;
  use Moose;
  
  extends 'Nginx::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
post_startup
pre_shutdown
post_shutdown
pre_reload
post_reload

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 ^

Chris Prather <chris@prather.org$<gt>

Based on Lighttpd::Control by Stevan Little <stevan.little@iinteractive.com>

COPYRIGHT AND LICENSE ^

Copyright 2008 Chris Prather

except for those parts that are

Copyright 2008 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.

syntax highlighting: