Browse Source

Merge branch 'python' of github.com:rtCamp/easyengine into python

bugfixes
harshadyeola 10 years ago
parent
commit
ee96792631
  1. 11
      config/plugins.d/info.conf
  2. 2
      ee/cli/bootstrap.py
  3. 26
      ee/cli/controllers/info.py
  4. 4
      ee/cli/plugins/clean.py
  5. 197
      ee/cli/plugins/info.py
  6. 8
      ee/cli/plugins/stack.py
  7. 9
      ee/cli/templates/info_mysql.mustache
  8. 10
      ee/cli/templates/info_nginx.mustache
  9. 35
      ee/cli/templates/info_php.mustache
  10. 4
      ee/core/download.py
  11. 2
      ee/core/extract.py
  12. 54
      ee/core/fileutils.py
  13. 6
      ee/core/git.py
  14. 13
      ee/core/services.py
  15. 6
      ee/core/shellexec.py

11
config/plugins.d/info.conf

@ -0,0 +1,11 @@
### Example Plugin Configuration for EasyEngine
[info]
### If enabled, load a plugin named `example` either from the Python module
### `ee.cli.plugins.example` or from the file path
### `/var/lib/ee/plugins/example.py`
enable_plugin = true
### Additional plugin configuration settings
foo = bar

2
ee/cli/bootstrap.py

@ -6,10 +6,8 @@
from cement.core import handler
from ee.cli.controllers.base import EEBaseController
from ee.cli.controllers.isl import EEImportslowlogController
from ee.cli.controllers.info import EEInfoController
def load(app):
handler.register(EEBaseController)
handler.register(EEInfoController)
handler.register(EEImportslowlogController)

26
ee/cli/controllers/info.py

@ -1,26 +0,0 @@
from cement.core.controller import CementBaseController, expose
class EEInfoController(CementBaseController):
class Meta:
label = 'info'
stacked_on = 'base'
stacked_type = 'nested'
description = 'info command used for debugging issued with stack or \
site specific configuration'
arguments = [
(['--mysql'],
dict(help='get mysql configuration information',
action='store_true')),
(['--php'],
dict(help='get php configuration information',
action='store_true')),
(['--nginx'],
dict(help='get nginx configuration information',
action='store_true')),
]
@expose(hide=True)
def default(self):
# TODO Default action for ee debug command
print("Inside EEInfoController.default().")

4
ee/cli/plugins/clean.py

@ -57,8 +57,8 @@ class EECleanController(CementBaseController):
else:
Log.error(self, "Memcache not installed")
except Exception as e:
Log.error(self, "Unable to restart memcached")
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to restart memcached")
@expose(hide=True)
def clean_fastcgi(self):
@ -75,8 +75,8 @@ class EECleanController(CementBaseController):
wp = urllib.request.urlopen(" https://127.0.0.1:22222/cache"
"/opcache/opgui.php?page=reset").read()
except Exception as e:
Log.error(self, "Unable to clean opacache")
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to clean opacache")
def load(app):

197
ee/cli/plugins/info.py

@ -0,0 +1,197 @@
"""EEInfo Plugin for EasyEngine."""
from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook
from pynginxconfig import NginxConfig
from ee.core.aptget import EEAptGet
from ee.core.shellexec import EEShellExec
import os
import configparser
def info_plugin_hook(app):
# do something with the ``app`` object here.
pass
class EEInfoController(CementBaseController):
class Meta:
label = 'info'
stacked_on = 'base'
stacked_type = 'nested'
description = 'info command used for debugging issued with stack or \
site specific configuration'
arguments = [
(['--mysql'],
dict(help='get mysql configuration information',
action='store_true')),
(['--php'],
dict(help='get php configuration information',
action='store_true')),
(['--nginx'],
dict(help='get nginx configuration information',
action='store_true')),
]
@expose(hide=True)
def info_nginx(self):
version = os.popen("nginx -v 2>&1 | cut -d':' -f2 | cut -d' ' -f2 | "
"cut -d'/' -f2 | tr -d '\n'").read()
allow = os.popen("grep ^allow /etc/nginx/common/acl.conf | "
"cut -d' ' -f2 | cut -d';' -f1 | tr '\n' ' '").read()
nc = NginxConfig()
nc.loadf('/etc/nginx/nginx.conf')
user = nc.get('user')[1]
worker_processes = nc.get('worker_processes')[1]
worker_connections = nc.get([('events',), 'worker_connections'])[1]
keepalive_timeout = nc.get([('http',), 'keepalive_timeout'])[1]
if os.path.isfile('/etc/nginx/conf.d/ee-nginx.conf'):
nc.loadf('/etc/nginx/conf.d/ee-nginx.conf')
fastcgi_read_timeout = nc.get('fastcgi_read_timeout')[1]
client_max_body_size = nc.get('client_max_body_size')[1]
else:
fastcgi_read_timeout = nc.get([('http',),
'fastcgi_read_timeout'])[1]
client_max_body_size = nc.get([('http',),
'client_max_body_size'])[1]
data = dict(version=version, allow=allow, user=user,
worker_processes=worker_processes,
keepalive_timeout=keepalive_timeout,
worker_connections=worker_connections,
fastcgi_read_timeout=fastcgi_read_timeout,
client_max_body_size=client_max_body_size)
self.app.render((data), 'info_nginx.mustache')
@expose(hide=True)
def info_php(self):
version = os.popen("php -v | head -n1 | cut -d' ' -f2 |"
" cut -d'+' -f1 | tr -d '\n'").read
config = configparser.ConfigParser()
config.read('/etc/php5/fpm/php.ini')
expose_php = config['PHP']['expose_php']
memory_limit = config['PHP']['memory_limit']
post_max_size = config['PHP']['post_max_size']
upload_max_filesize = config['PHP']['upload_max_filesize']
max_execution_time = config['PHP']['max_execution_time']
config.read('/etc/php5/fpm/pool.d/www.conf')
www_listen = config['www']['listen']
www_ping_path = config['www']['ping.path']
www_pm_status_path = config['www']['pm.status_path']
www_pm = config['www']['pm']
www_pm_max_requests = config['www']['pm.max_requests']
www_pm_max_children = config['www']['pm.max_children']
www_pm_start_servers = config['www']['pm.start_servers']
www_pm_min_spare_servers = config['www']['pm.min_spare_servers']
www_pm_max_spare_servers = config['www']['pm.max_spare_servers']
www_request_terminate_time = (config['www']
['request_terminate_timeout'])
try:
www_xdebug = (config['www']['php_admin_flag[xdebug.profiler_enable'
'_trigger]'])
except Exception as e:
www_xdebug = 'off'
config.read('/etc/php5/fpm/pool.d/debug.conf')
debug_listen = config['debug']['listen']
debug_ping_path = config['debug']['ping.path']
debug_pm_status_path = config['debug']['pm.status_path']
debug_pm = config['debug']['pm']
debug_pm_max_requests = config['debug']['pm.max_requests']
debug_pm_max_children = config['debug']['pm.max_children']
debug_pm_start_servers = config['debug']['pm.start_servers']
debug_pm_min_spare_servers = config['debug']['pm.min_spare_servers']
debug_pm_max_spare_servers = config['debug']['pm.max_spare_servers']
debug_request_terminate = (config['debug']
['request_terminate_timeout'])
try:
debug_xdebug = (config['debug']['php_admin_flag[xdebug.profiler_'
'enable_trigger]'])
except Exception as e:
debug_xdebug = 'off'
data = dict(version=version, expose_php=expose_php,
memory_limit=memory_limit, post_max_size=post_max_size,
upload_max_filesize=upload_max_filesize,
max_execution_time=max_execution_time,
www_listen=www_listen, www_ping_path=www_ping_path,
www_pm_status_path=www_pm_status_path, www_pm=www_pm,
www_pm_max_requests=www_pm_max_requests,
www_pm_max_children=www_pm_max_children,
www_pm_start_servers=www_pm_start_servers,
www_pm_min_spare_servers=www_pm_min_spare_servers,
www_pm_max_spare_servers=www_pm_max_spare_servers,
www_request_terminate_timeout=www_request_terminate_time,
www_xdebug_profiler_enable_trigger=www_xdebug,
debug_listen=debug_listen, debug_ping_path=debug_ping_path,
debug_pm_status_path=debug_pm_status_path,
debug_pm=debug_pm,
debug_pm_max_requests=debug_pm_max_requests,
debug_pm_max_children=debug_pm_max_children,
debug_pm_start_servers=debug_pm_start_servers,
debug_pm_min_spare_servers=debug_pm_min_spare_servers,
debug_pm_max_spare_servers=debug_pm_max_spare_servers,
debug_request_terminate_timeout=debug_request_terminate,
debug_xdebug_profiler_enable_trigger=debug_xdebug)
self.app.render((data), 'info_php.mustache')
@expose(hide=True)
def info_mysql(self):
version = os.popen("mysql -V | awk '{print($5)}' | cut -d ',' "
"-f1 | tr -d '\n'").read()
host = "localhost"
port = os.popen("mysql -e \"show variables\" | grep ^port | awk "
"'{print($2)}' | tr -d '\n'").read()
wait_timeout = os.popen("mysql -e \"show variables\" | grep "
"^wait_timeout | awk '{print($2)}' | "
"tr -d '\n'").read()
interactive_timeout = os.popen("mysql -e \"show variables\" | grep "
"^interactive_timeout | awk "
"'{print($2)}' | tr -d '\n'").read()
max_used_connections = os.popen("mysql -e \"show global status\" | "
"grep Max_used_connections | awk "
"'{print($2)}' | tr -d '\n'").read()
datadir = os.popen("mysql -e \"show variables\" | grep datadir | awk"
" '{print($2)}' | tr -d '\n'").read()
socket = os.popen("mysql -e \"show variables\" | grep \"^socket\" | "
"awk '{print($2)}' | tr -d '\n'").read()
data = dict(version=version, host=host, port=port,
wait_timeout=wait_timeout,
interactive_timeout=interactive_timeout,
max_used_connections=max_used_connections,
datadir=datadir, socket=socket)
self.app.render((data), 'info_mysql.mustache')
@expose(hide=True)
def default(self):
if (not self.app.pargs.nginx and not self.app.pargs.php
and not self.app.pargs.mysql):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.nginx:
if EEAptGet.is_installed('nginx-common'):
self.info_nginx()
else:
print("Nginx is not installed")
if self.app.pargs.php:
if EEAptGet.is_installed('php5-fpm'):
self.info_php()
else:
print("PHP5 is installed")
if self.app.pargs.mysql:
if EEShellExec.cmd_exec(self, "mysqladmin ping"):
self.info_mysql()
else:
print("MySQL is not installed")
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(EEInfoController)
# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', info_plugin_hook)

8
ee/cli/plugins/stack.py

@ -388,6 +388,14 @@ class EEStackController(CementBaseController):
Log.debug(self, "writting PHP5 configartion into "
" /etc/php5/fpm/pool.d/debug.conf")
config.write(confifile)
with open("/etc/php5/fpm/pool.d/debug.conf", "a") as myfile:
myfile.write("php_admin_value[xdebug.profiler_output_dir] "
"= /tmp/ \nphp_admin_value[xdebug.profiler_"
"output_name] = cachegrind.out.%p-%H-%R "
"\nphp_admin_flag[xdebug.profiler_enable"
"_trigger] = on \nphp_admin_flag[xdebug."
"profiler_enable] = off\n")
EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git")
EEService.reload_service(self, 'php5-fpm')

9
ee/cli/templates/info_mysql.mustache

@ -0,0 +1,9 @@
MySQL ({{version}}) on {{host}}:
port {{port}}
wait_timeout {{wait_timeout}}
interactive_timeout {{interactive_timeout}}
max_used_connections {{max_used_connections}}
datadir {{datadir}}
socket {{socket}}

10
ee/cli/templates/info_nginx.mustache

@ -0,0 +1,10 @@
NGINX ({{version}}):
user {{user}}
worker_processes {{worker_processes}}
worker_connections {{worker_connections}}
keepalive_timeout {{keepalive_timeout}}
fastcgi_read_timeout {{fastcgi_read_timeout}}
client_max_body_size {{client_max_body_size}}
allow {{allow}}

35
ee/cli/templates/info_php.mustache

@ -0,0 +1,35 @@
PHP ({{version}}):
user {{user}}
expose_php {{expose_php}}
memory_limit {{memory_limit}}
post_max_size {{post_max_size}}
upload_max_filesize {{upload_max_filesize}}
max_execution_time {{max_execution_time}}
Information about www.conf
ping.path {{www_ping_path}}
pm.status_path {{www_pm_status_path}}
process_manager {{www_pm}}
pm.max_requests {{www_pm_max_requests}}
pm.max_children {{www_pm_max_children}}
pm.start_servers {{www_pm_start_servers}}
pm.min_spare_servers {{www_pm_min_spare_servers}}
pm.max_spare_servers {{www_pm_max_spare_servers}}
request_terminate_timeout {{www_request_terminate_timeout}}
xdebug.profiler_enable_trigger {{www_xdebug_profiler_enable_trigger}}
listen {{www_listen}}
Information about debug.conf
ping.path {{debug_ping_path}}
pm.status_path {{debug_pm_status_path}}
process_manager {{debug_pm}}
pm.max_requests {{debug_pm_max_requests}}
pm.max_children {{debug_pm_max_children}}
pm.start_servers {{debug_pm_start_servers}}
pm.min_spare_servers {{debug_pm_min_spare_servers}}
pm.max_spare_servers {{debug_pm_max_spare_servers}}
request_terminate_timeout {{debug_request_terminate_timeout}}
xdebug.profiler_enable_trigger {{debug_xdebug_profiler_enable_trigger}}
listen {{debug_listen}}

4
ee/core/download.py

@ -22,9 +22,9 @@ class EEDownload():
Log.info(self, "Downloading "+pkg_name+" ...")
urllib.request.urlretrieve(url, filename)
except urllib.error.URLError as e:
Log.debug(self, "[{err}]".format(err=str(e.reason)))
Log.error(self, "Unable to donwload file, {0}"
.format(filename))
Log.debug(self, "[{err}]".format(err=str(e.reason)))
return False
except urllib.error.HTTPError as e:
Log.error(self, "Package download failed. {0}"
@ -32,8 +32,8 @@ class EEDownload():
Log.debug(self, "[{err}]".format(err=str(e.reason)))
return False
except urllib.error.ContentTooShortError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Package download failed. The amount of the"
" downloaded data is less than "
"the expected amount \{0} ".format(pkg_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False

2
ee/core/extract.py

@ -15,6 +15,6 @@ class EEExtract():
os.remove(file)
return True
except tarfile.TarError as e:
Log.error(self, 'Unable to extract file \{0}'.format(file))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, 'Unable to extract file \{0}'.format(file))
return False

54
ee/core/fileutils.py

@ -24,9 +24,8 @@ class EEFileUtils():
Log.info(self, "Removing "+os.path.basename(file)+"...")
shutil.rmtree(file)
except shutil.Error as e:
Log.error(self, 'Unable to Remove file ')
Log.debug(self, "{err}".format(err=str(e.reason)))
sys.exit(1)
Log.error(self, 'Unable to Remove file ')
def create_symlink(self, paths, errormsg=''):
src = paths[0]
@ -35,9 +34,8 @@ class EEFileUtils():
try:
os.symlink(src, dst)
except Exception as e:
Log.error(self, "Unable to create symbolic link ...\n ")
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1)
Log.error(self, "Unable to create symbolic link ...\n ")
else:
Log.debug(self, "Destination: {0} exists".format(dst))
@ -45,21 +43,20 @@ class EEFileUtils():
try:
os.unlink(filepath)
except Exception as e:
Log.error(self, "Unable to reomove symbolic link ...\n")
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1)
Log.error(self, "Unable to reomove symbolic link ...\n")
def copyfile(self, src, dest):
try:
shutil.copy2(src, dest)
except shutil.Error as e:
Log.debug(self, "{0}".format(e))
Log.error(self, 'Unable to copy file from {0} to {1}'
.format(src, dest))
Log.debug(self, "{0}".format(e))
except IOError as e:
Log.debug(self, "{e}".format(e.strerror))
Log.error(self, "Unable to copy file from {0} to {1}"
.fromat(src, dest))
Log.debug(self, "{e}".format(e.strerror))
def searchreplace(self, fnm, sstr, rstr):
try:
@ -67,26 +64,24 @@ class EEFileUtils():
print(line.replace(sstr, rstr), end='')
fileinput.close()
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to search {0} and replace {1} {2}"
.format(fnm, sstr, rstr))
Log.debug(self, "{0}".format(e))
def mvfile(self, src, dst):
try:
shutil.move(src, dst)
except shutil.Error as e:
Log.debug(self, "{err}".format(err=str(e.reason)))
Log.error(self, 'Unable to move file from {0} to {1}'
.format(src, dst))
Log.debug(self, "{err}".format(err=str(e.reason)))
sys.exit(1)
def chdir(self, path):
try:
os.chdir(path)
except OSError as e:
Log.error(self, 'Unable to Change Directory {0}'.format(path))
Log.debug(self, "{err}".format(err=e.strerror))
sys.exit(1)
Log.error(self, 'Unable to Change Directory {0}'.format(path))
def chown(self, path, user, group, recursive=False):
try:
@ -101,13 +96,11 @@ class EEFileUtils():
else:
shutil.chown(path, user=user, group=group)
except shutil.Error as e:
Log.error(self, "Unable to change owner : {0}".format(path))
Log.debug(self, "{0}".format(e))
sys.exit(1)
Log.error(self, "Unable to change owner : {0}".format(path))
except Exception as e:
Log.error(self, "Unable to change owner : {0} ".format(path))
Log.debug(self, "{0}".format(e))
sys.exit(1)
Log.error(self, "Unable to change owner : {0} ".format(path))
def chmod(self, path, perm, recursive=False):
try:
@ -120,17 +113,15 @@ class EEFileUtils():
else:
os.chmod(path, perm)
except OSError as e:
Log.error(self, "Unable to change owner : {0}".format(path))
Log.debug(self, "{0}".format(e.strerror))
sys.exit(1)
Log.error(self, "Unable to change owner : {0}".format(path))
def mkdir(self, path):
try:
os.makedirs(path)
except OSError as e:
Log.error(self, "Unable to create directory {0} ".format(path))
Log.debug(self, "{0}".format(e.strerror))
sys.exit(1)
Log.error(self, "Unable to create directory {0} ".format(path))
def isexist(self, path):
try:
@ -139,9 +130,8 @@ class EEFileUtils():
else:
return (False)
except OSError as e:
Log.error(self, "Unable to check path {0}".format(path))
Log.debug(self, "{0}".format(e.strerror))
sys.exit(1)
Log.error(self, "Unable to check path {0}".format(path))
def grep(self, fnm, sstr):
try:
@ -149,9 +139,9 @@ class EEFileUtils():
if sstr in line:
return line
except OSError as e:
Log.error(self, "Unable to Search string {0}{1}"
.format(e.strerror, "[FAIL]"))
sys.exit(1)
Log.debug(self, "{0}".format(e.strerror))
Log.error(self, "Unable to Search string {0} in {1}"
.format(sstr, fnm))
def rm(self, path):
if EEFileUtils.isexist(self, path):
@ -161,10 +151,10 @@ class EEFileUtils():
else:
os.remove(path)
except shutil.Error as e:
Log.error(self, "Unable to remove directory : {0} {1}"
.format(path, e))
sys.exit(1)
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to remove directory : {0} "
.format(path))
except OSError as e:
Log.error(self, "Unable to remove file : {0} {1}"
.format(path, e))
sys.exit(1)
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to remove file : {0} "
.format(path))

6
ee/core/git.py

@ -21,10 +21,9 @@ class EEGit:
.format(path))
git.init(path)
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to git init at {0}"
.format(path))
Log.error(self, "{0}".format(e))
sys.exit(1)
status = git.status("-s")
if len(status.splitlines()) > 0:
try:
@ -33,10 +32,9 @@ class EEGit:
git.add("--all")
git.commit("-am {0}".format(msg))
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to git commit at {0} "
.format(path))
Log.debug(self, "{0}".format(e))
sys.exit(1)
else:
Log.debug(self, "EEGit: Path {0} not present".format(path))

13
ee/core/services.py

@ -23,9 +23,9 @@ class EEService():
else:
Log.error(self, retcode[1])
except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Failed to start service {0}"
.format(service_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False
def stop_service(self, service_name):
@ -39,9 +39,9 @@ class EEService():
else:
return False
except OSError as e:
Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
Log.error(self, "Failed to stop service : {0}"
.format(service_name))
Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
return False
def restart_service(self, service_name):
@ -51,9 +51,9 @@ class EEService():
Log.info(self, "restart : {0:10}{1}"
.format(service_name, "[OK]"))
except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Failed to restart services \{0}"
.format(service_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
def reload_service(self, service_name):
try:
@ -67,8 +67,8 @@ class EEService():
.format(service_name, "[OK]"))
return True
else:
Log.error(self, "reload : {0}".format(service_name))
Log.debug("{0}".format(retcode[1]))
Log.error(self, "reload : {0}".format(service_name))
return False
retcode = subprocess.getstatusoutput('service {0} reload'
@ -80,10 +80,9 @@ class EEService():
else:
return False
except OSError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Failed to reload service {0}"
.format(service_name))
Log.debug(self, "{0}".format(e))
sys.exit(1)
def get_service_status(self, service_name):
try:
@ -99,7 +98,7 @@ class EEService():
else:
return False
except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Unable to get services status of {0}"
.format(service_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False

6
ee/core/shellexec.py

@ -24,10 +24,9 @@ class EEShellExec():
if errormsg:
Log.error(self, errormsg)
else:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Unable to execute command {0}"
.format(command))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1)
def invoke_editor(self, filepath, errormsg=''):
try:
@ -36,6 +35,5 @@ class EEShellExec():
if errormsg:
Log.error(self, errormsg)
else:
Log.error(self, "Unable to edit file {0}".format(filepath))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1)
Log.error(self, "Unable to edit file {0}".format(filepath))

Loading…
Cancel
Save