Last active
December 17, 2015 04:08
-
-
Save Kuchitama/5548125 to your computer and use it in GitHub Desktop.
Sample of Fabric task to install Nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import env, run, local, sudo, cd | |
from fabric.contrib.files import exists, upload_template | |
from fabric.decorators import task | |
import java_setup | |
nginx_version='1.2.8' | |
nginx_dir = "nginx-%s" % nginx_version | |
nginx_url = "http://nginx.org/download/%s.tar.gz" % nginx_dir | |
install_dir = "/usr/local/nginx" | |
@task | |
def target(): | |
env.hosts=['192.168.33.11'] | |
env.port = 22 | |
env.user = 'vagrant' | |
env.password = 'vagrant' | |
@task | |
def install_dev_pkg(): | |
sudo("apt-get -y install g++") | |
sudo("apt-get -y install libpcre3 libpcre3-dev") | |
def get_nginx(): | |
with cd("/tmp"): | |
sudo("wget %s" % nginx_url) | |
sudo("tar xzvf nginx-1.2.8.tar.gz") | |
with cd(nginx_dir): | |
sudo("./configure --prefix=%s" % install_dir) | |
sudo("make") | |
sudo("make install") | |
def clear(): | |
with cd("/tmp"): | |
sudo("rm -f %s.tar.gz" % nginx_dir ) | |
sudo("rm -rf %s" % nginx_dir ) | |
@task | |
def install_nginx(): | |
get_nginx() | |
clear() | |
@task | |
def upload_conf(target='dev'): | |
template = 'nginx.tmpl' | |
conf_path = '%s/conf/nginx.conf' % install_dir | |
if target == 'prod': | |
upload_template(template, conf_path, {'worker_processes':2, 'server_name':"product"}, use_sudo=True) | |
else: | |
upload_template(template, conf_path, {'worker_processes':1, 'server_name':"develop"}, use_sudo=True) | |
@task | |
def start_nginx(): | |
sudo('%s/sbin/nginx' % install_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fab target install_dev_pkg install_nginx upload_conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#user nobody; | |
worker_processes %(worker_processes)d; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
log_format main 'remote:$remote_addr\t' | |
'time:$time_local\t' | |
'request:$request\t' | |
'status:$status\t' | |
'referer:$http_referer\t' | |
'ua:$http_user_agent'; | |
access_log logs/access.log main; | |
sendfile on; | |
keepalive_timeout 65; | |
server { | |
listen 80; | |
server_name %(server_name)s; | |
location / { | |
root html; | |
index index.html index.htm; | |
} | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment