Files
WPIQ/wo/cli/plugins/stack.py

813 lines
36 KiB
Python
Raw Normal View History

2018-11-13 21:55:59 +01:00
"""Stack Plugin for WordOps"""
from cement.core.controller import CementBaseController, expose
2019-08-05 04:56:33 +02:00
from cement.core import handler, hook
import codecs
2018-11-13 21:55:59 +01:00
import configparser
import os
import pwd
import random
import shutil
import string
import re
2019-08-04 12:36:42 +02:00
import requests
2019-06-19 21:18:32 +02:00
import psutil
# from pynginxconfig import NginxConfig
from wo.cli.plugins.site_functions import *
from wo.cli.plugins.sitedb import *
2018-11-13 21:55:59 +01:00
from wo.cli.plugins.stack_migrate import WOStackMigrateController
from wo.cli.plugins.stack_services import WOStackStatusController
2018-11-13 21:55:59 +01:00
from wo.cli.plugins.stack_upgrade import WOStackUpgradeController
2019-08-05 04:56:33 +02:00
from wo.cli.plugins.stack_pref import pre_pref, post_pref
from wo.core.addswap import WOSwap
from wo.core.apt_repo import WORepo
from wo.core.aptget import WOAptGet
from wo.core.cron import WOCron
from wo.core.download import WODownload
from wo.core.extract import WOExtract
from wo.core.fileutils import WOFileUtils
from wo.core.git import WOGit
2018-11-13 21:55:59 +01:00
from wo.core.logging import Log
from wo.core.mysql import WOMysql
from wo.core.services import WOService
from wo.core.shellexec import CommandExecutionError, WOShellExec
from wo.core.variables import WOVariables
2018-11-13 21:55:59 +01:00
def wo_stack_hook(app):
pass
class WOStackController(CementBaseController):
class Meta:
label = 'stack'
stacked_on = 'base'
stacked_type = 'nested'
description = 'Stack command manages stack operations'
arguments = [
(['--all'],
dict(help='Install all stacks at once', action='store_true')),
(['--web'],
dict(help='Install web stack', action='store_true')),
(['--admin'],
dict(help='Install admin tools stack', action='store_true')),
2019-07-19 15:21:17 +02:00
(['--security'],
dict(help='Install security tools stack', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--nginx'],
dict(help='Install Nginx stack', action='store_true')),
(['--php'],
dict(help='Install PHP 7.2 stack', action='store_true')),
(['--php73'],
dict(help='Install PHP 7.3 stack', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--mysql'],
dict(help='Install MySQL stack', action='store_true')),
2019-08-15 23:46:16 +02:00
(['--mysqlclient'],
dict(help='Install MySQL client for remote MySQL server',
action='store_true')),
2018-11-13 21:55:59 +01:00
(['--wpcli'],
dict(help='Install WPCLI stack', action='store_true')),
(['--phpmyadmin'],
dict(help='Install PHPMyAdmin stack', action='store_true')),
2019-04-01 20:59:53 +02:00
(['--composer'],
dict(help='Install Composer stack', action='store_true')),
(['--netdata'],
2019-04-02 01:59:40 +02:00
dict(help='Install Netdata monitoring suite',
action='store_true')),
2019-04-23 19:03:42 +02:00
(['--dashboard'],
dict(help='Install WordOps dashboard', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--adminer'],
dict(help='Install Adminer stack', action='store_true')),
2019-04-25 01:38:14 +02:00
(['--fail2ban'],
dict(help='Install Fail2ban stack', action='store_true')),
2018-11-13 21:55:59 +01:00
(['--utils'],
dict(help='Install Utils stack', action='store_true')),
(['--redis'],
dict(help='Install Redis', action='store_true')),
(['--phpredisadmin'],
dict(help='Install phpRedisAdmin', action='store_true')),
2019-07-19 13:47:29 +02:00
(['--proftpd'],
dict(help='Install ProFTPd', action='store_true')),
2019-08-07 03:05:32 +02:00
(['--force'],
dict(help='Force install/remove/purge without prompt',
action='store_true')),
]
usage = "wo stack (command) [options]"
2018-11-13 21:55:59 +01:00
@expose(hide=True)
def default(self):
"""default action of wo stack command"""
self.app.args.print_help()
@expose(help="Install packages")
def install(self, packages=[], apt_packages=[], disp_msg=True):
"""Start installation of packages"""
self.msg = []
2019-08-07 03:05:32 +02:00
pargs = self.app.pargs
2018-11-13 21:55:59 +01:00
try:
# Default action for stack installation
2019-08-07 03:05:32 +02:00
if ((not pargs.web) and (not pargs.admin) and
(not pargs.nginx) and (not pargs.php) and
(not pargs.mysql) and (not pargs.wpcli) and
2019-08-15 23:46:16 +02:00
(not pargs.phpmyadmin) and (not pargs.composer) and
(not pargs.netdata) and (not pargs.dashboard) and
(not pargs.fail2ban) and (not pargs.security)
and (not pargs.mysqlclient) and
2019-08-07 03:05:32 +02:00
(not pargs.adminer) and (not pargs.utils) and
(not pargs.redis) and (not pargs.proftpd) and
(not pargs.phpredisadmin) and
(not pargs.php73)):
pargs.web = True
pargs.admin = True
pargs.security = True
if pargs.all:
pargs.web = True
pargs.admin = True
pargs.php73 = True
pargs.redis = True
pargs.proftpd = True
if pargs.web:
pargs.nginx = True
pargs.php = True
pargs.mysql = True
pargs.wpcli = True
if pargs.admin:
pargs.nginx = True
pargs.php = True
pargs.mysql = True
pargs.adminer = True
pargs.phpmyadmin = True
pargs.composer = True
pargs.utils = True
pargs.netdata = True
pargs.dashboard = True
pargs.phpredisadmin = True
if pargs.security:
pargs.fail2ban = True
2018-11-13 21:55:59 +01:00
2019-04-23 19:03:42 +02:00
# Redis
2019-08-07 03:05:32 +02:00
if pargs.redis:
2018-11-13 21:55:59 +01:00
if not WOAptGet.is_installed(self, 'redis-server'):
apt_packages = apt_packages + WOVariables.wo_redis
2019-08-07 03:05:32 +02:00
pargs.php = True
2018-11-13 21:55:59 +01:00
else:
Log.info(self, "Redis already installed")
2019-04-23 19:03:42 +02:00
# Nginx
2019-08-07 03:05:32 +02:00
if pargs.nginx:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Setting apt_packages variable for Nginx")
if not (WOAptGet.is_installed(self, 'nginx-custom')):
2019-03-08 00:43:25 +01:00
if not (WOAptGet.is_installed(self, 'nginx-plus') or
WOAptGet.is_installed(self, 'nginx')):
2018-11-13 21:55:59 +01:00
apt_packages = apt_packages + WOVariables.wo_nginx
else:
if WOAptGet.is_installed(self, 'nginx-plus'):
Log.info(self, "NGINX PLUS Detected ...")
apt = ["nginx-plus"] + WOVariables.wo_nginx
self.post_pref(apt, packages)
elif WOAptGet.is_installed(self, 'nginx'):
2019-04-03 07:53:25 +02:00
Log.info(self, "WordOps detected an already "
"installed nginx package."
"It may or may not have "
"required modules.\n")
2018-11-13 21:55:59 +01:00
apt = ["nginx"] + WOVariables.wo_nginx
self.post_pref(apt, packages)
else:
Log.debug(self, "Nginx Stable already installed")
2019-03-15 16:45:10 +01:00
# PHP 7.2
2019-08-07 03:05:32 +02:00
if pargs.php:
Log.debug(self, "Setting apt_packages variable for PHP 7.2")
2019-03-08 00:43:25 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.3-fpm')):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
2019-04-01 22:19:44 +02:00
WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php
2018-11-13 21:55:59 +01:00
else:
Log.debug(self, "PHP 7.2 already installed")
Log.info(self, "PHP 7.2 already installed")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# PHP 7.3
2019-08-07 03:05:32 +02:00
if pargs.php73:
2019-03-08 00:43:25 +01:00
Log.debug(self, "Setting apt_packages variable for PHP 7.3")
if not WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
WOVariables.wo_php73 + WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php73
2018-11-13 21:55:59 +01:00
else:
2019-03-08 00:43:25 +01:00
Log.debug(self, "PHP 7.3 already installed")
Log.info(self, "PHP 7.3 already installed")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# MariaDB 10.3
2019-08-07 03:05:32 +02:00
if pargs.mysql:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Setting apt_packages variable for MySQL")
if not WOShellExec.cmd_exec(self, "mysqladmin ping"):
apt_packages = apt_packages + WOVariables.wo_mysql
packages = packages + [["https://raw."
"githubusercontent.com/"
"major/MySQLTuner-perl"
"/master/mysqltuner.pl",
"/usr/bin/mysqltuner",
"MySQLTuner"]]
2019-07-29 11:23:23 +02:00
2019-08-15 23:46:16 +02:00
if pargs.mysqlclient:
Log.debug(self, "Setting apt_packages variable "
"for MySQL Client")
apt_packages = apt_packages + WOVariables.wo_mysql_client
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# WP-CLI
2019-08-07 03:05:32 +02:00
if pargs.wpcli:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Setting packages variable for WP-CLI")
if not WOShellExec.cmd_exec(self, "command -v wp"):
2018-11-13 21:55:59 +01:00
packages = packages + [["https://github.com/wp-cli/wp-cli/"
"releases/download/v{0}/"
"wp-cli-{0}.phar"
"".format(WOVariables.wo_wp_cli),
2019-03-04 07:12:57 +01:00
"/usr/local/bin/wp",
2018-11-13 21:55:59 +01:00
"WP-CLI"]]
else:
Log.debug(self, "WP-CLI is already installed")
Log.info(self, "WP-CLI is already installed")
2019-03-15 16:45:10 +01:00
2019-04-25 01:38:14 +02:00
# fail2ban
2019-08-07 03:05:32 +02:00
if pargs.fail2ban:
2019-04-25 01:38:14 +02:00
Log.debug(self, "Setting apt_packages variable for Fail2ban")
if not WOAptGet.is_installed(self, 'fail2ban'):
apt_packages = apt_packages + WOVariables.wo_fail2ban
else:
Log.debug(self, "Fail2ban already installed")
Log.info(self, "Fail2ban already installed")
2019-07-19 13:47:29 +02:00
# proftpd
2019-08-07 03:05:32 +02:00
if pargs.proftpd:
2019-07-19 13:47:29 +02:00
Log.debug(self, "Setting apt_packages variable for ProFTPd")
if not WOAptGet.is_installed(self, 'proftpd-basic'):
apt_packages = apt_packages + ["proftpd-basic"]
else:
Log.debug(self, "ProFTPd already installed")
Log.info(self, "ProFTPd already installed")
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpmyadmin:
2019-07-16 17:15:17 +02:00
if not os.path.isdir('/var/www/22222/htdocs/db/pma'):
Log.debug(self, "Setting packages variable "
"for phpMyAdmin ")
2019-08-07 03:05:32 +02:00
pargs.composer = True
2019-07-16 17:15:17 +02:00
packages = packages + [["https://github.com/phpmyadmin/"
"phpmyadmin/archive/STABLE.tar.gz",
"/var/lib/wo/tmp/pma.tar.gz",
"phpMyAdmin"]]
else:
Log.debug(self, "phpMyAdmin already installed")
Log.info(self, "phpMyAdmin already installed")
2019-04-01 20:59:53 +02:00
# Composer
2019-08-07 03:05:32 +02:00
if pargs.composer:
if not os.path.isfile('/usr/local/bin/composer'):
Log.debug(self, "Setting packages variable for Composer ")
packages = packages + [["https://getcomposer.org/"
"installer",
"/var/lib/wo/tmp/composer-install",
"Composer"]]
else:
Log.debug(self, "Composer already installed")
Log.info(self, "Composer already installed")
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpredisadmin:
if not os.path.isdir('/var/www/22222/htdocs/'
'cache/redis/phpRedisAdmin'):
2019-07-16 17:15:17 +02:00
Log.debug(
self, "Setting packages variable for phpRedisAdmin")
2019-08-07 03:05:32 +02:00
pargs.composer = True
2019-07-16 17:15:17 +02:00
packages = packages + [["https://github.com/"
"erikdubbelboer/"
"phpRedisAdmin/archive"
"/v1.11.3.tar.gz",
2019-07-16 17:15:17 +02:00
"/var/lib/wo/tmp/pra.tar.gz",
"phpRedisAdmin"]]
else:
Log.debug(self, "phpRedisAdmin already installed")
Log.info(self, "phpRedisAdmin already installed")
2019-03-15 16:45:10 +01:00
# ADMINER
2019-08-07 03:05:32 +02:00
if pargs.adminer:
2019-07-27 22:08:16 +02:00
Log.debug(self, "Setting packages variable for Adminer ")
packages = packages + [["https://github.com/vrana/adminer/"
"releases/download/v{0}"
"/adminer-{0}.php"
.format(WOVariables.wo_adminer),
"{0}22222/"
"htdocs/db/adminer/index.php"
.format(WOVariables.wo_webroot),
"Adminer"],
["https://raw.githubusercontent.com"
"/vrana/adminer/master/designs/"
"pepa-linha/adminer.css",
"{0}22222/"
"htdocs/db/adminer/adminer.css"
.format(WOVariables.wo_webroot),
"Adminer theme"]]
2019-04-16 08:50:15 +02:00
2019-04-02 01:59:40 +02:00
# Netdata
2019-08-07 03:05:32 +02:00
if pargs.netdata:
2019-04-02 01:59:40 +02:00
Log.debug(self, "Setting packages variable for Netdata")
2019-04-03 07:53:25 +02:00
if not os.path.exists('/opt/netdata'):
packages = packages + [['https://my-netdata.io/'
2019-04-23 19:03:42 +02:00
'kickstart-static64.sh',
'/var/lib/wo/tmp/kickstart.sh',
2019-04-03 07:53:25 +02:00
'Netdata']]
else:
Log.debug(self, "Netdata already installed")
Log.info(self, "Netdata already installed")
2019-04-02 01:59:40 +02:00
2019-04-23 19:03:42 +02:00
# WordOps Dashboard
2019-08-07 03:05:32 +02:00
if pargs.dashboard:
2019-07-16 17:15:17 +02:00
if not os.path.isfile('/var/www/22222/htdocs/index.php'):
Log.debug(
self, "Setting packages variable for WO-Dashboard")
packages = packages + \
2019-08-15 11:47:39 +02:00
[["https://github.com/WordOps/wordops-dashboard/"
"releases/download/v{0}/wordops-dashboard.tar.gz"
.format(WOVariables.wo_dashboard),
2019-07-16 17:15:17 +02:00
"/var/lib/wo/tmp/wo-dashboard.tar.gz",
"WordOps Dashboard"],
["https://github.com/soerennb/"
2019-07-27 22:08:16 +02:00
"extplorer/archive/v{0}.tar.gz"
.format(WOVariables.wo_extplorer),
2019-07-16 17:15:17 +02:00
"/var/lib/wo/tmp/extplorer.tar.gz",
"eXtplorer"]]
else:
Log.debug(self, "WordOps dashboard already installed")
Log.info(self, "WordOps dashboard already installed")
2019-04-23 19:03:42 +02:00
2019-03-15 16:45:10 +01:00
# UTILS
2019-08-07 03:05:32 +02:00
if pargs.utils:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Setting packages variable for utils")
2019-07-13 04:16:36 +02:00
packages = packages + [["https://raw.githubusercontent.com"
2018-11-13 21:55:59 +01:00
"/rtCamp/eeadmin/master/cache/nginx/"
"clean.php",
"{0}22222/htdocs/cache/"
"nginx/clean.php"
.format(WOVariables.wo_webroot),
"clean.php"],
["https://raw.github.com/rlerdorf/"
"opcache-status/master/opcache.php",
"{0}22222/htdocs/cache/"
"opcache/opcache.php"
.format(WOVariables.wo_webroot),
"opcache.php"],
["https://raw.github.com/amnuts/"
"opcache-gui/master/index.php",
"{0}22222/htdocs/"
"cache/opcache/opgui.php"
.format(WOVariables.wo_webroot),
"Opgui"],
["https://gist.github.com/ck-on/4959032"
"/raw/0b871b345fd6cfcd6d2be030c1f33d1"
"ad6a475cb/ocp.php",
"{0}22222/htdocs/cache/"
"opcache/ocp.php"
.format(WOVariables.wo_webroot),
"OCP.php"],
["https://github.com/jokkedk/webgrind/"
"archive/master.tar.gz",
2019-05-02 13:45:45 +02:00
'/var/lib/wo/tmp/webgrind.tar.gz',
'Webgrind'],
2019-07-13 04:50:28 +02:00
["https://www.percona.com/"
"get/pt-query-digest",
2018-11-13 21:55:59 +01:00
"/usr/bin/pt-query-advisor",
"pt-query-advisor"],
["https://github.com/box/Anemometer/"
"archive/master.tar.gz",
2019-05-02 13:45:45 +02:00
'/var/lib/wo/tmp/anemometer.tar.gz',
'Anemometer']
2018-11-13 21:55:59 +01:00
]
except Exception as e:
2019-07-29 15:08:49 +02:00
Log.debug(self, "{0}".format(e))
2018-11-13 21:55:59 +01:00
2019-04-30 18:50:30 +02:00
if (apt_packages) or (packages):
2019-07-17 03:00:53 +02:00
Log.debug(self, "Calling pre_pref")
2019-08-05 04:56:33 +02:00
pre_pref(self, apt_packages)
2019-04-30 18:50:30 +02:00
if (apt_packages):
2019-08-14 13:56:37 +02:00
# meminfo = (os.popen('/bin/cat /proc/meminfo '
# '| grep MemTotal').read()).split(":")
# memsplit = re.split(" kB", meminfo[1])
# wo_mem = int(memsplit[0])
# if (wo_mem < 4000000):
# WOSwap.add(self)
2018-11-13 21:55:59 +01:00
Log.info(self, "Updating apt-cache, please wait...")
WOAptGet.update(self)
Log.info(self, "Installing packages, please wait...")
2019-07-17 03:00:53 +02:00
WOAptGet.install(self, apt_packages)
2019-04-30 18:50:30 +02:00
if (packages):
2018-11-13 21:55:59 +01:00
Log.debug(self, "Downloading following: {0}".format(packages))
WODownload.download(self, packages)
2019-07-17 03:00:53 +02:00
Log.debug(self, "Calling post_pref")
2019-08-05 04:56:33 +02:00
post_pref(self, apt_packages, packages)
2019-07-25 11:40:12 +02:00
2018-11-13 21:55:59 +01:00
if disp_msg:
2019-04-30 18:50:30 +02:00
if (self.msg):
2018-11-13 21:55:59 +01:00
for msg in self.msg:
Log.info(self, Log.ENDC + msg)
Log.info(self, "Successfully installed packages")
else:
return self.msg
@expose(help="Remove packages")
def remove(self):
"""Start removal of packages"""
apt_packages = []
packages = []
2019-08-07 03:05:32 +02:00
pargs = self.app.pargs
if ((not pargs.web) and (not pargs.admin) and
(not pargs.nginx) and (not pargs.php) and
(not pargs.php73) and (not pargs.mysql) and
(not pargs.wpcli) and (not pargs.phpmyadmin) and
(not pargs.adminer) and (not pargs.utils) and
(not pargs.composer) and (not pargs.netdata) and
(not pargs.fail2ban) and (not pargs.proftpd) and
(not pargs.security) and
(not pargs.all) and (not pargs.redis) and
(not pargs.phpredisadmin)):
pargs.web = True
pargs.admin = True
pargs.security = True
if pargs.all:
pargs.web = True
pargs.admin = True
pargs.php73 = True
if pargs.web:
pargs.nginx = True
pargs.php = True
pargs.mysql = True
pargs.wpcli = True
if pargs.admin:
pargs.composer = True
pargs.utils = True
pargs.netdata = True
if os.path.isdir('{0}22222/htdocs'
.format(WOVariables.wo_webroot)):
packages = packages + ['{0}22222/htdocs/*'
.format(WOVariables.wo_webroot)]
2018-11-13 21:55:59 +01:00
2019-08-07 03:05:32 +02:00
if pargs.security:
pargs.fail2ban = True
2019-03-15 16:45:10 +01:00
# NGINX
2019-08-07 03:05:32 +02:00
if pargs.nginx:
2018-11-13 21:55:59 +01:00
if WOAptGet.is_installed(self, 'nginx-custom'):
Log.debug(self, "Removing apt_packages variable of Nginx")
apt_packages = apt_packages + WOVariables.wo_nginx
else:
2019-04-11 20:35:03 +02:00
Log.error(self, "Cannot Remove! Nginx Stable "
"version not found.")
2019-03-15 16:45:10 +01:00
# PHP 7.2
2019-08-07 03:05:32 +02:00
if pargs.php:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing apt_packages variable of PHP")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if not WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
WOVariables.wo_php_extra
2019-03-27 12:49:17 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php
else:
Log.error(self, "PHP 7.2 not found")
2018-11-13 21:55:59 +01:00
2019-03-08 00:43:25 +01:00
# PHP7.3
2019-08-07 03:05:32 +02:00
if pargs.php73:
2019-03-15 16:45:10 +01:00
Log.debug(self, "Removing apt_packages variable of PHP 7.3")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-04-01 20:59:53 +02:00
apt_packages = apt_packages + WOVariables.wo_php73 + \
2019-04-01 22:19:44 +02:00
WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php73
2019-03-27 12:49:17 +01:00
else:
Log.error(self, "PHP 7.3 not found")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# REDIS
2019-08-07 03:05:32 +02:00
if pargs.redis:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Remove apt_packages variable of Redis")
apt_packages = apt_packages + WOVariables.wo_redis
2019-03-15 16:45:10 +01:00
# MariaDB
2019-08-07 03:05:32 +02:00
if pargs.mysql:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing apt_packages variable of MySQL")
apt_packages = apt_packages + WOVariables.wo_mysql
packages = packages + ['/usr/bin/mysqltuner']
2019-07-18 17:04:20 +02:00
# fail2ban
2019-08-07 03:05:32 +02:00
if pargs.fail2ban:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'fail2ban'):
Log.debug(self, "Remove apt_packages variable of Fail2ban")
apt_packages = apt_packages + WOVariables.wo_fail2ban
else:
Log.error(self, "Fail2ban not found")
# proftpd
2019-08-07 03:05:32 +02:00
if pargs.proftpd:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'proftpd-basic'):
Log.debug(self, "Remove apt_packages variable for ProFTPd")
apt_packages = apt_packages + ["proftpd-basic"]
else:
Log.error(self, "ProFTPd not found")
2019-07-18 17:04:20 +02:00
2019-03-15 16:45:10 +01:00
# WPCLI
2019-08-07 03:05:32 +02:00
if pargs.wpcli:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of WPCLI ")
2019-03-04 07:12:57 +01:00
if os.path.isfile('/usr/local/bin/wp'):
packages = packages + ['/usr/local/bin/wp']
2018-11-13 21:55:59 +01:00
else:
Log.warn(self, "WP-CLI is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpmyadmin:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of phpMyAdmin ")
packages = packages + ['{0}22222/htdocs/db/pma'
.format(WOVariables.wo_webroot)]
# Composer
2019-08-07 03:05:32 +02:00
if pargs.composer:
Log.debug(self, "Removing package variable of Composer ")
if os.path.isfile('/usr/local/bin/composer'):
packages = packages + ['/usr/local/bin/composer']
else:
Log.warn(self, "Composer is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpredisadmin:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of phpRedisAdmin ")
if os.path.isdir('{0}22222/htdocs/cache/redis'
.format(WOVariables.wo_webroot)):
packages = packages + ['{0}22222/htdocs/'
'cache/redis/phpRedisAdmin'
.format(WOVariables.wo_webroot)]
2019-03-15 16:45:10 +01:00
# ADMINER
2019-08-07 03:05:32 +02:00
if pargs.adminer:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of Adminer ")
packages = packages + ['{0}22222/htdocs/db/adminer'
.format(WOVariables.wo_webroot)]
2019-08-07 03:05:32 +02:00
if pargs.utils:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of utils ")
packages = packages + ['{0}22222/htdocs/php/webgrind/'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/opcache'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/nginx/'
'clean.php'.format(WOVariables.wo_webroot),
'/usr/bin/pt-query-advisor',
'{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot)]
2019-08-07 03:05:32 +02:00
if pargs.netdata:
Log.debug(self, "Removing Netdata")
if os.path.isfile('/opt/netdata/usr/'
'libexec/netdata-uninstaller.sh'):
packages = packages + ['/var/lib/wo/tmp/kickstart.sh']
2019-08-07 03:05:32 +02:00
if pargs.dashboard:
Log.debug(self, "Removing Wo-Dashboard")
2019-08-07 03:05:32 +02:00
packages = packages + ['{0}22222/htdocs/assets'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/index.php'
.format(WOVariables.wo_webroot)]
2019-04-30 18:50:30 +02:00
if (packages) or (apt_packages):
2019-08-07 03:05:32 +02:00
if not pargs.force:
wo_prompt = input('Are you sure you to want to'
' remove from server.'
'\nPackage configuration will remain'
' on server after this operation.\n'
'Any answer other than '
'"yes" will be stop this'
' operation : ')
if (wo_prompt == 'YES' or wo_prompt == 'yes'
or pargs.force):
2018-11-13 21:55:59 +01:00
if (set(["nginx-custom"]).issubset(set(apt_packages))):
2018-11-13 21:55:59 +01:00
WOService.stop_service(self, 'nginx')
# Netdata uninstaller
if (set(['/var/lib/wo/tmp/'
'kickstart.sh']).issubset(set(packages))):
WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/"
"libexec/netdata-"
"uninstaller.sh -y -f")
2019-04-30 18:50:30 +02:00
if (packages):
2018-11-13 21:55:59 +01:00
WOFileUtils.remove(self, packages)
WOAptGet.auto_remove(self)
2019-04-30 18:50:30 +02:00
if (apt_packages):
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing apt_packages")
Log.info(self, "Removing packages, please wait...")
WOAptGet.remove(self, apt_packages)
WOAptGet.auto_remove(self)
Log.info(self, "Successfully removed packages")
@expose(help="Purge packages")
def purge(self):
"""Start purging of packages"""
apt_packages = []
packages = []
2019-08-07 03:05:32 +02:00
pargs = self.app.pargs
2018-11-13 21:55:59 +01:00
# Default action for stack purge
2019-08-07 03:05:32 +02:00
if ((not pargs.web) and (not pargs.admin) and
(not pargs.nginx) and (not pargs.php) and
(not pargs.php73) and (not pargs.mysql) and
(not pargs.wpcli) and (not pargs.phpmyadmin) and
(not pargs.adminer) and (not pargs.utils) and
(not pargs.composer) and (not pargs.netdata) and
(not pargs.fail2ban) and (not pargs.proftpd) and
(not pargs.security) and
(not pargs.all) and (not pargs.redis) and
(not pargs.phpredisadmin)):
pargs.web = True
pargs.admin = True
pargs.security = True
if pargs.all:
pargs.web = True
pargs.admin = True
pargs.php73 = True
if pargs.web:
pargs.nginx = True
pargs.php = True
pargs.mysql = True
pargs.wpcli = True
if pargs.admin:
pargs.utils = True
pargs.composer = True
pargs.netdata = True
if os.path.isdir('{0}22222/htdocs'
.format(WOVariables.wo_webroot)):
packages = packages + ['{0}22222/htdocs/*'
.format(WOVariables.wo_webroot)]
if pargs.security:
pargs.fail2ban = True
2019-03-15 16:45:10 +01:00
# NGINX
2019-08-07 03:05:32 +02:00
if pargs.nginx:
2018-11-13 21:55:59 +01:00
if WOAptGet.is_installed(self, 'nginx-custom'):
Log.debug(self, "Purge apt_packages variable of Nginx")
apt_packages = apt_packages + WOVariables.wo_nginx
else:
2019-04-23 19:03:42 +02:00
Log.error(self, "Cannot Purge! "
"Nginx Stable version not found.")
2019-03-15 16:45:10 +01:00
# PHP
2019-08-07 03:05:32 +02:00
if pargs.php:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Purge apt_packages variable PHP")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.2-fpm'):
if not (WOAptGet.is_installed(self, 'php7.3-fpm')):
2019-04-11 20:35:03 +02:00
apt_packages = apt_packages + WOVariables.wo_php + \
WOVariables.wo_php_extra
2019-03-27 12:49:17 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php
2018-11-13 21:55:59 +01:00
else:
2019-03-15 16:45:10 +01:00
Log.error(self, "Cannot Purge PHP 7.2. not found.")
2018-11-13 21:55:59 +01:00
2019-03-15 16:45:10 +01:00
# PHP 7.3
2019-08-07 03:05:32 +02:00
if pargs.php73:
2019-03-15 16:45:10 +01:00
Log.debug(self, "Removing apt_packages variable of PHP 7.3")
2019-03-27 12:49:17 +01:00
if WOAptGet.is_installed(self, 'php7.3-fpm'):
2019-03-16 09:18:15 +01:00
if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
2019-04-11 20:35:03 +02:00
apt_packages = apt_packages + WOVariables.wo_php73 + \
WOVariables.wo_php_extra
2019-03-16 09:18:15 +01:00
else:
apt_packages = apt_packages + WOVariables.wo_php73
2019-03-27 12:49:17 +01:00
2019-07-18 17:04:20 +02:00
# fail2ban
2019-08-07 03:05:32 +02:00
if pargs.fail2ban:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'fail2ban'):
Log.debug(self, "Purge apt_packages variable of Fail2ban")
apt_packages = apt_packages + WOVariables.wo_fail2ban
# proftpd
2019-08-07 03:05:32 +02:00
if pargs.proftpd:
2019-07-19 13:47:29 +02:00
if WOAptGet.is_installed(self, 'proftpd-basic'):
Log.debug(self, "Purge apt_packages variable for ProFTPd")
apt_packages = apt_packages + ["proftpd-basic"]
2019-07-18 17:04:20 +02:00
2019-03-15 16:45:10 +01:00
# WP-CLI
2019-08-07 03:05:32 +02:00
if pargs.wpcli:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Purge package variable WPCLI")
2019-03-04 07:12:57 +01:00
if os.path.isfile('/usr/local/bin/wp'):
packages = packages + ['/usr/local/bin/wp']
2018-11-13 21:55:59 +01:00
else:
Log.warn(self, "WP-CLI is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPMYADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpmyadmin:
2018-11-13 21:55:59 +01:00
packages = packages + ['{0}22222/htdocs/db/pma'.
format(WOVariables.wo_webroot)]
Log.debug(self, "Purge package variable phpMyAdmin")
2019-03-15 16:45:10 +01:00
# Composer
2019-08-07 03:05:32 +02:00
if pargs.composer:
Log.debug(self, "Removing package variable of Composer ")
if os.path.isfile('/usr/local/bin/composer'):
packages = packages + ['/usr/local/bin/composer']
else:
Log.warn(self, "Composer is not installed with WordOps")
2019-03-15 16:45:10 +01:00
# PHPREDISADMIN
2019-08-07 03:05:32 +02:00
if pargs.phpredisadmin:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Removing package variable of phpRedisAdmin ")
if os.path.isdir('{0}22222/htdocs/cache/redis'
.format(WOVariables.wo_webroot)):
packages = packages + ['{0}22222/htdocs/'
'cache/redis/phpRedisAdmin'
.format(WOVariables.wo_webroot)]
2019-03-15 16:45:10 +01:00
# Adminer
2019-08-07 03:05:32 +02:00
if pargs.adminer:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Purge package variable Adminer")
packages = packages + ['{0}22222/htdocs/db/adminer'
.format(WOVariables.wo_webroot)]
2019-03-15 16:45:10 +01:00
# utils
2019-08-07 03:05:32 +02:00
if pargs.utils:
2018-11-13 21:55:59 +01:00
Log.debug(self, "Purge package variable utils")
packages = packages + ['{0}22222/htdocs/php/webgrind/'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/opcache'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/cache/nginx/'
'clean.php'.format(WOVariables.wo_webroot),
'/usr/bin/pt-query-advisor',
'{0}22222/htdocs/db/anemometer'
.format(WOVariables.wo_webroot)
]
2019-08-07 03:05:32 +02:00
if pargs.netdata:
Log.debug(self, "Removing Netdata")
if os.path.isfile('/opt/netdata/usr/'
'libexec/netdata-uninstaller.sh'):
packages = packages + ['/var/lib/wo/tmp/kickstart.sh']
2019-08-07 03:05:32 +02:00
if pargs.dashboard:
Log.debug(self, "Removing Wo-Dashboard")
packages = packages + ['{0}22222/htdocs/assets/'
.format(WOVariables.wo_webroot),
'{0}22222/htdocs/index.php'
.format(WOVariables.wo_webroot)]
2019-04-30 18:50:30 +02:00
if (packages) or (apt_packages):
2018-11-13 21:55:59 +01:00
wo_prompt = input('Are you sure you to want to purge '
'from server '
'along with their configuration'
' packages,\nAny answer other than '
'"yes" will be stop this '
'operation :')
2019-08-07 03:05:32 +02:00
if wo_prompt == 'YES' or wo_prompt == 'yes' or pargs.force:
2018-11-13 21:55:59 +01:00
if (set(["nginx-custom"]).issubset(set(apt_packages))):
2018-11-13 21:55:59 +01:00
WOService.stop_service(self, 'nginx')
# Netdata uninstaller
if (set(['/var/lib/wo/tmp/'
'kickstart.sh']).issubset(set(packages))):
WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/"
"libexec/netdata-"
"uninstaller.sh -y -f")
if (set(["fail2ban"]).issubset(set(apt_packages))):
WOService.stop_service(self, 'fail2ban')
2019-04-30 18:50:30 +02:00
if (apt_packages):
2018-11-13 21:55:59 +01:00
Log.info(self, "Purging packages, please wait...")
WOAptGet.remove(self, apt_packages, purge=True)
WOAptGet.auto_remove(self)
2019-04-30 18:50:30 +02:00
if (packages):
2018-11-13 21:55:59 +01:00
WOFileUtils.remove(self, packages)
WOAptGet.auto_remove(self)
Log.info(self, "Successfully purged packages")
2019-03-07 18:38:19 +01:00
2018-11-13 21:55:59 +01:00
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(WOStackController)
handler.register(WOStackStatusController)
handler.register(WOStackMigrateController)
handler.register(WOStackUpgradeController)
# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', wo_stack_hook)