Improve wo stack services

This commit is contained in:
VirtuBox
2019-10-29 01:10:37 +01:00
parent bda69cb552
commit fd1105f459
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` - Version check before updating WordOps with `wo update` is now directly handled by `wo`
- Refactored WordOps download function with python3-requests - Refactored WordOps download function with python3-requests
- MySQL backup path changed to `/var/lib/wo-backup/mysql` - 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 #### 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 @@ class WOStackController(CementBaseController):
["https://raw.githubusercontent.com/chubin/cheat.sh" ["https://raw.githubusercontent.com/chubin/cheat.sh"
"/master/share/bash_completion.txt", "/master/share/bash_completion.txt",
"/etc/bash_completion.d/cht.sh", "/etc/bash_completion.d/cht.sh",
"cheat.sh bash_completion"]] "bash_completion"]]
# UTILS # UTILS
if pargs.utils: if pargs.utils:

View File

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