Browse Source

creating symbolic link

bugfixes
harshadyeola 10 years ago
parent
commit
bf93dd33e1
  1. 47
      ee/cli/plugins/site.py
  2. 56
      ee/cli/templates/virtualconf.mustache
  3. 9
      ee/core/fileutils.py

47
ee/cli/plugins/site.py

@ -2,6 +2,7 @@
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.domainvalidate import validate_domain from ee.core.domainvalidate import validate_domain
from ee.core.fileutils import EEFileUtils
import sys import sys
@ -111,11 +112,12 @@ class EESiteCreateController(CementBaseController):
# 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)
# 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
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
or self.app.pargs.wpfc or self.app.pargs.wpsc or or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wsubdir or self.app.pargs.wsubdomain)): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
data = dict(site_name=self.app.pargs.site_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)
@ -124,7 +126,7 @@ class EESiteCreateController(CementBaseController):
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
or self.app.pargs.wpfc or self.app.pargs.wpsc or or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wsubdir or self.app.pargs.wsubdomain)): self.app.pargs.wsubdir or self.app.pargs.wsubdomain)):
data = dict(site_name=self.app.pargs.site_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)
@ -133,7 +135,7 @@ class EESiteCreateController(CementBaseController):
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
or self.app.pargs.wpfc or self.app.pargs.wpsc or or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wsubdir or self.app.pargs.wsubdomain)): self.app.pargs.wsubdir or self.app.pargs.wsubdomain)):
data = dict(site_name=self.app.pargs.site_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)
@ -144,25 +146,25 @@ class EESiteCreateController(CementBaseController):
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)): self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if (self.app.pargs.wp and not (self.app.pargs.w3tc if (self.app.pargs.wp and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)): or self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=self.app.pargs.site_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)
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=self.app.pargs.site_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)
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=self.app.pargs.site_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)
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=self.app.pargs.site_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)
@ -172,25 +174,25 @@ class EESiteCreateController(CementBaseController):
self.app.pargs.wpsubdomain or self.app.pargs.wp)): self.app.pargs.wpsubdomain or self.app.pargs.wp)):
if (self.app.pargs.wpsubdir and not (self.app.pargs.w3tc if (self.app.pargs.wpsubdir and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)): or self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=self.app.pargs.site_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)
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=self.app.pargs.site_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)
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=self.app.pargs.site_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)
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=self.app.pargs.site_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)
@ -200,38 +202,47 @@ class EESiteCreateController(CementBaseController):
self.app.pargs.wpsubdir or self.app.pargs.wp)): self.app.pargs.wpsubdir or self.app.pargs.wp)):
if (self.app.pargs.wpsubdomain and not (self.app.pargs.w3tc if (self.app.pargs.wpsubdomain and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)): or self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=self.app.pargs.site_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)
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=self.app.pargs.site_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)
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=self.app.pargs.site_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)
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=self.app.pargs.site_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)
try: try:
ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}.conf' ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}.conf'
.format(self.app.pargs.site_name), 'w') .format(ee_domain_name), 'w')
self.app.render((data), 'virtualconf.mustache', self.app.render((data), 'virtualconf.mustache',
out=ee_site_nginx_conf) out=ee_site_nginx_conf)
ee_site_nginx_conf.close() 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: except Exception as e:
print("Select proper options for creating site") 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):

56
ee/cli/templates/virtualconf.mustache

@ -1,32 +1,32 @@
server { server {
{{#multisite}} {{#multisite}}
# Uncomment the following line for domain mapping # Uncomment the following line for domain mapping
# listen 80 default_server; # listen 80 default_server;
{{/multisite}} {{/multisite}}
server_name {{site_name}} {{#multisite}}*{{/multisite}}{{^multisite}}www{{/multisite}}.{{site_name}}; server_name {{site_name}} {{#multisite}}*{{/multisite}}{{^multisite}}www{{/multisite}}.{{site_name}};
{{#multisite}} {{#multisite}}
# Uncomment the following line for domain mapping # Uncomment the following line for domain mapping
#server_name_in_redirect off; #server_name_in_redirect off;
{{/multisite}} {{/multisite}}
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 /var/www/{{site_name}}/htdocs;
index {{^static}}index.php{{/static}} index.html index.htm; index {{^static}}index.php{{/static}} index.html index.htm;
{{#static}} {{#static}}
location / { location / {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
} }
{{/static}} {{/static}}
{{^static}}include{{/static}} {{#basic}}common/php.conf;{{/basic}}{{#w3tc}}common/w3tc.conf;{{/w3tc}}{{#wpfc}}common/wpfc.conf;{{/wpfc}} {{#wpsc}}common/wpsc.conf;{{/wpsc}} {{^static}}include{{/static}} {{#basic}}common/php.conf;{{/basic}}{{#w3tc}}common/w3tc.conf;{{/w3tc}}{{#wpfc}}common/wpfc.conf;{{/wpfc}} {{#wpsc}}common/wpsc.conf;{{/wpsc}}
{{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}} {{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}
{{#wp}}include common/wpcommon.conf;{{/wp}} {{#wp}}include common/wpcommon.conf;{{/wp}}
include common/locations.conf; include common/locations.conf;
} }

9
ee/core/fileutils.py

@ -1,6 +1,7 @@
"""EasyEngine file utils core classes.""" """EasyEngine file utils core classes."""
import shutil import shutil
import os import os
import glob
class EEFileUtils(): class EEFileUtils():
@ -23,3 +24,11 @@ class EEFileUtils():
print("Unable to remove file, [{err}]" print("Unable to remove file, [{err}]"
.format(err=str(e.reason))) .format(err=str(e.reason)))
return False return False
def create_symlink(paths):
src = paths[0]
dst = paths[1]
try:
os.symlink(src, dst)
except Exception as e:
print("Unable to create sybolic link for {0}".format(e))

Loading…
Cancel
Save