-
-
Save n3dst4/888154 to your computer and use it in GitHub Desktop.
Webfaction install script for nginx 0.8.54
This file contains hidden or 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
-----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