diff --git a/config/plugins.d/clean.conf b/config/plugins.d/clean.conf new file mode 100644 index 00000000..be834348 --- /dev/null +++ b/config/plugins.d/clean.conf @@ -0,0 +1,8 @@ +### Example Plugin Configuration for EasyEngine + +[clean] + +### 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 diff --git a/ee/cli/bootstrap.py b/ee/cli/bootstrap.py index 07250f46..8fee5c47 100644 --- a/ee/cli/bootstrap.py +++ b/ee/cli/bootstrap.py @@ -5,7 +5,6 @@ from cement.core import handler from ee.cli.controllers.base import EEBaseController -from ee.cli.controllers.clean import EECleanController from ee.cli.controllers.secure import EESecureController from ee.cli.controllers.isl import EEImportslowlogController from ee.cli.controllers.info import EEInfoController @@ -13,7 +12,6 @@ from ee.cli.controllers.info import EEInfoController def load(app): handler.register(EEBaseController) - handler.register(EECleanController) handler.register(EEInfoController) handler.register(EEImportslowlogController) handler.register(EESecureController) diff --git a/ee/cli/controllers/clean.py b/ee/cli/controllers/clean.py deleted file mode 100644 index 52b9afdf..00000000 --- a/ee/cli/controllers/clean.py +++ /dev/null @@ -1,41 +0,0 @@ -"""EasyEngine site controller.""" - -from cement.core.controller import CementBaseController, expose - - -class EECleanController(CementBaseController): - class Meta: - label = 'clean' - stacked_on = 'base' - stacked_type = 'nested' - description = 'clean command cleans different cache with following \ - options' - arguments = [ - (['--all'], - dict(help='clean all cache', action='store_true')), - (['--fastcgi'], - dict(help='clean fastcgi cache', action='store_true')), - (['--memcache'], - dict(help='clean memcache', action='store_true')), - (['--opcache'], - dict(help='clean opcode cache cache', action='store_true')) - ] - - @expose(hide=True) - def default(self): - # TODO Default action for ee clean command here - print("Inside EECleanController.default().") - - # clean command Options and subcommand calls and definations to - # mention here - - # If using an output handler such as 'mustache', you could also - # render a data dictionary using a template. For example: - # - # data = dict(foo='bar') - # self.app.render(data, 'default.mustache') - # - # - # The 'default.mustache' file would be loaded from - # ``ee.cli.templates``, or ``/var/lib/ee/templates/``. - # diff --git a/ee/cli/plugins/clean.py b/ee/cli/plugins/clean.py new file mode 100644 index 00000000..02444987 --- /dev/null +++ b/ee/cli/plugins/clean.py @@ -0,0 +1,83 @@ +from ee.core.shellexec import EEShellExec +from ee.core.aptget import EEAptGet +from ee.core.services import EEService +from cement.core.controller import CementBaseController, expose +from cement.core import handler, hook +import os + + +def clean_plugin_hook(app): + # do something with the ``app`` object here. + pass + + +class EECleanController(CementBaseController): + class Meta: + label = 'clean' + stacked_on = 'base' + stacked_type = 'nested' + description = 'clean command cleans different cache with following \ + options' + arguments = [ + (['--all'], + dict(help='clean all cache', action='store_true')), + (['--fastcgi'], + dict(help='clean fastcgi cache', action='store_true')), + (['--memcache'], + dict(help='clean memcache', action='store_true')), + (['--opcache'], + dict(help='clean opcode cache cache', action='store_true')) + ] + + @expose(hide=True) + def default(self): + # TODO Default action for ee clean command here + if (not (self.app.pargs.all or self.app.pargs.fastcgi or + self.app.pargs.memcache or self.app.pargs.opcache)): + self.clean_fastcgi() + if self.app.pargs.all: + self.clean_memcache() + self.clean_fastcgi() + self.clean_opcache() + if self.app.pargs.fastcgi: + self.clean_fastcgi() + if self.app.pargs.memcache: + self.clean_memcache() + if self.app.pargs.opcache: + self.clean_opcache() + + @expose(hide=True) + def clean_memcache(self): + print("in memcache..") + pkg = EEAptGet() + if(pkg.is_installed("memcached")): + print("memcache is installed...") + EEService.restart_service(self, "memcached") + print("Cleaning memcache..") + else: + print("memcache is not installed..") + + @expose(hide=True) + def clean_fastcgi(self): + if(os.path.isdir("/var/run/nginx-cache")): + print("Cleaning fastcgi...") + EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*") + else: + print("Error occur while Cleaning fastcgi..") + + @expose(hide=True) + def clean_opcache(self): + try: + print("Cleaning opcache.... ") + EEShellExec.cmd_exec(self, "wget --no-check-certificate --spider" + " -q https://127.0.0.1:22222/cache/opcache" + "/opgui.php?page=reset") + except OSError: + print("Unable to clean opache..") + + +def load(app): + # register the plugin class.. this only happens if the plugin is enabled + handler.register(EECleanController) + # register a hook (function) to run after arguments are parsed. + hook.register('post_argument_parsing', clean_plugin_hook) diff --git a/ee/core/services.py b/ee/core/services.py index e6b8de58..615e65fe 100644 --- a/ee/core/services.py +++ b/ee/core/services.py @@ -38,8 +38,8 @@ class EEService(): def restart_service(self, service_name): try: - EEService.stop_service(service_name) - EEService.start_service(service_name) + EEService.stop_service(self, service_name) + EEService.start_service(self, service_name) except OSError as e: self.app.log.error("Execution failed:", e)