You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
8.5 KiB

from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook
from ee.core.services import EEService
from ee.core.logging import Log
10 years ago
from ee.core.variables import EEVariables
class EEStackStatusController(CementBaseController):
class Meta:
label = 'stack_services'
stacked_on = 'stack'
stacked_type = 'embedded'
description = 'Get status of stack'
arguments = [
(['--memcache'],
dict(help='start/stop/restart memcache', action='store_true')),
(['--dovecot'],
dict(help='start/stop/restart dovecot', action='store_true')),
]
@expose(help="Start stack services")
def start(self):
"""Start services"""
services = []
if self.app.pargs.nginx:
Log.debug(self, "nginx service start")
services = services + ['nginx']
if self.app.pargs.php:
Log.debug(self, "php5-fpm service start")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service start")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found,"
"unable to start MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service start")
services = services + ['postfix']
if self.app.pargs.memcache:
Log.debug(self, "memcached service start")
services = services + ['memcached']
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service start")
services = services + ['dovecot']
10 years ago
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
10 years ago
Log.debug(self, "nginx,php5-fpm,mysql,postfix services start")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services start")
for service in services:
10 years ago
EEService.start_service(self, service)
@expose(help="Stop stack services")
def stop(self):
"""Stop services"""
services = []
if self.app.pargs.nginx:
Log.debug(self, "nginx service stop")
services = services + ['nginx']
if self.app.pargs.php:
Log.debug(self, "php5-fpm service stop")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service stop")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to stop MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service stop")
services = services + ['postfix']
if self.app.pargs.memcache:
Log.debug(self, "memcached service stop")
services = services + ['memcached']
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service stop")
services = services + ['dovecot']
10 years ago
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
Log.debug(self, "nginx,php5-fpm,mysql,postfix services stop")
10 years ago
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services stop")
for service in services:
10 years ago
EEService.stop_service(self, service)
@expose(help="Restart stack services")
def restart(self):
"""Restart services"""
services = []
if self.app.pargs.nginx:
Log.debug(self, "nginx service restart")
services = services + ['nginx']
if self.app.pargs.php:
Log.debug(self, "php5-fpm service restart")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service restart")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to restart MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service restart")
services = services + ['postfix']
if self.app.pargs.memcache:
Log.debug(self, "memcached service restart")
services = services + ['memcached']
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service restart")
services = services + ['dovecot']
10 years ago
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
Log.debug(self, "nginx,php5-fpm,mysql,postfix services restart")
10 years ago
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services restart")
for service in services:
10 years ago
EEService.restart_service(self, service)
@expose(help="Get stack status")
def status(self):
"""Status of services"""
services = []
if self.app.pargs.nginx:
Log.debug(self, "nginx service status")
services = services + ['nginx']
if self.app.pargs.php:
Log.debug(self, "php5-fpm service status")
services = services + ['php5-fpm']
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service status")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to get MySQL service status")
if self.app.pargs.postfix:
services = services + ['postfix']
Log.debug(self, "postfix service status")
if self.app.pargs.memcache:
Log.debug(self, "memcached service status")
services = services + ['memcached']
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service status")
services = services + ['dovecot']
10 years ago
if not services and EEVariables.ee_mysql_host is "localhost":
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
10 years ago
Log.debug(self, "nginx,php5-fpm,mysql,postfix services status")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services status")
for service in services:
10 years ago
if EEService.get_service_status(self, service):
10 years ago
Log.info(self, "{0:10}: {1}".format(service, "Running"))
10 years ago
@expose(help="Reload stack services")
10 years ago
def reload(self):
"""Reload service"""
10 years ago
services = []
if self.app.pargs.nginx:
Log.debug(self, "nginx service reload")
10 years ago
services = services + ['nginx']
if self.app.pargs.php:
Log.debug(self, "php5-fpm service reload")
10 years ago
services = services + ['php5-fpm']
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service reload")
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found, "
"unable to remote MySQL service")
if self.app.pargs.postfix:
Log.debug(self, "postfix service reload")
10 years ago
services = services + ['postfix']
if self.app.pargs.memcache:
Log.debug(self, "memcached service reload")
10 years ago
services = services + ['memcached']
if self.app.pargs.dovecot:
Log.debug(self, "dovecot service reload")
10 years ago
services = services + ['dovecot']
10 years ago
if not services and EEVariables.ee_mysql_host is "localhost":
10 years ago
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
Log.debug(self, "nginx,php5-fpm,mysql,postfix services reload")
10 years ago
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services reload")
for service in services:
10 years ago
EEService.reload_service(self, service)