Improve `wo stack services`

This commit is contained in:
VirtuBox 2019-10-29 01:10:37 +01:00
parent bda69cb552
commit fd1105f459
Signed by: virtubox
GPG Key ID: 22EB296C97BAD476
5 changed files with 61 additions and 98 deletions

View File

@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Version check before updating WordOps with `wo update` is now directly handled by `wo`
- Refactored WordOps download function with python3-requests
- MySQL backup path changed to `/var/lib/wo-backup/mysql`
- Do not check anymore if stack are installed with apt in `wo service` but only if there is a systemd service
#### Fixed

4
MANIFEST.in Normal file
View File

@ -0,0 +1,4 @@
recursive-include *.py
include setup.cfg
include README.md CHANGELOG.md LICENSE
include *.txt

View File

@ -1,23 +0,0 @@
name: test-wordops
version: git
summary: WordOps
description: |
WordOps is an essential toolset that eases WordPress
site and server administration. It provide the ability
to install a high performance WordPress stack
with a few keystrokes.
confinement: devmode
base: core18
parts:
test-wordops:
plugin: python
python-version: python3
source: .
stage-packages:
- cement
- python-apt
apps:
test-wordops:
command: wo

View File

@ -457,7 +457,7 @@ def install(self, packages=[], apt_packages=[], disp_msg=True):
["https://raw.githubusercontent.com/chubin/cheat.sh"
"/master/share/bash_completion.txt",
"/etc/bash_completion.d/cht.sh",
"cheat.sh bash_completion"]]
"bash_completion"]]
# UTILS
if pargs.utils:

View File

@ -1,8 +1,6 @@
import os
from cement.core.controller import CementBaseController, expose
from wo.core.aptget import WOAptGet
from wo.core.logging import Log
from wo.core.services import WOService
from wo.core.variables import WOVar
@ -19,6 +17,7 @@ class Meta:
def start(self):
"""Start services"""
services = []
wo_system = "/lib/systemd/system/"
pargs = self.app.pargs
if not (pargs.nginx or pargs.php or
pargs.php73 or
@ -34,23 +33,23 @@ def start(self):
pargs.netdata = True
if pargs.nginx:
if (WOAptGet.is_installed(self, 'nginx-custom')):
if os.path.exists('{0}'.format(wo_system) + 'nginx.service'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if pargs.php:
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'):
services = services + ['php7.2-fpm']
else:
Log.info(self, "PHP7.2-FPM is not installed")
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
if pargs.php73:
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
@ -58,9 +57,7 @@ def start(self):
if pargs.mysql:
if ((WOVar.wo_mysql_host == "localhost") or
(WOVar.wo_mysql_host == "127.0.0.1")):
if (WOAptGet.is_installed(self, 'mysql-server') or
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
WOAptGet.is_installed(self, 'mariadb-server')):
if os.path.exists('/etc/systemd/system/mysql.service'):
services = services + ['mysql']
else:
Log.info(self, "MySQL is not installed")
@ -69,28 +66,28 @@ def start(self):
"Unable to check MySQL service status")
if pargs.redis:
if WOAptGet.is_installed(self, 'redis-server'):
if os.path.exists('{0}'.format(wo_system) +
'redis-server.service'):
services = services + ['redis-server']
else:
Log.info(self, "Redis server is not installed")
if pargs.fail2ban:
if WOAptGet.is_installed(self, 'fail2ban'):
if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'):
services = services + ['fail2ban']
else:
Log.info(self, "fail2ban is not installed")
# proftpd
if pargs.proftpd:
if WOAptGet.is_installed(self, 'proftpd-basic'):
if os.path.exists('/etc/init.d/proftpd'):
services = services + ['proftpd']
else:
Log.info(self, "ProFTPd is not installed")
# netdata
if pargs.netdata:
if (os.path.isdir("/opt/netdata") or
os.path.isdir("/etc/netdata")):
if os.path.exists('{0}'.format(wo_system) + 'netdata.service'):
services = services + ['netdata']
else:
Log.info(self, "Netdata is not installed")
@ -103,6 +100,7 @@ def start(self):
def stop(self):
"""Stop services"""
services = []
wo_system = "/lib/systemd/system/"
pargs = self.app.pargs
if not (pargs.nginx or pargs.php or
pargs.php73 or
@ -115,39 +113,32 @@ def stop(self):
pargs.php = True
pargs.mysql = True
# nginx
if pargs.nginx:
if (WOAptGet.is_installed(self, 'nginx-custom')):
if os.path.exists('{0}'.format(wo_system) + 'nginx.service'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
# php7.2
if pargs.php:
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'):
services = services + ['php7.2-fpm']
else:
Log.info(self, "PHP7.2-FPM is not installed")
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
# php7.3
if pargs.php73:
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
# mysql
if pargs.mysql:
if ((WOVar.wo_mysql_host == "localhost") or
(WOVar.wo_mysql_host == "127.0.0.1")):
if (WOAptGet.is_installed(self, 'mysql-server') or
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
WOAptGet.is_installed(self, 'mariadb-server')):
if os.path.exists('/etc/systemd/system/mysql.service'):
services = services + ['mysql']
else:
Log.info(self, "MySQL is not installed")
@ -155,31 +146,29 @@ def stop(self):
Log.warn(self, "Remote MySQL found, "
"Unable to check MySQL service status")
# redis
if pargs.redis:
if WOAptGet.is_installed(self, 'redis-server'):
if os.path.exists('{0}'.format(wo_system) +
'redis-server.service'):
services = services + ['redis-server']
else:
Log.info(self, "Redis server is not installed")
# fail2ban
if pargs.fail2ban:
if WOAptGet.is_installed(self, 'fail2ban'):
if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'):
services = services + ['fail2ban']
else:
Log.info(self, "fail2ban is not installed")
# proftpd
if pargs.proftpd:
if WOAptGet.is_installed(self, 'proftpd-basic'):
if os.path.exists('/etc/init.d/proftpd'):
services = services + ['proftpd']
else:
Log.info(self, "ProFTPd is not installed")
# netdata
if pargs.netdata:
if (os.path.isdir("/opt/netdata") or
os.path.isdir("/etc/netdata")):
if os.path.exists('{0}'.format(wo_system) + 'netdata.service'):
services = services + ['netdata']
else:
Log.info(self, "Netdata is not installed")
@ -192,6 +181,7 @@ def stop(self):
def restart(self):
"""Restart services"""
services = []
wo_system = "/lib/systemd/system/"
pargs = self.app.pargs
if not (pargs.nginx or pargs.php or
pargs.php73 or
@ -206,24 +196,23 @@ def restart(self):
pargs.netdata = True
if pargs.nginx:
if (WOAptGet.is_installed(self, 'nginx-custom')):
if os.path.exists('{0}'.format(wo_system) + 'nginx.service'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if pargs.php:
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'):
services = services + ['php7.2-fpm']
else:
Log.info(self, "PHP7.2-FPM is not installed")
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
if pargs.php73:
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
@ -231,10 +220,7 @@ def restart(self):
if pargs.mysql:
if ((WOVar.wo_mysql_host == "localhost") or
(WOVar.wo_mysql_host == "127.0.0.1")):
if ((WOAptGet.is_installed(self, 'mysql-server') or
WOAptGet.is_installed(self,
'percona-server-server-5.6') or
WOAptGet.is_installed(self, 'mariadb-server'))):
if os.path.exists('/etc/systemd/system/mysql.service'):
services = services + ['mysql']
else:
Log.info(self, "MySQL is not installed")
@ -243,28 +229,28 @@ def restart(self):
"Unable to check MySQL service status")
if pargs.redis:
if WOAptGet.is_installed(self, 'redis-server'):
if os.path.exists('{0}'.format(wo_system) +
'redis-server.service'):
services = services + ['redis-server']
else:
Log.info(self, "Redis server is not installed")
if pargs.fail2ban:
if WOAptGet.is_installed(self, 'fail2ban'):
if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'):
services = services + ['fail2ban']
else:
Log.info(self, "fail2ban is not installed")
# proftpd
if pargs.proftpd:
if WOAptGet.is_installed(self, 'proftpd-basic'):
if os.path.exists('/etc/init.d/proftpd'):
services = services + ['proftpd']
else:
Log.info(self, "ProFTPd is not installed")
# netdata
if pargs.netdata:
if (os.path.isdir("/opt/netdata") or
os.path.isdir("/etc/netdata")):
if os.path.exists('{0}'.format(wo_system) + 'netdata.service'):
services = services + ['netdata']
else:
Log.info(self, "Netdata is not installed")
@ -277,6 +263,7 @@ def restart(self):
def status(self):
"""Status of services"""
services = []
wo_system = "/lib/systemd/system/"
pargs = self.app.pargs
if not (pargs.nginx or pargs.php or
pargs.php73 or
@ -292,24 +279,23 @@ def status(self):
pargs.netdata = True
if pargs.nginx:
if (WOAptGet.is_installed(self, 'nginx-custom')):
if os.path.exists('{0}'.format(wo_system) + 'nginx.service'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if pargs.php:
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'):
services = services + ['php7.2-fpm']
else:
Log.info(self, "PHP7.2-FPM is not installed")
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
if pargs.php73:
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
@ -317,9 +303,7 @@ def status(self):
if pargs.mysql:
if ((WOVar.wo_mysql_host == "localhost") or
(WOVar.wo_mysql_host == "127.0.0.1")):
if (WOAptGet.is_installed(self, 'mysql-server') or
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
WOAptGet.is_installed(self, 'mariadb-server')):
if os.path.exists('/etc/systemd/system/mysql.service'):
services = services + ['mysql']
else:
Log.info(self, "MySQL is not installed")
@ -328,28 +312,28 @@ def status(self):
"Unable to check MySQL service status")
if pargs.redis:
if WOAptGet.is_installed(self, 'redis-server'):
if os.path.exists('{0}'.format(wo_system) +
'redis-server.service'):
services = services + ['redis-server']
else:
Log.info(self, "Redis server is not installed")
if pargs.fail2ban:
if WOAptGet.is_installed(self, 'fail2ban'):
if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'):
services = services + ['fail2ban']
else:
Log.info(self, "fail2ban is not installed")
# proftpd
if pargs.proftpd:
if WOAptGet.is_installed(self, 'proftpd-basic'):
if os.path.exists('/etc/init.d/proftpd'):
services = services + ['proftpd']
else:
Log.info(self, "ProFTPd is not installed")
# netdata
if pargs.netdata:
if (os.path.isdir("/opt/netdata") or
os.path.isdir("/etc/netdata")):
if os.path.exists('{0}'.format(wo_system) + 'netdata.service'):
services = services + ['netdata']
else:
Log.info(self, "Netdata is not installed")
@ -362,6 +346,7 @@ def status(self):
def reload(self):
"""Reload service"""
services = []
wo_system = "/lib/systemd/system/"
pargs = self.app.pargs
if not (pargs.nginx or pargs.php or
pargs.php73 or
@ -376,25 +361,23 @@ def reload(self):
pargs.fail2ban = True
if pargs.nginx:
if (WOAptGet.is_installed(self, 'nginx-custom') or
WOAptGet.is_installed(self, 'nginx-mainline')):
if os.path.exists('{0}'.format(wo_system) + 'nginx.service'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
if pargs.php:
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.2-fpm.service'):
services = services + ['php7.2-fpm']
else:
Log.info(self, "PHP7.2-FPM is not installed")
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
if pargs.php73:
if WOAptGet.is_installed(self, 'php7.3-fpm'):
if os.path.exists('{0}'.format(wo_system) + 'php7.3-fpm.service'):
services = services + ['php7.3-fpm']
else:
Log.info(self, "PHP7.3-FPM is not installed")
@ -402,9 +385,7 @@ def reload(self):
if pargs.mysql:
if ((WOVar.wo_mysql_host == "localhost") or
(WOVar.wo_mysql_host == "127.0.0.1")):
if (WOAptGet.is_installed(self, 'mysql-server') or
WOAptGet.is_installed(self, 'percona-server-server-5.6') or
WOAptGet.is_installed(self, 'mariadb-server')):
if os.path.exists('/etc/systemd/system/mysql.service'):
services = services + ['mysql']
else:
Log.info(self, "MySQL is not installed")
@ -413,28 +394,28 @@ def reload(self):
"Unable to check MySQL service status")
if pargs.redis:
if WOAptGet.is_installed(self, 'redis-server'):
if os.path.exists('{0}'.format(wo_system) +
'redis-server.service'):
services = services + ['redis-server']
else:
Log.info(self, "Redis server is not installed")
if pargs.fail2ban:
if WOAptGet.is_installed(self, 'fail2ban'):
if os.path.exists('{0}'.format(wo_system) + 'fail2ban.service'):
services = services + ['fail2ban']
else:
Log.info(self, "fail2ban is not installed")
# proftpd
if pargs.proftpd:
if WOAptGet.is_installed(self, 'proftpd-basic'):
if os.path.exists('/etc/init.d/proftpd'):
services = services + ['proftpd']
else:
Log.info(self, "ProFTPd is not installed")
# netdata
if pargs.netdata:
if (os.path.isdir("/opt/netdata") or
os.path.isdir("/etc/netdata")):
if os.path.exists('{0}'.format(wo_system) + 'netdata.service'):
services = services + ['netdata']
else:
Log.info(self, "Netdata is not installed")