2018-11-13 21:55:59 +01:00
|
|
|
from cement.core.controller import CementBaseController, expose
|
|
|
|
|
from cement.core import handler, hook
|
|
|
|
|
from wo.core.services import WOService
|
|
|
|
|
from wo.core.logging import Log
|
|
|
|
|
from wo.core.variables import WOVariables
|
|
|
|
|
from wo.core.aptget import WOAptGet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WOStackStatusController(CementBaseController):
|
|
|
|
|
class Meta:
|
|
|
|
|
label = 'stack_services'
|
|
|
|
|
stacked_on = 'stack'
|
|
|
|
|
stacked_type = 'embedded'
|
|
|
|
|
description = 'Check the stack status'
|
|
|
|
|
arguments = [
|
2019-03-07 13:15:15 +01:00
|
|
|
(['--memcached'],
|
|
|
|
|
dict(help='start/stop/restart memcached', action='store_true')),
|
2019-03-02 20:38:31 +01:00
|
|
|
]
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
@expose(help="Start stack services")
|
|
|
|
|
def start(self):
|
|
|
|
|
"""Start services"""
|
|
|
|
|
services = []
|
2019-03-13 05:02:53 +01:00
|
|
|
if not (self.app.pargs.nginx or self.app.pargs.php or
|
|
|
|
|
self.app.pargs.php73 or
|
|
|
|
|
self.app.pargs.mysql or
|
|
|
|
|
self.app.pargs.memcached or
|
|
|
|
|
self.app.pargs.redis):
|
2018-11-13 21:55:59 +01:00
|
|
|
self.app.pargs.nginx = True
|
|
|
|
|
self.app.pargs.php = True
|
|
|
|
|
self.app.pargs.mysql = True
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.nginx:
|
2019-03-02 20:38:31 +01:00
|
|
|
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['nginx']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Nginx is not installed")
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.php:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.2-fpm'):
|
|
|
|
|
services = services + ['php7.2-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.2-FPM is not installed")
|
|
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2019-03-02 20:38:31 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.php73:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.mysql:
|
|
|
|
|
if ((WOVariables.wo_mysql_host is "localhost") or
|
2019-03-02 20:38:31 +01:00
|
|
|
(WOVariables.wo_mysql_host is "127.0.0.1")):
|
2018-11-13 21:55:59 +01:00
|
|
|
if (WOAptGet.is_installed(self, 'mysql-server') or
|
2019-03-02 20:38:31 +01:00
|
|
|
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
|
|
|
|
|
WOAptGet.is_installed(self, 'mariadb-server')):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['mysql']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "MySQL is not installed")
|
|
|
|
|
else:
|
|
|
|
|
Log.warn(self, "Remote MySQL found, "
|
|
|
|
|
"Unable to check MySQL service status")
|
|
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if self.app.pargs.memcached:
|
2018-11-13 21:55:59 +01:00
|
|
|
if WOAptGet.is_installed(self, 'memcached'):
|
|
|
|
|
services = services + ['memcached']
|
|
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "Memcached is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.redis:
|
|
|
|
|
if WOAptGet.is_installed(self, 'redis-server'):
|
|
|
|
|
services = services + ['redis-server']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Redis server is not installed")
|
|
|
|
|
|
|
|
|
|
for service in services:
|
|
|
|
|
Log.debug(self, "Starting service: {0}".format(service))
|
|
|
|
|
WOService.start_service(self, service)
|
|
|
|
|
|
|
|
|
|
@expose(help="Stop stack services")
|
|
|
|
|
def stop(self):
|
|
|
|
|
"""Stop services"""
|
|
|
|
|
services = []
|
2019-03-02 20:38:31 +01:00
|
|
|
if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73
|
2019-03-13 05:02:53 +01:00
|
|
|
or self.app.pargs.mysql or self.app.pargs.memcached
|
2018-11-13 21:55:59 +01:00
|
|
|
or self.app.pargs.redis):
|
|
|
|
|
self.app.pargs.nginx = True
|
|
|
|
|
self.app.pargs.php = True
|
|
|
|
|
self.app.pargs.mysql = True
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.nginx:
|
2019-03-02 20:38:31 +01:00
|
|
|
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['nginx']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Nginx is not installed")
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.php:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.2-fpm'):
|
|
|
|
|
services = services + ['php7.2-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.2-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2019-03-02 20:38:31 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.php73:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.mysql:
|
|
|
|
|
if ((WOVariables.wo_mysql_host is "localhost") or
|
2019-03-02 20:38:31 +01:00
|
|
|
(WOVariables.wo_mysql_host is "127.0.0.1")):
|
2018-11-13 21:55:59 +01:00
|
|
|
if (WOAptGet.is_installed(self, 'mysql-server') or
|
2019-03-02 20:38:31 +01:00
|
|
|
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
|
|
|
|
|
WOAptGet.is_installed(self, 'mariadb-server')):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['mysql']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "MySQL is not installed")
|
|
|
|
|
else:
|
|
|
|
|
Log.warn(self, "Remote MySQL found, "
|
|
|
|
|
"Unable to check MySQL service status")
|
|
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if self.app.pargs.memcached:
|
2018-11-13 21:55:59 +01:00
|
|
|
if WOAptGet.is_installed(self, 'memcached'):
|
|
|
|
|
services = services + ['memcached']
|
|
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "Memcached is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.redis:
|
|
|
|
|
if WOAptGet.is_installed(self, 'redis-server'):
|
|
|
|
|
services = services + ['redis-server']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Redis server is not installed")
|
|
|
|
|
|
|
|
|
|
for service in services:
|
|
|
|
|
Log.debug(self, "Stopping service: {0}".format(service))
|
|
|
|
|
WOService.stop_service(self, service)
|
|
|
|
|
|
|
|
|
|
@expose(help="Restart stack services")
|
|
|
|
|
def restart(self):
|
|
|
|
|
"""Restart services"""
|
|
|
|
|
services = []
|
2019-03-02 20:38:31 +01:00
|
|
|
if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73
|
2019-03-13 05:02:53 +01:00
|
|
|
or self.app.pargs.mysql or self.app.pargs.memcached
|
2018-11-13 21:55:59 +01:00
|
|
|
or self.app.pargs.redis):
|
|
|
|
|
self.app.pargs.nginx = True
|
|
|
|
|
self.app.pargs.php = True
|
|
|
|
|
self.app.pargs.mysql = True
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.nginx:
|
2019-03-02 20:38:31 +01:00
|
|
|
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['nginx']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Nginx is not installed")
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.php:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.2-fpm'):
|
|
|
|
|
services = services + ['php7.2-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.2-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2019-03-02 20:38:31 +01:00
|
|
|
if self.app.pargs.php73:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
2019-03-02 20:38:31 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.mysql:
|
|
|
|
|
if ((WOVariables.wo_mysql_host is "localhost") or
|
2019-03-02 20:38:31 +01:00
|
|
|
(WOVariables.wo_mysql_host is "127.0.0.1")):
|
2018-11-13 21:55:59 +01:00
|
|
|
if (WOAptGet.is_installed(self, 'mysql-server') or
|
2019-03-02 20:38:31 +01:00
|
|
|
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
|
|
|
|
|
WOAptGet.is_installed(self, 'mariadb-server')):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['mysql']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "MySQL is not installed")
|
|
|
|
|
else:
|
|
|
|
|
Log.warn(self, "Remote MySQL found, "
|
|
|
|
|
"Unable to check MySQL service status")
|
|
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if self.app.pargs.memcached:
|
2018-11-13 21:55:59 +01:00
|
|
|
if WOAptGet.is_installed(self, 'memcached'):
|
|
|
|
|
services = services + ['memcached']
|
|
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "Memcached is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.redis:
|
|
|
|
|
if WOAptGet.is_installed(self, 'redis-server'):
|
|
|
|
|
services = services + ['redis-server']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Redis server is not installed")
|
|
|
|
|
|
|
|
|
|
for service in services:
|
|
|
|
|
Log.debug(self, "Restarting service: {0}".format(service))
|
|
|
|
|
WOService.restart_service(self, service)
|
|
|
|
|
|
|
|
|
|
@expose(help="Get stack status")
|
|
|
|
|
def status(self):
|
|
|
|
|
"""Status of services"""
|
|
|
|
|
services = []
|
2019-03-02 20:38:31 +01:00
|
|
|
if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73
|
2019-03-13 05:02:53 +01:00
|
|
|
or self.app.pargs.mysql or self.app.pargs.memcached
|
2018-11-13 21:55:59 +01:00
|
|
|
or self.app.pargs.redis):
|
|
|
|
|
self.app.pargs.nginx = True
|
|
|
|
|
self.app.pargs.php = True
|
|
|
|
|
self.app.pargs.mysql = True
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.nginx:
|
2019-03-02 20:38:31 +01:00
|
|
|
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['nginx']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Nginx is not installed")
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.php:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.2-fpm'):
|
|
|
|
|
services = services + ['php7.2-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.2-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2019-03-02 20:38:31 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.php73:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.mysql:
|
|
|
|
|
if ((WOVariables.wo_mysql_host is "localhost") or
|
2019-03-02 20:38:31 +01:00
|
|
|
(WOVariables.wo_mysql_host is "127.0.0.1")):
|
2018-11-13 21:55:59 +01:00
|
|
|
if (WOAptGet.is_installed(self, 'mysql-server') or
|
2019-03-02 20:38:31 +01:00
|
|
|
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
|
|
|
|
|
WOAptGet.is_installed(self, 'mariadb-server')):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['mysql']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "MySQL is not installed")
|
|
|
|
|
else:
|
|
|
|
|
Log.warn(self, "Remote MySQL found, "
|
|
|
|
|
"Unable to check MySQL service status")
|
|
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if self.app.pargs.memcached:
|
2018-11-13 21:55:59 +01:00
|
|
|
if WOAptGet.is_installed(self, 'memcached'):
|
|
|
|
|
services = services + ['memcached']
|
|
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "Memcached is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.redis:
|
|
|
|
|
if WOAptGet.is_installed(self, 'redis-server'):
|
|
|
|
|
services = services + ['redis-server']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Redis server is not installed")
|
|
|
|
|
|
|
|
|
|
for service in services:
|
|
|
|
|
if WOService.get_service_status(self, service):
|
|
|
|
|
Log.info(self, "{0:10}: {1}".format(service, "Running"))
|
|
|
|
|
|
|
|
|
|
@expose(help="Reload stack services")
|
|
|
|
|
def reload(self):
|
|
|
|
|
"""Reload service"""
|
|
|
|
|
services = []
|
2019-03-02 20:38:31 +01:00
|
|
|
if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73
|
2019-03-13 05:02:53 +01:00
|
|
|
or self.app.pargs.mysql or self.app.pargs.memcached
|
2018-11-13 21:55:59 +01:00
|
|
|
or self.app.pargs.redis):
|
|
|
|
|
self.app.pargs.nginx = True
|
|
|
|
|
self.app.pargs.php = True
|
|
|
|
|
self.app.pargs.mysql = True
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.nginx:
|
2019-03-02 20:38:31 +01:00
|
|
|
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['nginx']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Nginx is not installed")
|
|
|
|
|
|
|
|
|
|
if self.app.pargs.php:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.2-fpm'):
|
|
|
|
|
services = services + ['php7.2-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.2-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
2019-03-07 13:26:25 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
2019-03-02 20:38:31 +01:00
|
|
|
if self.app.pargs.php73:
|
2019-03-07 13:15:15 +01:00
|
|
|
if WOAptGet.is_installed(self, 'php7.3-fpm'):
|
|
|
|
|
services = services + ['php7.3-fpm']
|
2018-11-13 21:55:59 +01:00
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "PHP7.3-FPM is not installed")
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
if self.app.pargs.mysql:
|
|
|
|
|
if ((WOVariables.wo_mysql_host is "localhost") or
|
2019-03-02 20:38:31 +01:00
|
|
|
(WOVariables.wo_mysql_host is "127.0.0.1")):
|
2018-11-13 21:55:59 +01:00
|
|
|
if (WOAptGet.is_installed(self, 'mysql-server') or
|
2019-03-02 20:38:31 +01:00
|
|
|
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
|
|
|
|
|
WOAptGet.is_installed(self, 'mariadb-server')):
|
2018-11-13 21:55:59 +01:00
|
|
|
services = services + ['mysql']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "MySQL is not installed")
|
|
|
|
|
else:
|
|
|
|
|
Log.warn(self, "Remote MySQL found, "
|
|
|
|
|
"Unable to check MySQL service status")
|
|
|
|
|
|
2019-03-07 13:15:15 +01:00
|
|
|
if self.app.pargs.memcached:
|
2018-11-13 21:55:59 +01:00
|
|
|
if WOAptGet.is_installed(self, 'memcached'):
|
|
|
|
|
services = services + ['memcached']
|
|
|
|
|
else:
|
2019-03-07 13:15:15 +01:00
|
|
|
Log.info(self, "Memcached is not installed")
|
2019-03-02 20:38:31 +01:00
|
|
|
|
2018-11-13 21:55:59 +01:00
|
|
|
if self.app.pargs.redis:
|
|
|
|
|
if WOAptGet.is_installed(self, 'redis-server'):
|
|
|
|
|
services = services + ['redis-server']
|
|
|
|
|
else:
|
|
|
|
|
Log.info(self, "Redis server is not installed")
|
|
|
|
|
|
|
|
|
|
for service in services:
|
|
|
|
|
Log.debug(self, "Reloading service: {0}".format(service))
|
|
|
|
|
WOService.reload_service(self, service)
|