Fix clamav install

This commit is contained in:
VirtuBox
2019-08-31 12:18:16 +02:00
parent 956a5e0a6b
commit 5fa39709ef
3 changed files with 91 additions and 90 deletions

View File

@@ -265,7 +265,7 @@ class WOStackController(CementBaseController):
if pargs.clamav: if pargs.clamav:
Log.debug(self, "Setting apt_packages variable for ClamAV") Log.debug(self, "Setting apt_packages variable for ClamAV")
if not WOAptGet.is_installed(self, 'clamav'): if not WOAptGet.is_installed(self, 'clamav'):
apt_packages = apt_packages + ["clamav"] apt_packages = apt_packages + WOVariables.wo_clamav
else: else:
Log.debug(self, "ClamAV already installed") Log.debug(self, "ClamAV already installed")
Log.info(self, "ClamAV already installed") Log.info(self, "ClamAV already installed")
@@ -587,7 +587,7 @@ class WOStackController(CementBaseController):
if pargs.clamav: if pargs.clamav:
Log.debug(self, "Setting apt_packages variable for ClamAV") Log.debug(self, "Setting apt_packages variable for ClamAV")
if WOAptGet.is_installed(self, 'clamav'): if WOAptGet.is_installed(self, 'clamav'):
apt_packages = apt_packages + ["clamav"] apt_packages = apt_packages + WOVariables.wo_clamav
# proftpd # proftpd
if pargs.proftpd: if pargs.proftpd:
@@ -793,7 +793,7 @@ class WOStackController(CementBaseController):
if pargs.clamav: if pargs.clamav:
Log.debug(self, "Setting apt_packages variable for ClamAV") Log.debug(self, "Setting apt_packages variable for ClamAV")
if WOAptGet.is_installed(self, 'clamav'): if WOAptGet.is_installed(self, 'clamav'):
apt_packages = apt_packages + ["clamav"] apt_packages = apt_packages + WOVariables.wo_clamav
# proftpd # proftpd
if pargs.proftpd: if pargs.proftpd:

View File

@@ -1079,100 +1079,100 @@ def post_pref(self, apt_packages, packages, upgrade=False):
msg="Adding ProFTPd into Git") msg="Adding ProFTPd into Git")
WOService.reload_service(self, 'proftpd') WOService.reload_service(self, 'proftpd')
# Redis configuration # Redis configuration
if set(WOVariables.wo_redis).issubset(set(apt_packages)): if set(WOVariables.wo_redis).issubset(set(apt_packages)):
if os.path.isfile("/etc/nginx/conf.d/upstream.conf"): if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
if not WOFileUtils.grep(self, "/etc/nginx/conf.d/" if not WOFileUtils.grep(self, "/etc/nginx/conf.d/"
"upstream.conf", "upstream.conf",
"redis"): "redis"):
with open("/etc/nginx/conf.d/upstream.conf", with open("/etc/nginx/conf.d/upstream.conf",
"a") as redis_file: "a") as redis_file:
redis_file.write("upstream redis {\n" redis_file.write("upstream redis {\n"
" server 127.0.0.1:6379;\n" " server 127.0.0.1:6379;\n"
" keepalive 10;\n}\n") " keepalive 10;\n}\n")
if os.path.isfile("/etc/nginx/nginx.conf"): if os.path.isfile("/etc/nginx/nginx.conf"):
if not os.path.isfile("/etc/nginx/conf.d/redis.conf"): if not os.path.isfile("/etc/nginx/conf.d/redis.conf"):
with open("/etc/nginx/conf.d/redis.conf", with open("/etc/nginx/conf.d/redis.conf",
"a") as redis_file:
redis_file.write("# Log format Settings\n"
"log_format rt_cache_redis "
"'$remote_addr "
"$upstream_response_time "
"$srcache_fetch_status "
"[$time_local]"
" '\n '$http_host"
" \"$request\" "
"$status $body_bytes_sent '\n"
"'\"$http_referer\" "
"\"$http_user_agent\"';\n")
# set redis.conf parameter
# set maxmemory 10% for ram below 512MB and 20% for others
# set maxmemory-policy allkeys-lru
# enable systemd service
Log.debug(self, "Enabling redis systemd service")
WOShellExec.cmd_exec(self, "systemctl enable redis-server")
if (os.path.isfile("/etc/redis/redis.conf") and
not WOFileUtils.grep(self, "/etc/redis/redis.conf",
"WordOps")):
Log.info(self, "Tuning Redis configuration")
with open("/etc/redis/redis.conf",
"a") as redis_file: "a") as redis_file:
redis_file.write("# Log format Settings\n" redis_file.write("\n# WordOps v3.9.8\n")
"log_format rt_cache_redis " wo_ram = psutil.virtual_memory().total / (1024 * 1024)
"'$remote_addr " if wo_ram < 1024:
"$upstream_response_time " Log.debug(self, "Setting maxmemory variable to "
"$srcache_fetch_status " "{0} in redis.conf"
"[$time_local]" .format(int(wo_ram*1024*1024*0.1)))
" '\n '$http_host" WOFileUtils.searchreplace(self,
" \"$request\" " "/etc/redis/redis.conf",
"$status $body_bytes_sent '\n" "# maxmemory <bytes>",
"'\"$http_referer\" " "maxmemory {0}"
"\"$http_user_agent\"';\n") .format
# set redis.conf parameter (int(wo_ram*1024*1024*0.1)))
# set maxmemory 10% for ram below 512MB and 20% for others
# set maxmemory-policy allkeys-lru else:
# enable systemd service Log.debug(self, "Setting maxmemory variable to {0} "
Log.debug(self, "Enabling redis systemd service") "in redis.conf"
WOShellExec.cmd_exec(self, "systemctl enable redis-server") .format(int(wo_ram*1024*1024*0.2)))
if (os.path.isfile("/etc/redis/redis.conf") and WOFileUtils.searchreplace(self,
not WOFileUtils.grep(self, "/etc/redis/redis.conf", "/etc/redis/redis.conf",
"WordOps")): "# maxmemory <bytes>",
Log.info(self, "Tuning Redis configuration") "maxmemory {0}"
with open("/etc/redis/redis.conf", .format
"a") as redis_file: (int(wo_ram*1024*1024*0.2)))
redis_file.write("\n# WordOps v3.9.8\n")
wo_ram = psutil.virtual_memory().total / (1024 * 1024) Log.debug(
if wo_ram < 1024: self, "Setting maxmemory-policy variable to "
Log.debug(self, "Setting maxmemory variable to " "allkeys-lru in redis.conf")
"{0} in redis.conf"
.format(int(wo_ram*1024*1024*0.1)))
WOFileUtils.searchreplace(self, WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf", "/etc/redis/redis.conf",
"# maxmemory <bytes>", "# maxmemory-policy "
"maxmemory {0}" "noeviction",
.format "maxmemory-policy "
(int(wo_ram*1024*1024*0.1))) "allkeys-lru")
Log.debug(
else: self, "Setting tcp-backlog variable to "
Log.debug(self, "Setting maxmemory variable to {0} " "in redis.conf")
"in redis.conf"
.format(int(wo_ram*1024*1024*0.2)))
WOFileUtils.searchreplace(self, WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf", "/etc/redis/redis.conf",
"# maxmemory <bytes>", "tcp-backlog 511",
"maxmemory {0}" "tcp-backlog 32768")
.format WOFileUtils.chown(self, '/etc/redis/redis.conf',
(int(wo_ram*1024*1024*0.2))) 'redis', 'redis', recursive=False)
WOService.restart_service(self, 'redis-server')
Log.debug( # Redis configuration
self, "Setting maxmemory-policy variable to " if set(["clamav"]).issubset(set(apt_packages)):
"allkeys-lru in redis.conf") Log.debug("Setting up freshclam cronjob")
WOFileUtils.searchreplace(self, WOTemplate.render(self, '/opt/freshclam.sh',
"/etc/redis/redis.conf", 'freshclam.mustache',
"# maxmemory-policy " data, overwrite=False)
"noeviction", WOFileUtils.chmod(self, "/opt/freshclam.sh", 0o775)
"maxmemory-policy " WOCron.setcron_weekly(self, '/opt/freshclam.sh '
"allkeys-lru") '> /dev/null 2>&1',
Log.debug( comment='ClamAV freshclam cronjob '
self, "Setting tcp-backlog variable to " 'added by WordOps')
"in redis.conf")
WOFileUtils.searchreplace(self,
"/etc/redis/redis.conf",
"tcp-backlog 511",
"tcp-backlog 32768")
WOFileUtils.chown(self, '/etc/redis/redis.conf',
'redis', 'redis', recursive=False)
WOService.restart_service(self, 'redis-server')
# Redis configuration
if set(["clamav"]).issubset(set(apt_packages)):
Log.debug("Setting up freshclam cronjob")
WOTemplate.render(self, '/opt/freshclam.sh',
'freshclam.mustache',
data, overwrite=False)
WOFileUtils.chmod(self, "/opt/freshclam.sh", 0o775)
WOCron.setcron_weekly(self, '/opt/freshclam.sh '
'> /dev/null 2>&1',
comment='ClamAV freshclam cronjob '
'added by WordOps')
if (packages): if (packages):
# WP-CLI # WP-CLI

View File

@@ -160,6 +160,7 @@ class WOVariables():
wo_mysql_client = ["mariadb-client", "python3-mysql.connector"] wo_mysql_client = ["mariadb-client", "python3-mysql.connector"]
wo_fail2ban = ["fail2ban"] wo_fail2ban = ["fail2ban"]
wo_clamav = ["clamav", "clamav-freshclam"]
# Redis repo details # Redis repo details
if wo_distro == 'ubuntu': if wo_distro == 'ubuntu':