Skip to content

Instantly share code, notes, and snippets.

@fudanchii
Created April 29, 2012 15:05
Show Gist options
  • Save fudanchii/2551051 to your computer and use it in GitHub Desktop.
Save fudanchii/2551051 to your computer and use it in GitHub Desktop.
fabric file to upgrade nginx in remote host
from __future__ import with_statement
from fabric.api import *
from posixpath import basename
version = "1.5.7"
what="http://nginx.org/download/nginx-%s.tar.gz" % version
prefix="/opt/nginx"
opt = "--prefix=/opt/nginx --with-openssl=../openssl-1.0.1e --with-pcre --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-ipv6 --with-http_image_filter_module"
env.hosts = [""]
env.user=""
def upgrade():
pkg = basename(what)
dirname = pkg[0:-7]
run("wget %s" % what)
run("tar -xf %s" % pkg)
with cd(dirname):
run("./configure %s" % configOpts())
run("make")
run("make install")
ngx_restart()
status()
def status():
run("%s/sbin/nginx -V" % prefix)
run("/opt/service/supervisorctl status nginx")
def ngx_restart():
test = run("%s/sbin/nginx -t" % prefix).return_code
if test == 0:
run("/opt/service/supervisorctl restart nginx")
def version():
run("%s/sbin/nginx -v" % prefix)
def configOpts():
result = run("%s/sbin/nginx -V" % prefix)
return result.split('\n')[-1][21:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment