Skip to content

Instantly share code, notes, and snippets.

@n3dst4
Forked from robflaherty/nginx-0765-installer.txt
Created March 26, 2011 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n3dst4/888154 to your computer and use it in GitHub Desktop.
Save n3dst4/888154 to your computer and use it in GitHub Desktop.
Webfaction install script for nginx 0.8.54
-----BEGIN WEBFACTION INSTALL SCRIPT-----
#!/bin/env python2.7
"""
Nginx 0.8.54 Installer New
"autostart": not applicable
"extra info": Enter domain name for the nginx app
"""
import sys
import xmlrpclib
import os
import re
def create(server, session_id, account, username, app_name, autostart, extra_info):
#Create app
app = server.create_app(
session_id,
app_name,
'custom_app_with_port',
False,
'',)
#Retrieve, extract
cmd = """\
wget http://sysoev.ru/nginx/nginx-0.8.54.tar.gz > /dev/null 2>&1;
tar -xzf nginx-0.8.54.tar.gz
"""
server.system(session_id, cmd)
#Configure, make, install, remove
cmd = """\
cd nginx-0.8.54
./configure --prefix=$HOME/webapps/%s --with-http_ssl_module
make && make install
cd ..
rm -fr nginx-0.7.65*
""" % (app_name)
try:
server.system(session_id, cmd)
except xmlrpclib.Fault, e:
if "deprecated" not in e.faultString:
raise e
#Edit Nginx config
conf_filename = "{0}/webapps/{1}/conf/nginx.conf".format(
os.environ["HOME"],
app_name
)
conf_text = '';
with open(conf_filename) as conf_file:
conf_text = re.sub(
r'listen\s+80',
'listen {0}'.format(str(app['port'])),
conf_file.read())
with open(conf_filename, 'w') as conf_file:
conf_file.write(conf_text)
cmd = """\
cd ~/webapps/%s
./sbin/nginx
""" % (app_name)
server.system(session_id, cmd)
print app['id']
def delete(server, session_id, account, username, app_name, autostart, extra_info):
# Delete app
server.delete_app(app_name)
if __name__ == '__main__':
# Parse command line arguments
command, username, password, machine, app_name, autostart, extra_info = sys.argv[1:]
# Connect to API server
url = 'https://api.webfaction.com/'
server = xmlrpclib.ServerProxy(url)
# Login
session_id, account = server.login(username, password, machine)
# Call create or delete method
method = locals()[command] # create or delete
method(server, session_id, account, username, app_name, autostart, extra_info)
-----END WEBFACTION INSTALL SCRIPT-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment