Source

stagehand / install / nginx.py

Full commit
"""
stagehand.installers.nginx

Install nginx using apt (default) or from source.
Requires a working fabric installation on the installing host.

Copyright 2010-2012 Van Lindberg. Released under the BSD license.

The exported API consists of the following functions:

- nginx_installed(): Test to see whether nginx has been installed
  and is available on the $PATH. Return True or False.

  install_nginx(use_src=False): Try to install the latest nginx 
  provided by apt. The precise packages installed are 
  controlled by constants.NGINX_APT_PACKAGES. Exposed as a task.
  
"""
# stdlib imports
import re
import urllib

# Third party imports
from fabric.api import *

# Package imports
from .. import constants
from ..utils import report, which
from .tools import add_apt_repository, apt_install, update_packages 

__all__ = ['nginx_installed', 'install_nginx']

@runs_once
def add_nginx_archive(archive=constants.NGINX_PPA):
  """
  Add the archive for nginx.
  """
  add_apt_repository(archive)

def nginx_installed():
  """
  Test to see whether nginx has been installed.
  Return True or False.
  """
  return bool(which('nginx'))

@task(default=True)
def install_nginx(upgrade=False):
  """
  Install the latest nginx provided by apt (default) or by
  the source downloads on nginx.net.  
  """
  if nginx_installed() and not upgrade:
    report('Nginx already installed. Skipping...')
    return
  else:
    # Make sure that we have the latest
    add_nginx_uwsgi_ppa()
    apt_install(constants.NGINX_APT_PACKAGES, warn_only=True)
    if not nginx_installed(): 
      abort('Could not install nginx.')
    else:
      report('Nginx installed.')


#~