Browse Source

Improved stack service command

servicefixes
gau1991 10 years ago
parent
commit
31334c4155
  1. 334
      ee/cli/plugins/stack_services.py

334
ee/cli/plugins/stack_services.py

@ -22,158 +22,250 @@ class EEStackStatusController(CementBaseController):
def start(self): def start(self):
"""Start services""" """Start services"""
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 self.app.pargs.nginx:
Log.debug(self, "nginx service start") if EEVariables.ee_platform_distro == 'debian':
services = services + ['nginx'] 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 self.app.pargs.php:
Log.debug(self, "php5-fpm service start") if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm'] services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql: if self.app.pargs.mysql:
if EEVariables.ee_mysql_host is "localhost": if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service start")
services = services + ['mysql'] services = services + ['mysql']
else: else:
Log.warn(self, "Remote MySQL found," Log.warn(self, "Remote MySQL found,"
"unable to start MySQL service") "Unable to start MySQL service")
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service start") if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix'] services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm: if self.app.pargs.hhvm:
services = services + ['hhvm'] if EEAptGet.is_installed(self, 'hhvm'):
Log.debug(self, "hhvm service start") services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service start") if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached'] services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot: if self.app.pargs.dovecot:
Log.debug(self, "dovecot service start") if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix', Log.info(self, "Mail server is not installed")
'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services start")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix,hhvm services start")
for service in services: for service in services:
Log.debug(self, "Starting service: {0}".format(service))
EEService.start_service(self, service) EEService.start_service(self, service)
@expose(help="Stop stack services") @expose(help="Stop stack services")
def stop(self): def stop(self):
"""Stop services""" """Stop services"""
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 self.app.pargs.nginx:
Log.debug(self, "nginx service stop") if EEVariables.ee_platform_distro == 'debian':
services = services + ['nginx'] 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 self.app.pargs.php:
Log.debug(self, "php5-fpm service stop") if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm'] services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql: if self.app.pargs.mysql:
if EEVariables.ee_mysql_host is "localhost": if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service stop")
services = services + ['mysql'] services = services + ['mysql']
else: else:
Log.warn(self, "Remote MySQL found, " Log.warn(self, "Remote MySQL found,"
"unable to stop MySQL service") "Unable to stop MySQL service")
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service stop") if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix'] services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm: if self.app.pargs.hhvm:
services = services + ['hhvm'] if EEAptGet.is_installed(self, 'hhvm'):
Log.debug(self, "hhvm service stop") services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service stop") if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached'] services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot: if self.app.pargs.dovecot:
Log.debug(self, "dovecot service stop") if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix', Log.info(self, "Mail server is not installed")
'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services stop")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix,hhvm services stop")
for service in services: for service in services:
Log.debug(self, "Stopping service: {0}".format(service))
EEService.stop_service(self, service) EEService.stop_service(self, service)
@expose(help="Restart stack services") @expose(help="Restart stack services")
def restart(self): def restart(self):
"""Restart services""" """Restart services"""
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 self.app.pargs.nginx:
Log.debug(self, "nginx service restart") if EEVariables.ee_platform_distro == 'debian':
services = services + ['nginx'] 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 self.app.pargs.php:
Log.debug(self, "php5-fpm service restart") if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm'] services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql: if self.app.pargs.mysql:
if EEVariables.ee_mysql_host is "localhost": if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service restart")
services = services + ['mysql'] services = services + ['mysql']
else: else:
Log.warn(self, "Remote MySQL found, " Log.warn(self, "Remote MySQL found,"
"unable to restart MySQL service") "Unable to restart MySQL service")
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service restart") if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix'] services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm: if self.app.pargs.hhvm:
services = services + ['hhvm'] if EEAptGet.is_installed(self, 'hhvm'):
Log.debug(self, "hhvm service restart") services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service restart") if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached'] services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot: if self.app.pargs.dovecot:
Log.debug(self, "dovecot service restart") if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix', Log.info(self, "Mail server is not installed")
'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services"
"restart")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix,hhvm services restart")
for service in services: for service in services:
Log.debug(self, "Restarting service: {0}".format(service))
EEService.restart_service(self, service) EEService.restart_service(self, service)
@expose(help="Get stack status") @expose(help="Get stack status")
def status(self): def status(self):
"""Status of services""" """Status of services"""
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 self.app.pargs.nginx:
Log.debug(self, "nginx service status") if EEVariables.ee_platform_distro == 'debian':
services = services + ['nginx'] 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 self.app.pargs.php:
Log.debug(self, "php5-fpm service status") if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm'] services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql: if self.app.pargs.mysql:
if EEVariables.ee_mysql_host is "localhost": if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service status")
services = services + ['mysql'] services = services + ['mysql']
else: else:
Log.warn(self, "Remote MySQL found, " Log.warn(self, "Remote MySQL found,"
"unable to get MySQL service status") "Unable to check MySQL service status")
if self.app.pargs.postfix: if self.app.pargs.postfix:
services = services + ['postfix'] if EEAptGet.is_installed(self, 'postfix'):
Log.debug(self, "postfix service status") services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm: if self.app.pargs.hhvm:
services = services + ['hhvm'] if EEAptGet.is_installed(self, 'hhvm'):
Log.debug(self, "hhvm service status") services = services + ['hhvm']
else:
Log.info(self, "HHVM is not installed")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service status") if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached'] services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot: if self.app.pargs.dovecot:
Log.debug(self, "dovecot service status") if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix', Log.info(self, "Mail server is not installed")
'hhvm']
Log.debug(self, "nginx,php5-fpm,mysql,postfix,hhvm services"
" status")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix', 'hhvm']
Log.debug(self, "nginx,php5-fpm,postfix,hhvm services status")
for service in services: for service in services:
if EEService.get_service_status(self, service): if EEService.get_service_status(self, service):
Log.info(self, "{0:10}: {1}".format(service, "Running")) Log.info(self, "{0:10}: {1}".format(service, "Running"))
@ -182,35 +274,59 @@ class EEStackStatusController(CementBaseController):
def reload(self): def reload(self):
"""Reload service""" """Reload service"""
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 self.app.pargs.nginx:
Log.debug(self, "nginx service reload") if EEVariables.ee_platform_distro == 'debian':
services = services + ['nginx'] 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 self.app.pargs.php:
Log.debug(self, "php5-fpm service reload") if EEAptGet.is_installed(self, 'php5-fpm'):
services = services + ['php5-fpm'] services = services + ['php5-fpm']
else:
Log.info(self, "PHP5-FPM is not installed")
if self.app.pargs.mysql: if self.app.pargs.mysql:
if EEVariables.ee_mysql_host is "localhost": if EEVariables.ee_mysql_host is "localhost":
Log.debug(self, "mysql service reload")
services = services + ['mysql'] services = services + ['mysql']
else: else:
Log.warn(self, "Remote MySQL found, " Log.warn(self, "Remote MySQL found,"
"unable to remote MySQL service") "Unable to reload MySQL service")
if self.app.pargs.postfix: if self.app.pargs.postfix:
Log.debug(self, "postfix service reload") if EEAptGet.is_installed(self, 'postfix'):
services = services + ['postfix'] services = services + ['postfix']
else:
Log.info(self, "Postfix is not installed")
if self.app.pargs.hhvm: if self.app.pargs.hhvm:
Log.warn(self, "hhvm does not support to reload") Log.info(self, "HHVM does not support to reload")
if self.app.pargs.memcache: if self.app.pargs.memcache:
Log.debug(self, "memcached service reload") if EEAptGet.is_installed(self, 'memcached'):
services = services + ['memcached'] services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
if self.app.pargs.dovecot: if self.app.pargs.dovecot:
Log.debug(self, "dovecot service reload") if EEAptGet.is_installed(self, 'dovecot-core'):
services = services + ['dovecot'] services = services + ['dovecot']
if not services and EEVariables.ee_mysql_host is "localhost": else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] Log.info(self, "Mail server is not installed")
Log.debug(self, "nginx,php5-fpm,mysql,postfix services reload")
elif not services:
services = services + ['nginx', 'php5-fpm', 'postfix']
Log.debug(self, "nginx,php5-fpm,postfix services reload")
for service in services: for service in services:
Log.debug(self, "Reloading service: {0}".format(service))
EEService.reload_service(self, service) EEService.reload_service(self, service)

Loading…
Cancel
Save