Browse Source

ee domain setup module

bugfixes
harshadyeola 10 years ago
parent
commit
5982ea7e76
  1. 22
      config/ee.conf
  2. 62
      ee/cli/plugins/site.py
  3. 53
      ee/cli/plugins/site_functions.py
  4. 2
      ee/cli/templates/virtualconf.mustache
  5. 10
      ee/core/fileutils.py
  6. 2
      ee/core/variables.py

22
config/ee.conf

@ -37,3 +37,25 @@
### The maximun number of log files to maintain when rotating ### The maximun number of log files to maintain when rotating
# max_files = 4 # max_files = 4
[stack]
# ip-address =
[mysql]
grant-host = localhost
db-name = false
db-user = false
[wordpress]
prefix = false
user =
password =
email =

62
ee/cli/plugins/site.py

@ -1,9 +1,12 @@
"""EasyEngine site controller.""" """EasyEngine site controller."""
from cement.core.controller import CementBaseController, expose from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook from cement.core import handler, hook
from ee.core.variables import EEVariables
from ee.core.domainvalidate import validate_domain from ee.core.domainvalidate import validate_domain
from ee.core.fileutils import EEFileUtils from ee.core.fileutils import EEFileUtils
from ee.cli.plugins.site_functions import setup_domain
import sys import sys
import os
def ee_site_hook(app): def ee_site_hook(app):
@ -111,6 +114,14 @@ class EESiteCreateController(CementBaseController):
# self.app.render((data), 'default.mustache') # self.app.render((data), 'default.mustache')
# Check domain name validation # Check domain name validation
ee_domain_name = validate_domain(self.app.pargs.site_name) ee_domain_name = validate_domain(self.app.pargs.site_name)
ee_site_webroot = EEVariables.ee_webroot + ee_domain_name
# Check if doain previously exists or not
if os.path.isfile('/etc/nginx/sites-available/{0}.conf'
.format(ee_domain_name)):
self.app.log.error("site {0} already exists"
.format(ee_domain_name))
return False
# setup nginx configuration for site # setup nginx configuration for site
if (self.app.pargs.html and not (self.app.pargs.php or if (self.app.pargs.html and not (self.app.pargs.php or
@ -120,7 +131,7 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=True, basic=False, wp=False, w3tc=False, static=True, basic=False, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.php and not (self.app.pargs.html or if (self.app.pargs.php and not (self.app.pargs.html or
self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc
@ -129,7 +140,7 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=False, w3tc=False, static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.mysql and not (self.app.pargs.html or if (self.app.pargs.mysql and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.wp or self.app.pargs.w3tc self.app.pargs.php or self.app.pargs.wp or self.app.pargs.w3tc
@ -138,7 +149,7 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=False, w3tc=False, static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or
self.app.pargs.wpsc) and not (self.app.pargs.html or self.app.pargs.wpsc) and not (self.app.pargs.html or
@ -149,25 +160,25 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=False, wpfc=False, wpsc=False, multisite=False,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=False, wpfc=True, wpsc=False, multisite=False,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=False, wpfc=False, wpsc=True, multisite=False,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.wpsubdir and not (self.app.pargs.html or if (self.app.pargs.wpsubdir and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.php or self.app.pargs.mysql or
@ -177,25 +188,25 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=True) wpsubdir=True, webroot=ee_site_webroot)
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=True) wpsubdir=True, webroot=ee_site_webroot)
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True, wpfc=True, wpsc=False, multisite=True,
wpsubdir=True) wpsubdir=True, webroot=ee_site_webroot)
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True, wpfc=False, wpsc=True, multisite=True,
wpsubdir=True) wpsubdir=True, webroot=ee_site_webroot)
if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or self.app.pargs.php or self.app.pargs.mysql or
@ -205,44 +216,27 @@ class EESiteCreateController(CementBaseController):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=True, wp=True, w3tc=False, static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.w3tc and not if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)): (self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=True, static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True, wpfc=False, wpsc=False, multisite=True,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.wpfc and not if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)): (self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True, wpfc=True, wpsc=False, multisite=True,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
if (self.app.pargs.wpsc and not if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)): (self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain_name, data = dict(site_name=ee_domain_name,
static=False, basic=False, wp=True, w3tc=False, static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True, wpfc=False, wpsc=True, multisite=True,
wpsubdir=False) wpsubdir=False, webroot=ee_site_webroot)
try: setup_domain(self, data)
ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}.conf'
.format(ee_domain_name), 'w')
self.app.render((data), 'virtualconf.mustache',
out=ee_site_nginx_conf)
ee_site_nginx_conf.close()
except IOError as e:
print("Unable to create nginx conf for {2} ({0}): {1}"
.format(e.errno, e.strerror))
except Exception as e:
print("{0}".format(e))
# create symbolic link
EEFileUtils.create_symlink(['/etc/nginx/sites-available/{0}.conf'
.format(ee_domain_name),
'/etc/nginx/sites-enabled/{0}.conf'
.format(ee_domain_name)])
class EESiteUpdateController(CementBaseController): class EESiteUpdateController(CementBaseController):

53
ee/cli/plugins/site_functions.py

@ -0,0 +1,53 @@
import os
from ee.core.fileutils import EEFileUtils
def setup_domain(self, data):
ee_domain_name = data['site_name']
ee_site_webroot = data['webroot']
print("Creating {0}, please wait...".format(ee_domain_name))
# write nginx config for file
try:
ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}.conf'
.format(ee_domain_name), 'w')
self.app.render((data), 'virtualconf.mustache',
out=ee_site_nginx_conf)
ee_site_nginx_conf.close()
except IOError as e:
print("Unable to create nginx conf for {2} ({0}): {1}"
.format(e.errno, e.strerror))
except Exception as e:
print("{0}".format(e))
# create symbolic link for
EEFileUtils.create_symlink(['/etc/nginx/sites-available/{0}.conf'
.format(ee_domain_name),
'/etc/nginx/sites-enabled/{0}.conf'
.format(ee_domain_name)])
# Creating htdocs & logs directory
try:
if not os.path.exists('{0}/htdocs'.format(ee_site_webroot)):
os.makedirs('{0}/htdocs'.format(ee_site_webroot))
if not os.path.exists('{0}/logs'.format(ee_site_webroot)):
os.makedirs('{0}/logs'.format(ee_site_webroot))
except Exception as e:
print("{0}".format(e))
EEFileUtils.create_symlink(['/var/log/nginx/{0}.access.log'
.format(ee_domain_name),
'{0}/logs/access.log'
.format(ee_site_webroot)])
EEFileUtils.create_symlink(['/var/log/nginx/{0}.error.log'
.format(ee_domain_name),
'{0}/logs/error.log'
.format(ee_site_webroot)])
def setup_database(self, data):
ee_domain_name = data['site_name']
ee_random = (''.join(random.sample(string.ascii_uppercase +
string.ascii_lowercase + string.digits, 64)))
ee_replace_dot = ee_domain_name.replace('.', '_')

2
ee/cli/templates/virtualconf.mustache

@ -15,7 +15,7 @@ server {
access_log /var/log/nginx/{{site_name}}.access.log {{^static}}rt_cache{{/static}}; access_log /var/log/nginx/{{site_name}}.access.log {{^static}}rt_cache{{/static}};
error_log /var/log/nginx/{{site_name}}.error.log; error_log /var/log/nginx/{{site_name}}.error.log;
root /var/www/{{site_name}}/htdocs; root {{webroot}}/htdocs;
index {{^static}}index.php{{/static}} index.html index.htm; index {{^static}}index.php{{/static}} index.html index.htm;

10
ee/core/fileutils.py

@ -31,4 +31,12 @@ class EEFileUtils():
try: try:
os.symlink(src, dst) os.symlink(src, dst)
except Exception as e: except Exception as e:
print("Unable to create sybolic link for {0}".format(e)) print("Unable to create symbolic link ...\n {0} "
.format(e.reason))
def remove_symlink(filepath):
try:
os.unlink(path)
except Exception as e:
print("Unable to reomove symbolic link ...\n {0} "
.format(e.reason))

2
ee/core/variables.py

@ -20,6 +20,8 @@ class EEVariables():
# Get FQDN of system # Get FQDN of system
ee_fqdn = socket.getfqdn() ee_fqdn = socket.getfqdn()
ee_webroot = '/var/www/'
# Get git user name and EMail # Get git user name and EMail
try: try:
ee_user = config['user']['name'] ee_user = config['user']['name']

Loading…
Cancel
Save