Several improvements
This commit is contained in:
@@ -331,16 +331,17 @@ 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 rt_cache_redis "
|
"# Log format Settings\n"
|
||||||
"'$remote_addr "
|
"log_format rt_cache_redis "
|
||||||
"$upstream_response_time "
|
"'$remote_addr "
|
||||||
"$srcache_fetch_status "
|
"$upstream_response_time "
|
||||||
"[$time_local] '\n"
|
"$srcache_fetch_status "
|
||||||
"'$http_host \"$request\" $status"
|
"[$time_local] '\n"
|
||||||
" $body_bytes_sent '\n"
|
"'$http_host \"$request\" $status"
|
||||||
"'\"$http_referer\" "
|
" $body_bytes_sent '\n"
|
||||||
"\"$http_user_agent\"';\n")
|
"'\"$http_referer\" "
|
||||||
|
"\"$http_user_agent\"';\n")
|
||||||
|
|
||||||
# Nginx-Plus does not have nginx
|
# Nginx-Plus does not have nginx
|
||||||
# package structure like this
|
# package structure like this
|
||||||
@@ -357,30 +358,33 @@ 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(
|
||||||
'/etc/nginx/sites-available/22222',
|
self,
|
||||||
'22222.mustache', data, overwrite=False)
|
'/etc/nginx/sites-available/22222',
|
||||||
|
'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(
|
||||||
"$(openssl passwd -crypt "
|
self, "printf \"WordOps:"
|
||||||
"{password} 2> /dev/null)\n\""
|
"$(openssl passwd -crypt "
|
||||||
"> /etc/nginx/htpasswd-wo "
|
"{password} 2> /dev/null)\n\""
|
||||||
"2>/dev/null"
|
"> /etc/nginx/htpasswd-wo "
|
||||||
.format(password=passwd))
|
"2>/dev/null"
|
||||||
|
.format(password=passwd))
|
||||||
except CommandExecutionError as e:
|
except CommandExecutionError as e:
|
||||||
Log.debug(self, "{0}".format(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
|
||||||
WOFileUtils.create_symlink(self, ['/etc/nginx/'
|
WOFileUtils.create_symlink(
|
||||||
'sites-available/'
|
self, ['/etc/nginx/'
|
||||||
'22222',
|
'sites-available/'
|
||||||
'/etc/nginx/'
|
'22222',
|
||||||
'sites-enabled/'
|
'/etc/nginx/'
|
||||||
'22222'])
|
'sites-enabled/'
|
||||||
|
'22222'])
|
||||||
# Create log and cert folder and softlinks
|
# Create log and cert folder and softlinks
|
||||||
if not os.path.exists('{0}22222/logs'
|
if not os.path.exists('{0}22222/logs'
|
||||||
.format(ngxroot)):
|
.format(ngxroot)):
|
||||||
@@ -406,51 +410,58 @@ 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(
|
||||||
['/var/log/nginx/'
|
self,
|
||||||
'22222.access.log',
|
['/var/log/nginx/'
|
||||||
'{0}22222/'
|
'22222.access.log',
|
||||||
'logs/access.log'
|
'{0}22222/'
|
||||||
.format(ngxroot)]
|
'logs/access.log'
|
||||||
)
|
.format(ngxroot)]
|
||||||
|
)
|
||||||
|
|
||||||
WOFileUtils.create_symlink(self,
|
WOFileUtils.create_symlink(
|
||||||
['/var/log/nginx/'
|
self,
|
||||||
'22222.error.log',
|
['/var/log/nginx/'
|
||||||
'{0}22222/'
|
'22222.error.log',
|
||||||
'logs/error.log'
|
'{0}22222/'
|
||||||
.format(ngxroot)]
|
'logs/error.log'
|
||||||
)
|
.format(ngxroot)]
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
WOShellExec.cmd_exec(self, "openssl genrsa -out "
|
WOShellExec.cmd_exec(
|
||||||
"{0}22222/cert/22222.key 2048"
|
self, "openssl genrsa -out "
|
||||||
.format(ngxroot))
|
"{0}22222/cert/22222.key 2048"
|
||||||
WOShellExec.cmd_exec(self, "openssl req -new -batch "
|
.format(ngxroot))
|
||||||
"-subj /commonName=localhost/ "
|
WOShellExec.cmd_exec(
|
||||||
"-key {0}22222/cert/22222.key "
|
self, "openssl req -new -batch "
|
||||||
"-out {0}22222/cert/"
|
"-subj /commonName=localhost/ "
|
||||||
"22222.csr"
|
"-key {0}22222/cert/22222.key "
|
||||||
.format(ngxroot))
|
"-out {0}22222/cert/"
|
||||||
|
"22222.csr"
|
||||||
|
.format(ngxroot))
|
||||||
|
|
||||||
WOFileUtils.mvfile(self, "{0}22222/cert/22222.key"
|
WOFileUtils.mvfile(
|
||||||
.format(ngxroot),
|
self, "{0}22222/cert/22222.key"
|
||||||
"{0}22222/cert/"
|
.format(ngxroot),
|
||||||
"22222.key.org"
|
"{0}22222/cert/"
|
||||||
.format(ngxroot))
|
"22222.key.org"
|
||||||
|
.format(ngxroot))
|
||||||
|
|
||||||
WOShellExec.cmd_exec(self, "openssl rsa -in "
|
WOShellExec.cmd_exec(
|
||||||
"{0}22222/cert/"
|
self, "openssl rsa -in "
|
||||||
"22222.key.org -out "
|
"{0}22222/cert/"
|
||||||
"{0}22222/cert/22222.key"
|
"22222.key.org -out "
|
||||||
.format(ngxroot))
|
"{0}22222/cert/22222.key"
|
||||||
|
.format(ngxroot))
|
||||||
|
|
||||||
WOShellExec.cmd_exec(self, "openssl x509 -req -days "
|
WOShellExec.cmd_exec(
|
||||||
"3652 -in {0}22222/cert/"
|
self, "openssl x509 -req -days "
|
||||||
"22222.csr -signkey {0}"
|
"3652 -in {0}22222/cert/"
|
||||||
"22222/cert/22222.key -out "
|
"22222.csr -signkey {0}"
|
||||||
"{0}22222/cert/22222.crt"
|
"22222/cert/22222.key -out "
|
||||||
.format(ngxroot))
|
"{0}22222/cert/22222.crt"
|
||||||
|
.format(ngxroot))
|
||||||
|
|
||||||
except CommandExecutionError as e:
|
except CommandExecutionError as e:
|
||||||
Log.debug(self, "{0}".format(e))
|
Log.debug(self, "{0}".format(e))
|
||||||
@@ -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)
|
||||||
Log.info(self, "Updating phpMyAdmin, please wait...")
|
if os.path.isdir("/var/www/22222/htdocs/db/pma"):
|
||||||
WOShellExec.cmd_exec(self, "/usr/local/bin/composer update "
|
Log.info(self, "Updating phpMyAdmin, please wait...")
|
||||||
"--no-plugins --no-scripts "
|
WOShellExec.cmd_exec(
|
||||||
"-n --no-dev -d "
|
self, "/usr/local/bin/composer update "
|
||||||
"/var/www/22222/htdocs/db/pma/")
|
"--no-plugins --no-scripts "
|
||||||
WOFileUtils.chown(self, '{0}22222/htdocs/db/pma'
|
"-n --no-dev -d "
|
||||||
.format(WOVariables.wo_webroot),
|
"/var/www/22222/htdocs/db/pma/")
|
||||||
'www-data',
|
WOFileUtils.chown(
|
||||||
'www-data',
|
self, '{0}22222/htdocs/db/pma'
|
||||||
recursive=True)
|
.format(WOVariables.wo_webroot),
|
||||||
|
'www-data',
|
||||||
|
'www-data',
|
||||||
|
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,34 +1313,33 @@ 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))
|
||||||
Log.info(
|
Log.info(
|
||||||
@@ -1398,20 +1425,23 @@ 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(
|
||||||
"config.php"
|
self, "{0}22222/htdocs/php/webgrind/"
|
||||||
.format(WOVariables.wo_webroot),
|
"config.php"
|
||||||
"/usr/local/bin/dot", "/usr/bin/dot")
|
.format(WOVariables.wo_webroot),
|
||||||
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/"
|
"/usr/local/bin/dot", "/usr/bin/dot")
|
||||||
"config.php"
|
WOFileUtils.searchreplace(
|
||||||
.format(WOVariables.wo_webroot),
|
self, "{0}22222/htdocs/php/webgrind/"
|
||||||
"Europe/Copenhagen",
|
"config.php"
|
||||||
WOVariables.wo_timezone)
|
.format(WOVariables.wo_webroot),
|
||||||
|
"Europe/Copenhagen",
|
||||||
|
WOVariables.wo_timezone)
|
||||||
|
|
||||||
WOFileUtils.searchreplace(self, "{0}22222/htdocs/php/webgrind/"
|
WOFileUtils.searchreplace(
|
||||||
"config.php"
|
self, "{0}22222/htdocs/php/webgrind/"
|
||||||
.format(WOVariables.wo_webroot),
|
"config.php"
|
||||||
"90", "100")
|
.format(WOVariables.wo_webroot),
|
||||||
|
"90", "100")
|
||||||
|
|
||||||
Log.debug(self, "Setting Privileges of webroot permission to "
|
Log.debug(self, "Setting Privileges of webroot permission to "
|
||||||
"{0}22222/htdocs/php/webgrind/ file "
|
"{0}22222/htdocs/php/webgrind/ file "
|
||||||
@@ -1458,13 +1488,14 @@ 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(
|
||||||
'\'anemometer\'@\'{0}\' IDENTIFIED'
|
self, 'grant all on slow_query_log.* to'
|
||||||
' BY \'{1}\''.format(self.app.config.get(
|
'\'anemometer\'@\'{0}\' IDENTIFIED'
|
||||||
'mysql', 'grant-host'),
|
' BY \'{1}\''.format(self.app.config.get(
|
||||||
chars),
|
'mysql', 'grant-host'),
|
||||||
errormsg="cannot grant priviledges",
|
chars),
|
||||||
log=False)
|
errormsg="cannot grant priviledges",
|
||||||
|
log=False)
|
||||||
|
|
||||||
# Custom Anemometer configuration
|
# Custom Anemometer configuration
|
||||||
Log.debug(self, "configration Anemometer")
|
Log.debug(self, "configration Anemometer")
|
||||||
@@ -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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user