Skip to content

Instantly share code, notes, and snippets.

@mihow
Forked from robflaherty/nginx-0765-installer.txt
Created April 23, 2011 01:04
Show Gist options
  • Save mihow/938071 to your computer and use it in GitHub Desktop.
Save mihow/938071 to your computer and use it in GitHub Desktop.
Nginx 1.0.0 installer for Webfaction
-----BEGIN WEBFACTION INSTALL SCRIPT-----
#!/bin/env python2.6
VERSION = "1.0.0"
"""
Nginx Installer
"autostart": not applicable
"extra info": Enter domain name for the nginx app
"""
import sys
from webfaction.api import *
def create(api, app_name, app_domain):
#Create app
app = api.create_app(app_name, 'custom_app_with_port')
#Retrieve, extract
cmd = """\
wget http://sysoev.ru/nginx/nginx-%s.tar.gz > /dev/null 2>&1;
tar -xzf nginx-%s.tar.gz
""" % (VERSION, VERSION)
api.system(cmd)
#Configure, make, install, remove
cmd = """\
cd nginx-%s
./configure --prefix=$HOME/webapps/%s/nginx --with-http_ssl_module
make && make install
cd ..
rm -fr nginx-%s*
""" % (VERSION, app_name, VERSION)
api.system(cmd)
#Edit Nginx config
cmd = """\
sed -i 's/listen 80/listen %s/' $HOME/webapps/%s/nginx/conf/nginx.conf
sed -i 's/localhost/%s/' $HOME/webapps/%s/nginx/conf/nginx.conf
""" % (app['port'], app_name, app_domain, app_name)
api.system(cmd)
cmd = """\
cd ~/webapps/%s
./nginx/sbin/nginx
""" % (app_name)
api.system(cmd)
print app['id']
def delete(api, app_name, app_domain):
# Delete app
api.delete_app(app_name)
if __name__ == '__main__':
action, username, password, server, app_name, autostart, extra_info = \
sys.argv[1:]
api = API(username, password, server)
if extra_info:
app_domain = extra_info
else:
app_domain = 'www.example.com'
try:
locals()[action](api, app_name, app_domain)
except APIError, e:
print e
sys.exit()
-----END WEBFACTION INSTALL SCRIPT-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment