Several improvements

This commit is contained in:
VirtuBox
2019-08-31 14:18:38 +02:00
parent 91fe49fd81
commit 4684265d3d

View File

@@ -331,7 +331,8 @@ def post_pref(self, apt_packages, packages, upgrade=False):
"/redis.conf")): "/redis.conf")):
with open("/etc/nginx/conf.d/" with open("/etc/nginx/conf.d/"
"redis.conf", "a") as redis_file: "redis.conf", "a") as redis_file:
redis_file.write("# Log format Settings\n" redis_file.write(
"# Log format Settings\n"
"log_format rt_cache_redis " "log_format rt_cache_redis "
"'$remote_addr " "'$remote_addr "
"$upstream_response_time " "$upstream_response_time "
@@ -357,14 +358,16 @@ def post_pref(self, apt_packages, packages, upgrade=False):
# 22222 port settings # 22222 port settings
if not os.path.isfile('/etc/nginx/sites-available/22222'): if not os.path.isfile('/etc/nginx/sites-available/22222'):
WOTemplate.render(self, WOTemplate.render(
self,
'/etc/nginx/sites-available/22222', '/etc/nginx/sites-available/22222',
'22222.mustache', data, overwrite=False) '22222.mustache', data, overwrite=False)
passwd = ''.join([random.choice passwd = ''.join([random.choice
(string.ascii_letters + string.digits) (string.ascii_letters + string.digits)
for n in range(24)]) for n in range(24)])
try: try:
WOShellExec.cmd_exec(self, "printf \"WordOps:" WOShellExec.cmd_exec(
self, "printf \"WordOps:"
"$(openssl passwd -crypt " "$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\"" "{password} 2> /dev/null)\n\""
"> /etc/nginx/htpasswd-wo " "> /etc/nginx/htpasswd-wo "
@@ -375,7 +378,8 @@ def post_pref(self, apt_packages, packages, upgrade=False):
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
WOFileUtils.create_symlink(self, ['/etc/nginx/' WOFileUtils.create_symlink(
self, ['/etc/nginx/'
'sites-available/' 'sites-available/'
'22222', '22222',
'/etc/nginx/' '/etc/nginx/'
@@ -406,7 +410,8 @@ def post_pref(self, apt_packages, packages, upgrade=False):
os.makedirs('{0}22222/conf/nginx' os.makedirs('{0}22222/conf/nginx'
.format(ngxroot)) .format(ngxroot))
WOFileUtils.create_symlink(self, WOFileUtils.create_symlink(
self,
['/var/log/nginx/' ['/var/log/nginx/'
'22222.access.log', '22222.access.log',
'{0}22222/' '{0}22222/'
@@ -414,7 +419,8 @@ def post_pref(self, apt_packages, packages, upgrade=False):
.format(ngxroot)] .format(ngxroot)]
) )
WOFileUtils.create_symlink(self, WOFileUtils.create_symlink(
self,
['/var/log/nginx/' ['/var/log/nginx/'
'22222.error.log', '22222.error.log',
'{0}22222/' '{0}22222/'
@@ -423,29 +429,34 @@ def post_pref(self, apt_packages, packages, upgrade=False):
) )
try: try:
WOShellExec.cmd_exec(self, "openssl genrsa -out " WOShellExec.cmd_exec(
self, "openssl genrsa -out "
"{0}22222/cert/22222.key 2048" "{0}22222/cert/22222.key 2048"
.format(ngxroot)) .format(ngxroot))
WOShellExec.cmd_exec(self, "openssl req -new -batch " WOShellExec.cmd_exec(
self, "openssl req -new -batch "
"-subj /commonName=localhost/ " "-subj /commonName=localhost/ "
"-key {0}22222/cert/22222.key " "-key {0}22222/cert/22222.key "
"-out {0}22222/cert/" "-out {0}22222/cert/"
"22222.csr" "22222.csr"
.format(ngxroot)) .format(ngxroot))
WOFileUtils.mvfile(self, "{0}22222/cert/22222.key" WOFileUtils.mvfile(
self, "{0}22222/cert/22222.key"
.format(ngxroot), .format(ngxroot),
"{0}22222/cert/" "{0}22222/cert/"
"22222.key.org" "22222.key.org"
.format(ngxroot)) .format(ngxroot))
WOShellExec.cmd_exec(self, "openssl rsa -in " WOShellExec.cmd_exec(
self, "openssl rsa -in "
"{0}22222/cert/" "{0}22222/cert/"
"22222.key.org -out " "22222.key.org -out "
"{0}22222/cert/22222.key" "{0}22222/cert/22222.key"
.format(ngxroot)) .format(ngxroot))
WOShellExec.cmd_exec(self, "openssl x509 -req -days " WOShellExec.cmd_exec(
self, "openssl x509 -req -days "
"3652 -in {0}22222/cert/" "3652 -in {0}22222/cert/"
"22222.csr -signkey {0}" "22222.csr -signkey {0}"
"22222/cert/22222.key -out " "22222/cert/22222.key -out "
@@ -1114,8 +1125,8 @@ def post_pref(self, apt_packages, packages, upgrade=False):
Log.debug(self, "Enabling redis systemd service") Log.debug(self, "Enabling redis systemd service")
WOShellExec.cmd_exec(self, "systemctl enable redis-server") WOShellExec.cmd_exec(self, "systemctl enable redis-server")
if (os.path.isfile("/etc/redis/redis.conf") and if (os.path.isfile("/etc/redis/redis.conf") and
not WOFileUtils.grep(self, "/etc/redis/redis.conf", (not WOFileUtils.grep(self, "/etc/redis/redis.conf",
"WordOps")): "WordOps"))):
Log.info(self, "Tuning Redis configuration") Log.info(self, "Tuning Redis configuration")
with open("/etc/redis/redis.conf", with open("/etc/redis/redis.conf",
"a") as redis_file: "a") as redis_file:
@@ -1171,10 +1182,10 @@ def post_pref(self, apt_packages, packages, upgrade=False):
'freshclam.mustache', 'freshclam.mustache',
data, overwrite=False) data, overwrite=False)
WOFileUtils.chmod(self, "/opt/freshclam.sh", 0o775) WOFileUtils.chmod(self, "/opt/freshclam.sh", 0o775)
WOCron.setcron_weekly(self, '/opt/freshclam.sh ' # WOCron.setcron_weekly(self, '/opt/freshclam.sh '
'> /dev/null 2>&1', # '> /dev/null 2>&1',
comment='ClamAV freshclam cronjob ' # comment='ClamAV freshclam cronjob '
'added by WordOps') # 'added by WordOps')
if (packages): if (packages):
# WP-CLI # WP-CLI
@@ -1255,16 +1266,33 @@ def post_pref(self, apt_packages, packages, upgrade=False):
shutil.copyfile('/var/lib/wo/tmp/composer.phar', shutil.copyfile('/var/lib/wo/tmp/composer.phar',
'/usr/local/bin/composer') '/usr/local/bin/composer')
WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775) WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)
if os.path.isdir("/var/www/22222/htdocs/db/pma"):
Log.info(self, "Updating phpMyAdmin, please wait...") Log.info(self, "Updating phpMyAdmin, please wait...")
WOShellExec.cmd_exec(self, "/usr/local/bin/composer update " WOShellExec.cmd_exec(
self, "/usr/local/bin/composer update "
"--no-plugins --no-scripts " "--no-plugins --no-scripts "
"-n --no-dev -d " "-n --no-dev -d "
"/var/www/22222/htdocs/db/pma/") "/var/www/22222/htdocs/db/pma/")
WOFileUtils.chown(self, '{0}22222/htdocs/db/pma' WOFileUtils.chown(
self, '{0}22222/htdocs/db/pma'
.format(WOVariables.wo_webroot), .format(WOVariables.wo_webroot),
'www-data', 'www-data',
'www-data', 'www-data',
recursive=True) recursive=True)
if not os.path.exists('{0}22222/htdocs/cache/'
'redis/phpRedisAdmin'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating new directory "
"{0}22222/htdocs/cache/redis"
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/cache/redis/phpRedisAdmin'
.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
'www-data',
'www-data',
recursive=True)
# MySQLtuner # MySQLtuner
if any('/usr/bin/mysqltuner' == x[1] if any('/usr/bin/mysqltuner' == x[1]
for x in packages): for x in packages):
@@ -1285,33 +1313,32 @@ def post_pref(self, apt_packages, packages, upgrade=False):
else: else:
wo_netdata = "/opt/netdata/" wo_netdata = "/opt/netdata/"
# disable mail notifications # disable mail notifications
WOFileUtils.searchreplace(self, "{0}usr/" WOFileUtils.searchreplace(
"lib/netdata/conf.d/" self, "{0}usr/"
"health_alarm_notify.conf" "lib/netdata/conf.d/health_alarm_notify.conf"
.format(wo_netdata), .format(wo_netdata),
'SEND_EMAIL="YES"', 'SEND_EMAIL="YES"',
'SEND_EMAIL="NO"') 'SEND_EMAIL="NO"')
# make changes persistant # make changes persistant
WOFileUtils.copyfile(self, "{0}usr/" WOFileUtils.copyfile(
"lib/netdata/conf.d/" self, "{0}usr/lib/netdata/conf.d/"
"health_alarm_notify.conf" "health_alarm_notify.conf"
.format(wo_netdata), .format(wo_netdata),
"{0}etc/netdata/" "{0}etc/netdata/health_alarm_notify.conf"
"health_alarm_notify.conf"
.format(wo_netdata)) .format(wo_netdata))
# check if mysql credentials are available # check if mysql credentials are available
if os.path.isfile('/etc/mysql/conf.d/my.cnf'): if os.path.isfile('/etc/mysql/conf.d/my.cnf'):
try: try:
WOMysql.execute(self, WOMysql.execute(
"create user " self,
"'netdata'@'localhost';", "create user 'netdata'@'localhost';",
log=False) log=False)
WOMysql.execute(self, WOMysql.execute(
"grant usage on *.* to " self,
"'netdata'@'localhost';", "grant usage on *.* to 'netdata'@'localhost';",
log=False) log=False)
WOMysql.execute(self, WOMysql.execute(
"flush privileges;", self, "flush privileges;",
log=False) log=False)
except CommandExecutionError as e: except CommandExecutionError as e:
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
@@ -1398,17 +1425,20 @@ def post_pref(self, apt_packages, packages, upgrade=False):
'{0}22222/htdocs/php/webgrind' '{0}22222/htdocs/php/webgrind'
.format(WOVariables.wo_webroot)) .format(WOVariables.wo_webroot))
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/" WOFileUtils.searchreplace(
self, "{0}22222/htdocs/php/webgrind/"
"config.php" "config.php"
.format(WOVariables.wo_webroot), .format(WOVariables.wo_webroot),
"/usr/local/bin/dot", "/usr/bin/dot") "/usr/local/bin/dot", "/usr/bin/dot")
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/" WOFileUtils.searchreplace(
self, "{0}22222/htdocs/php/webgrind/"
"config.php" "config.php"
.format(WOVariables.wo_webroot), .format(WOVariables.wo_webroot),
"Europe/Copenhagen", "Europe/Copenhagen",
WOVariables.wo_timezone) WOVariables.wo_timezone)
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/" WOFileUtils.searchreplace(
self, "{0}22222/htdocs/php/webgrind/"
"config.php" "config.php"
.format(WOVariables.wo_webroot), .format(WOVariables.wo_webroot),
"90", "100") "90", "100")
@@ -1458,7 +1488,8 @@ def post_pref(self, apt_packages, packages, upgrade=False):
Log.debug(self, "grant all on slow-query-log.*" Log.debug(self, "grant all on slow-query-log.*"
" to anemometer@root_user" " to anemometer@root_user"
" IDENTIFIED BY password ") " IDENTIFIED BY password ")
WOMysql.execute(self, 'grant all on slow_query_log.* to' WOMysql.execute(
self, 'grant all on slow_query_log.* to'
'\'anemometer\'@\'{0}\' IDENTIFIED' '\'anemometer\'@\'{0}\' IDENTIFIED'
' BY \'{1}\''.format(self.app.config.get( ' BY \'{1}\''.format(self.app.config.get(
'mysql', 'grant-host'), 'mysql', 'grant-host'),
@@ -1482,41 +1513,3 @@ def post_pref(self, apt_packages, packages, upgrade=False):
if any('/usr/bin/pt-query-advisor' == x[1] if any('/usr/bin/pt-query-advisor' == x[1]
for x in packages): for x in packages):
WOFileUtils.chmod(self, "/usr/bin/pt-query-advisor", 0o775) WOFileUtils.chmod(self, "/usr/bin/pt-query-advisor", 0o775)
# phpredisadmin
if any('/var/lib/wo/tmp/pra.tar.gz' == x[1]
for x in packages):
if not os.path.exists('{0}22222/htdocs/cache/'
'redis/phpRedisAdmin'
.format(WOVariables.wo_webroot)):
Log.debug(self, "Creating new directory "
"{0}22222/htdocs/cache/redis"
.format(WOVariables.wo_webroot))
os.makedirs('{0}22222/htdocs/cache/redis/phpRedisAdmin'
.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
'www-data',
'www-data',
recursive=True)
if os.path.isfile("/usr/local/bin/composer"):
WOShellExec.cmd_exec(self, "/usr/local/bin/composer"
"create-project --no-plugins "
"--no-scripts -n -s dev "
"erik-dubbelboer/php-redis-admin "
"/var/www/22222/htdocs/cache"
"/redis/phpRedisAdmin ")
Log.debug(self, 'Setting Privileges of webroot permission to '
'{0}22222/htdocs/cache/redis'
.format(WOVariables.wo_webroot))
WOFileUtils.chown(self, '{0}22222/htdocs'
.format(WOVariables.wo_webroot),
'www-data',
'www-data',
recursive=True)
if (self.msg):
for msg in self.msg:
Log.info(self, Log.ENDC + msg)
else:
return self.msg