def install_nginx(): "Builds and installs nginx." env.user = env.server.root_login #print "Building nginx..." #with settings(warn_only=True): # run("rm -rf ~/_build") # Delete previous build files. # run("mkdir ~/_build") # Create new build file directory. # #with cd("~/_build"): # run("wget %s" % env.server.nginx_src) # run("tar -xzf %s" % env.server.nginx_src.rsplit('/', 1)[-1]) # with cd("nginx*"): # run("./configure") # run("make") # sudo("make install") # sudo("cp /usr/local/nginx/sbin/nginx /usr/sbin/nginx") # #with settings(warn_only=True): # run("rm -rf ~/_build") # Cleanup # #print "Setting up nginx init..." #if not exists("/etc/init.d/nginx"): # put_template( env.server['nginx.init'], "/etc/init.d/nginx", env.server, use_sudo=True) # sudo("chmod 755 /etc/init.d/nginx") # sudo("chown root:root /etc/init.d/nginx") # sudo("update-rc.d nginx defaults") sudo("apt-get install -qy nginx") print "Setting up nginx conf..." put_template( env.server['server_nginx.conf'], "/etc/nginx/nginx.conf", env.server, use_sudo=True)
def deploy(name=None): """ Deploy the given ``project``, or if not specified, the current project. """ import server if name: activate_project(name) else: name = env.project.key config = env.project print "Installing project %r..." % name print "", "Cloning repo..." with settings(warn_only=True): run("mkdir /www/%s" % name) run("mkdir /www/%s/src" % name) run("git clone %s /www/%s/src" % (config.git, name)) if config.mysql_name: # Todo: move to mysql.py print "", "Creating MySQL database..." with settings(warn_only=True): run("mysql --user=root --password=%s --execute=\"CREATE DATABASE %s\"" % (env.server.mysql_root_password, config.mysql_name)) run("mysql --user=root --password=%s --execute=\"GRANT ALL ON %s.* TO '%s'@'localhost' IDENTIFIED BY '%s'\"" % (env.server.mysql_root_password, config.mysql_name, config.mysql_user, config.mysql_password)) with cd("/www/%s" % name): print "", "Updating repo..." with cd("src"): run("git pull") with settings(warn_only=True): run("mkdir logs") run("mkdir sql") print "", "Installing virtualenv" with settings(warn_only=True): run("virtualenv env") print "", "Installing pip requirements..." with settings(warn_only=True): run("virtualenv env") run("env/bin/pip install -r src/requirements.txt") run("env/bin/pip install mysql-python") #run("env/bin/pip install cython -e git+https://github.com/surfly/gevent.git#egg=gevent") print "Generating config files..." for conf in ["nginx.conf", "uwsgi.conf", "supervisor.conf"]: server.put_template( config[conf], "/www/%s/%s" % (name, conf), config) print "Generating custom manage.py file..." server.put_template( config["manage.py"], "/www/%s/src/manage.py" % name, config) run("chmod 755 /www/%s/src/manage.py" % name) print "Generating custom wsgi.py file..." server.put_template( config["wsgi.py"], "/www/%s/src/wsgi.py" % name, config) print "Supervisorctl rereading config..." run("sudo supervisorctl reread") up() print "Restarting nginx..." run("sudo /etc/init.d/nginx restart")
def build_config(): "Builds the config files for nginx, supervisor, and nginx." print "Building config files..." for c in ["nginx.conf", "uwsgi.conf", "supervisor.conf"]: put_template( env.project[c], root(c), env.project)
def build(): "Builds the www infrastructure." owner = env.server.www_owner env.user = '******' sudo("apt-get install libpcre3 libpcre3-dev") sudo("apt-get update") if env.project.gems: sudo("apt-get ruby") sudo("gem install %s" % " ".join(env.project.gems)) with settings(warn_only=True): sudo("rm -rf /root/_build") # Delete previous build files. sudo("mkdir /root/_build") # Create new build file directory. print "Building uwsgi..." sudo("apt-get -qy install build-essential psmisc libxml2 libxml2-dev") with cd("/root/_build"): sudo("wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz") sudo("tar -xzf uwsgi-latest.tar.gz") with cd("uwsgi*"): sudo("make") with settings(warn_only=True): sudo("rm /usr/local/sbin/uwsgi") sudo("cp uwsgi /usr/local/sbin") uwsgi_dir = sudo("pwd") print "Building nginx..." sudo("apt-get -qy install libssl-dev") with cd("/root/_build"): sudo("wget http://nginx.org/download/%s" % env.server.nginx_version) sudo("tar -xzf %s" % env.server.nginx_version) with cd("nginx*"): sudo("./configure") sudo("make") sudo("make install") put_template( env.server['server_nginx.conf'], "/usr/local/nginx/conf/nginx.conf", env.server, use_sudo=True) append("/etc/sudoers", "%s ALL=NOPASSWD: /etc/init.d/nginx restart" % owner, use_sudo=True) append("/etc/sudoers", "%s ALL=NOPASSWD: /etc/init.d/nginx reload" % owner, use_sudo=True) with settings(warn_only=True): sudo("rm -rf /root/_build") # Cleanup print "Creating /www..." with settings(warn_only=True): sudo("mkdir /www") sudo("chown -R %s:%s /www" % (owner, owner)) print "Adding www to supervisor..." sed("/etc/supervisor/supervisord.conf", r"files = .*", r"files = /www/*/supervisor.conf /www/supervisor.conf", use_sudo=True) print "Restarting www service..." if exists("/etc/init.d/nginx"): with settings(warn_only=True): sudo("/etc/init.d/nginx stop") sudo("/etc/init.d/nginx start") else: put_template( env.server['nginx.init'], "/etc/init.d/nginx", env.server, use_sudo=True) run("chmod 755 /etc/init.d/nginx") sudo("/etc/init.d/nginx start")