Improve debug log & maintenance

* refactored command `wo maintenance`
This commit is contained in:
VirtuBox
2019-07-25 08:24:02 +02:00
parent ba2c2fec5d
commit dbb7dfc956
6 changed files with 90 additions and 76 deletions

View File

@@ -53,3 +53,4 @@ script:
- sudo wo stack upgrade --composer --no-prompt - sudo wo stack upgrade --composer --no-prompt
- sudo wo update --travis - sudo wo update --travis
- sudo wo stack status - sudo wo stack status
- sudo wo maintenance

41
install
View File

@@ -413,7 +413,7 @@ wo_install() {
>> "$wo_install_log" 2>&1 >> "$wo_install_log" 2>&1
if [ "$wo_force_install" = "y" ]; then if [ "$wo_force_install" = "y" ]; then
[ ! -f "$HOME/.gitconfig" ] && { bash -c 'echo -e "[user]\n\tname = $USER\n\temail = root@$HOSTNAME.local" > $HOME/.gitconfig'; } [ ! -f "$HOME/.gitconfig" ] && { bash -c 'echo -e "[user]\n\tname = $USER\n\temail = root@$HOSTNAME.local" > $HOME/.gitconfig'; }
fi fi
if [ -f "$HOME/.gitconfig" ]; then if [ -f "$HOME/.gitconfig" ]; then
@@ -449,7 +449,7 @@ wo_upgrade_nginx() {
# add new Nginx repository # add new Nginx repository
if [ "$wo_linux_distro" = "Ubuntu" ]; then if [ "$wo_linux_distro" = "Ubuntu" ]; then
if [ ! -f /etc/apt/sources.list.d/wordops-ubuntu-nginx-wo-"$(lsb_release -sc)".list ]; then if [ ! -f /etc/apt/sources.list.d/wordops-ubuntu-nginx-wo-"$(lsb_release -sc)".list ]; then
add-apt-repository ppa:wordops/nginx-wo -y -u add-apt-repository ppa:wordops/nginx-wo -y -u
fi fi
else else
if [ "$wo_distro_version" == "jessie" ]; then if [ "$wo_distro_version" == "jessie" ]; then
@@ -469,28 +469,29 @@ wo_upgrade_nginx() {
} }
# install new nginx package # install new nginx package
if [ -x /usr/local/bin/wo ]; then if [ -n "$CHECK_NGINX_EE" ] || [ -n "$CHECK_NGINX_WO" ]; then
if [ -x /usr/local/bin/wo ]; then
if [ -n "$CHECK_NGINX_EE" ]; then
# remove previous package
apt-mark unhold nginx-ee nginx-common nginx-custom
apt-get --assume-yes purge nginx-ee nginx-common nginx-custom --allow-change-held-packages
# remove previous php-fpm pool configuration
if [ -n "$CHECK_PHP72" ]; then
apt-get purge php7.2-fpm -y -qq
rm -f /etc/php/7.2/fpm/pool.d/{www.conf,www-two.conf,debug.conf}
fi
elif [ -n "$CHECK_NGINX_WO" ]; then
apt-mark unhold nginx-wo nginx-common nginx-custom
apt-get --assume-yes purge nginx-wo nginx-common nginx-custom --allow-change-held-packages
if [ -n "$CHECK_NGINX_EE" ]; then
# remove previous package
apt-mark unhold nginx-ee nginx-common nginx-custom
apt-get -y purge nginx-ee nginx-common nginx-custom --allow-change-held-packages
# remove previous php-fpm pool configuration
if [ -n "$CHECK_PHP72" ]; then
apt-get purge php7.2-fpm -y -qq
rm -f /etc/php/7.2/fpm/pool.d/{www.conf,www-two.conf,debug.conf}
fi fi
elif [ -n "$CHECK_NGINX_WO" ]; then if [ -d /etc/nginx ]; then
apt-mark unhold nginx-wo nginx-common nginx-custom rm -rf /etc/nginx
apt-get -y purge nginx-wo nginx-common nginx-custom --allow-change-held-packages fi
/usr/local/bin/wo stack install --nginx --php
rm -f /etc/nginx/common/acl.conf /etc/nginx/conf.d/{map-wp-cache.conf,map-wp.conf,fascgi.conf,blockips.conf} /etc/nginx/htpasswd-wo
fi fi
if [ -d /etc/nginx ]; then
rm -rf /etc/nginx
fi
/usr/local/bin/wo stack install --nginx --php
rm -f /etc/nginx/common/acl.conf /etc/nginx/conf.d/{map-wp-cache.conf,map-wp.conf,fascgi.conf,blockips.conf} /etc/nginx/htpasswd-wo
fi fi
# restore sites and configuration # restore sites and configuration

View File

@@ -3,11 +3,7 @@
from cement.core.controller import CementBaseController, expose from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook from cement.core import handler, hook
from wo.core.logging import Log from wo.core.logging import Log
from wo.core.variables import WOVariables
from wo.core.aptget import WOAptGet from wo.core.aptget import WOAptGet
from wo.core.apt_repo import WORepo
from wo.core.services import WOService
from wo.core.shellexec import WOShellExec
def wo_maintenance_hook(app): def wo_maintenance_hook(app):
@@ -27,16 +23,12 @@ class WOMaintenanceController(CementBaseController):
try: try:
Log.info(self, "updating apt-cache, please wait...") Log.info(self, "updating apt-cache, please wait...")
WOShellExec.cmd_exec(self, "apt-get update") WOAptGet.update(self)
Log.info(self, "updating packages, please wait...") Log.info(self, "updating packages, please wait...")
WOShellExec.cmd_exec(self, "DEBIAN_FRONTEND=noninteractive " WOAptGet.dist_upgrade(self)
"apt-get -o "
"Dpkg::Options::='--force-confmiss' "
"-o Dpkg::Options::='--force-confold' "
"-y dist-upgrade")
Log.info(self, "cleaning-up packages, please wait...") Log.info(self, "cleaning-up packages, please wait...")
WOShellExec.cmd_exec(self, "apt-get -y --purge autoremove") WOAptGet.auto_remove(self)
WOShellExec.cmd_exec(self, "apt-get -y autoclean") WOAptGet.auto_clean(self)
except OSError as e: except OSError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.error(self, "Package updates failed !") Log.error(self, "Package updates failed !")

View File

@@ -619,7 +619,7 @@ class WOSiteCreateController(CementBaseController):
if (data['wp'] and (self.app.pargs.vhostonly)): if (data['wp'] and (self.app.pargs.vhostonly)):
try: try:
data = setupdatabase(self, data) wo_wp_creds = setupwordpress(self, data)
# Add database information for site into database # Add database information for site into database
updateSiteInfo(self, wo_domain, db_name=data['wo_db_name'], updateSiteInfo(self, wo_domain, db_name=data['wo_db_name'],
db_user=data['wo_db_user'], db_user=data['wo_db_user'],

View File

@@ -1,7 +1,7 @@
from wo.cli.plugins.stack import WOStackController from wo.cli.plugins.stack import WOStackController
from wo.core.fileutils import WOFileUtils from wo.core.fileutils import WOFileUtils
from wo.core.mysql import * from wo.core.mysql import *
from wo.core.shellexec import * from wo.core.shellexec import WOShellExec, CommandExecutionError
from wo.core.sslutils import SSL from wo.core.sslutils import SSL
from wo.core.variables import WOVariables from wo.core.variables import WOVariables
from wo.cli.plugins.sitedb import * from wo.cli.plugins.sitedb import *
@@ -670,6 +670,7 @@ def installwp_plugin(self, plugin_name, data):
else '' else ''
)) ))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("plugin activation failed") raise SiteError("plugin activation failed")
return 1 return 1
@@ -693,6 +694,7 @@ def uninstallwp_plugin(self, plugin_name, data):
"--allow-root uninstall " "--allow-root uninstall "
"{0}".format(plugin_name)) "{0}".format(plugin_name))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("plugin uninstall failed") raise SiteError("plugin uninstall failed")
@@ -710,6 +712,7 @@ def setupwp_plugin(self, plugin_name, plugin_option, plugin_data, data):
"{0} \'{1}\' --format=json" "{0} \'{1}\' --format=json"
.format(plugin_option, plugin_data)) .format(plugin_option, plugin_data))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("plugin setup failed") raise SiteError("plugin setup failed")
else: else:
try: try:
@@ -720,6 +723,7 @@ def setupwp_plugin(self, plugin_name, plugin_option, plugin_data, data):
.format(plugin_option, plugin_data .format(plugin_option, plugin_data
)) ))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("plugin setup failed") raise SiteError("plugin setup failed")
@@ -1001,6 +1005,7 @@ def updatewpuserpassword(self, wo_domain, wo_site_webroot):
is_wp = WOShellExec.cmd_exec(self, "wp --allow-root core" is_wp = WOShellExec.cmd_exec(self, "wp --allow-root core"
" version") " version")
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("is WordPress site? check command failed ") raise SiteError("is WordPress site? check command failed ")
# Exit if wo_domain is not wordpress install # Exit if wo_domain is not wordpress install
@@ -1020,6 +1025,7 @@ def updatewpuserpassword(self, wo_domain, wo_site_webroot):
WOShellExec.cmd_exec(self, "wp --allow-root user list " WOShellExec.cmd_exec(self, "wp --allow-root user list "
"--fields=user_login | grep -v user_login") "--fields=user_login | grep -v user_login")
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("fetch wp userlist command failed") raise SiteError("fetch wp userlist command failed")
if not wo_wp_user: if not wo_wp_user:
@@ -1030,6 +1036,7 @@ def updatewpuserpassword(self, wo_domain, wo_site_webroot):
"--fields=user_login | grep {0}$ " "--fields=user_login | grep {0}$ "
.format(wo_wp_user)) .format(wo_wp_user))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("if wp user exists check command failed") raise SiteError("if wp user exists check command failed")
if is_user_exist: if is_user_exist:
@@ -1308,6 +1315,7 @@ def removeAcmeConf(self, domain):
"-d {0} --ecc" "-d {0} --ecc"
.format(domain)) .format(domain))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Cert removal failed") Log.error(self, "Cert removal failed")
WOFileUtils.rm(self, '/etc/letsencrypt/renewal/{0}_ecc' WOFileUtils.rm(self, '/etc/letsencrypt/renewal/{0}_ecc'
@@ -1651,8 +1659,6 @@ def archivedCertificateHandle(self, domain):
.format(WOVariables.wo_ssl_live, domain)) .format(WOVariables.wo_ssl_live, domain))
sslconf.close() sslconf.close()
updateSiteInfo(self, domain, ssl=True)
except IOError as e: except IOError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.debug(self, "Error occured while generating " Log.debug(self, "Error occured while generating "
@@ -1667,8 +1673,6 @@ def archivedCertificateHandle(self, domain):
"\n\t/etc/letsencrypt/live/{0}/fullchain.pem\n\t" "\n\t/etc/letsencrypt/live/{0}/fullchain.pem\n\t"
"/etc/letsencrypt/live/{0}/key.pem".format(domain)) "/etc/letsencrypt/live/{0}/key.pem".format(domain))
updateSiteInfo(self, domain, ssl=True)
elif (check_prompt == "3"): elif (check_prompt == "3"):
Log.info(self, "Issuing SSL cert with acme.sh") Log.info(self, "Issuing SSL cert with acme.sh")
ssl = WOShellExec.cmd_exec(self, "/etc/letsencrypt/acme.sh " ssl = WOShellExec.cmd_exec(self, "/etc/letsencrypt/acme.sh "

View File

@@ -1,36 +1,39 @@
"""Stack Plugin for WordOps""" """Stack Plugin for WordOps"""
from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook from cement.core import handler, hook
from wo.cli.plugins.site_functions import * from cement.core.controller import CementBaseController, expose
from wo.core.variables import WOVariables
from wo.core.aptget import WOAptGet
from wo.core.download import WODownload
from wo.core.shellexec import WOShellExec, CommandExecutionError
from wo.core.fileutils import WOFileUtils
from wo.core.apt_repo import WORepo
from wo.core.extract import WOExtract
from wo.core.mysql import WOMysql
from wo.core.addswap import WOSwap
from wo.core.git import WOGit
from wo.core.checkfqdn import check_fqdn
from pynginxconfig import NginxConfig
from wo.core.services import WOService
import random
import string
import configparser
import shutil
import os
import pwd
import grp
import codecs import codecs
import configparser
import grp
import os
import platform import platform
import pwd
import random
import shutil
import string
import psutil import psutil
from wo.cli.plugins.stack_services import WOStackStatusController # from pynginxconfig import NginxConfig
from wo.cli.plugins.stack_migrate import WOStackMigrateController from wo.cli.plugins.site_functions import *
from wo.cli.plugins.stack_upgrade import WOStackUpgradeController
from wo.core.logging import Log
from wo.cli.plugins.sitedb import * from wo.cli.plugins.sitedb import *
from wo.cli.plugins.stack_migrate import WOStackMigrateController
from wo.cli.plugins.stack_services import WOStackStatusController
from wo.cli.plugins.stack_upgrade import WOStackUpgradeController
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.checkfqdn import check_fqdn
from wo.core.download import WODownload
from wo.core.extract import WOExtract
from wo.core.fileutils import WOFileUtils
from wo.core.git import WOGit
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
def wo_stack_hook(app): def wo_stack_hook(app):
@@ -129,6 +132,7 @@ class WOStackController(CementBaseController):
.format(chars=chars), .format(chars=chars),
log=False) log=False)
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error("Failed to initialize MySQL package") Log.error("Failed to initialize MySQL package")
Log.debug(self, "echo \"mariadb-server-10.3 " Log.debug(self, "echo \"mariadb-server-10.3 "
@@ -143,6 +147,7 @@ class WOStackController(CementBaseController):
.format(chars=chars), .format(chars=chars),
log=False) log=False)
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error("Failed to initialize MySQL package") Log.error("Failed to initialize MySQL package")
else: else:
Log.debug(self, "Pre-seeding MySQL") Log.debug(self, "Pre-seeding MySQL")
@@ -158,6 +163,7 @@ class WOStackController(CementBaseController):
.format(chars=chars), .format(chars=chars),
log=False) log=False)
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error("Failed to initialize MySQL package") Log.error("Failed to initialize MySQL package")
Log.debug(self, "echo \"mariadb-server-10.1 " Log.debug(self, "echo \"mariadb-server-10.1 "
@@ -172,6 +178,7 @@ class WOStackController(CementBaseController):
.format(chars=chars), .format(chars=chars),
log=False) log=False)
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error("Failed to initialize MySQL package") Log.error("Failed to initialize MySQL package")
# generate my.cnf root credentials # generate my.cnf root credentials
mysql_config = """ mysql_config = """
@@ -473,6 +480,7 @@ class WOStackController(CementBaseController):
"2>/dev/null" "2>/dev/null"
.format(password=passwd)) .format(password=passwd))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Failed to save HTTP Auth") Log.error(self, "Failed to save HTTP Auth")
# Create Symbolic link for 22222 # Create Symbolic link for 22222
@@ -552,6 +560,7 @@ class WOStackController(CementBaseController):
.format(WOVariables.wo_webroot)) .format(WOVariables.wo_webroot))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error( Log.error(
self, "Failed to generate HTTPS " self, "Failed to generate HTTPS "
"certificate for 22222") "certificate for 22222")
@@ -1076,10 +1085,14 @@ class WOStackController(CementBaseController):
"query_cache_type = 1 \" " "query_cache_type = 1 \" "
"/etc/mysql/my.cnf") "/etc/mysql/my.cnf")
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to update MySQL file") Log.error(self, "Unable to update MySQL file")
WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775) WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775)
WOCron.setcron_weekly(self, 'mysqlcheck -Aos --auto-repair '
'> /dev/null 2>&1',
comment='MySQL optimization cronjob '
'added by WordOps')
WOGit.add(self, ["/etc/mysql"], msg="Adding MySQL into Git") WOGit.add(self, ["/etc/mysql"], msg="Adding MySQL into Git")
WOService.reload_service(self, 'mysql') WOService.reload_service(self, 'mysql')
@@ -1138,6 +1151,7 @@ class WOStackController(CementBaseController):
WOShellExec.cmd_exec(self, "ufw allow " WOShellExec.cmd_exec(self, "ufw allow "
"49000:50000/tcp") "49000:50000/tcp")
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to add UFW rule") Log.error(self, "Unable to add UFW rule")
if os.path.isfile("/etc/fail2ban/jail.d/custom.conf"): if os.path.isfile("/etc/fail2ban/jail.d/custom.conf"):
@@ -1265,6 +1279,7 @@ class WOStackController(CementBaseController):
"flush privileges;", "flush privileges;",
log=False) log=False)
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.info( Log.info(
self, "fail to setup mysql user for netdata") self, "fail to setup mysql user for netdata")
WOService.restart_service(self, 'netdata') WOService.restart_service(self, 'netdata')
@@ -1386,6 +1401,7 @@ class WOStackController(CementBaseController):
'/anemometer/install.sql' '/anemometer/install.sql'
.format(WOVariables.wo_webroot)) .format(WOVariables.wo_webroot))
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
raise SiteError("Unable to import Anemometer database") raise SiteError("Unable to import Anemometer database")
WOMysql.execute(self, 'grant select on' WOMysql.execute(self, 'grant select on'
@@ -1657,16 +1673,16 @@ class WOStackController(CementBaseController):
Log.debug(self, "Setting packages variable for Adminer ") Log.debug(self, "Setting packages variable for Adminer ")
packages = packages + [["https://github.com/vrana/adminer/" packages = packages + [["https://github.com/vrana/adminer/"
"releases/download/v{0}" "releases/download/v{0}"
"/adminer-{0}.php" "/adminer-{0}.php"
.format(WOVariables.wo_adminer), .format(WOVariables.wo_adminer),
"{0}22222/" "{0}22222/"
"htdocs/db/adminer/index.php" "htdocs/db/adminer/index.php"
.format(WOVariables.wo_webroot), .format(WOVariables.wo_webroot),
"Adminer"], "Adminer"],
["https://raw.githubusercontent.com" ["https://raw.githubusercontent.com"
"/vrana/adminer/master/designs/" "/vrana/adminer/master/designs/"
"pepa-linha/adminer.css", "pepa-linha/adminer.css",
"{0}22222/" "{0}22222/"
"htdocs/db/adminer/adminer.css" "htdocs/db/adminer/adminer.css"
.format(WOVariables.wo_webroot), .format(WOVariables.wo_webroot),
"Adminer theme"]] "Adminer theme"]]