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.

333 lines
12 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 not (self.app.pargs.nginx and self.app.pargs.php
and self.app.pargs.mysql and self.app.pargs.postfix
and self.app.pargs.hhvm and self.app.pargs.memcache
and self.app.pargs.dovecot):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.postfix = True
if self.app.pargs.nginx:
if EEVariables.ee_platform_distro == 'debian':
check_nginx = 'nginx-extras'
else:
check_nginx = 'nginx-custom'
if EEAptGet.is_installed(self, check_nginx):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if self.app.pargs.php:
if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found,"
"Unable to start MySQL service")
if self.app.pargs.postfix:
if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm:
if EEAptGet.is_installed(self, 'hhvm'):
services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache:
if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot:
if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot']
else:
Log.info(self, "Mail server is not installed")
10 years ago
for service in services:
Log.debug(self, "Starting service: {0}".format(service))
10 years ago
EEService.start_service(self, service)
@expose(help="Stop stack services")
def stop(self):
"""Stop services"""
services = []
if not (self.app.pargs.nginx and self.app.pargs.php
and self.app.pargs.mysql and self.app.pargs.postfix
and self.app.pargs.hhvm and self.app.pargs.memcache
and self.app.pargs.dovecot):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.postfix = True
if self.app.pargs.nginx:
if EEVariables.ee_platform_distro == 'debian':
check_nginx = 'nginx-extras'
else:
check_nginx = 'nginx-custom'
if EEAptGet.is_installed(self, check_nginx):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if self.app.pargs.php:
if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found,"
"Unable to stop MySQL service")
if self.app.pargs.postfix:
if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm:
if EEAptGet.is_installed(self, 'hhvm'):
services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache:
if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot:
if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot']
else:
Log.info(self, "Mail server is not installed")
for service in services:
Log.debug(self, "Stopping service: {0}".format(service))
10 years ago
EEService.stop_service(self, service)
@expose(help="Restart stack services")
def restart(self):
"""Restart services"""
services = []
if not (self.app.pargs.nginx and self.app.pargs.php
and self.app.pargs.mysql and self.app.pargs.postfix
and self.app.pargs.hhvm and self.app.pargs.memcache
and self.app.pargs.dovecot):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.postfix = True
if self.app.pargs.nginx:
if EEVariables.ee_platform_distro == 'debian':
check_nginx = 'nginx-extras'
else:
check_nginx = 'nginx-custom'
if EEAptGet.is_installed(self, check_nginx):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if self.app.pargs.php:
if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found,"
"Unable to restart MySQL service")
if self.app.pargs.postfix:
if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm:
if EEAptGet.is_installed(self, 'hhvm'):
services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache:
if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot:
if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot']
else:
Log.info(self, "Mail server is not installed")
10 years ago
for service in services:
Log.debug(self, "Restarting service: {0}".format(service))
10 years ago
EEService.restart_service(self, service)
@expose(help="Get stack status")
def status(self):
"""Status of services"""
services = []
if not (self.app.pargs.nginx and self.app.pargs.php
and self.app.pargs.mysql and self.app.pargs.postfix
and self.app.pargs.hhvm and self.app.pargs.memcache
and self.app.pargs.dovecot):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.postfix = True
if self.app.pargs.nginx:
if EEVariables.ee_platform_distro == 'debian':
check_nginx = 'nginx-extras'
else:
check_nginx = 'nginx-custom'
if EEAptGet.is_installed(self, check_nginx):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if self.app.pargs.php:
if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found,"
"Unable to check MySQL service status")
if self.app.pargs.postfix:
if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm:
if EEAptGet.is_installed(self, 'hhvm'):
services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache:
if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot:
if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot']
else:
Log.info(self, "Mail server is not installed")
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 not (self.app.pargs.nginx and self.app.pargs.php
and self.app.pargs.mysql and self.app.pargs.postfix
and self.app.pargs.hhvm and self.app.pargs.memcache
and self.app.pargs.dovecot):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
self.app.pargs.postfix = True
10 years ago
if self.app.pargs.nginx:
if EEVariables.ee_platform_distro == 'debian':
check_nginx = 'nginx-extras'
else:
check_nginx = 'nginx-custom'
if EEAptGet.is_installed(self, check_nginx):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if self.app.pargs.php:
if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql:
10 years ago
if EEVariables.ee_mysql_host is "localhost":
services = services + ['mysql']
else:
Log.warn(self, "Remote MySQL found,"
"Unable to reload MySQL service")
if self.app.pargs.postfix:
if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm:
Log.info(self, "HHVM does not support to reload")
if self.app.pargs.memcache:
if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot:
if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot']
else:
Log.info(self, "Mail server is not installed")
10 years ago
for service in services:
Log.debug(self, "Reloading service: {0}".format(service))
10 years ago
EEService.reload_service(self, service)