Skip to content

Commit

Permalink
Merge pull request #189 from plesk/recreate-awstats-config
Browse files Browse the repository at this point in the history
Recreate awstats config after conversion done
  • Loading branch information
SandakovMM authored Mar 1, 2024
2 parents 8cbac19 + dac643b commit 9859d3d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
36 changes: 35 additions & 1 deletion actions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import typing

from common import action, files, motd, plesk, util
from common import action, files, log, motd, plesk, rpm, util


class FixNamedConfig(action.ActiveAction):
Expand Down Expand Up @@ -226,3 +226,37 @@ def _post_action(self):

def _revert_action(self):
pass


class RecreateAwstatConfigurationFiles(action.ActiveAction):
def __init__(self):
self.name = "recreate awstat configuration files for domains"

def get_awstat_domains(self) -> typing.Set[str]:
domains_awstats_directory = "/usr/local/psa/etc/awstats/"
domains = set()
for awstat_config_file in os.listdir(domains_awstats_directory):
if awstat_config_file.startswith("awstats.") and awstat_config_file.endswith("-http.conf"):
domains.add(awstat_config_file.split("awstats.")[-1].rsplit("-http.conf")[0])
return domains

def _prepare_action(self):
pass

def _post_action(self):
rpm.handle_all_rpmnew_files("/etc/awstats")

for domain in self.get_awstat_domains():
log.info(f"Recreating awstat configuration for domain: {domain}")
util.logged_check_call(
[
"/usr/sbin/plesk", "sbin", "webstatmng", "--set-configs",
"--stat-prog", "awstats", "--domain-name", domain
], stdin=subprocess.DEVNULL
)

def _revert_action(self):
pass

def estimate_post_time(self) -> int:
return len(self.get_awstat_domains()) * 0.1 + 5
9 changes: 1 addition & 8 deletions actions/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,7 @@ def _use_rpmnew_repositories(self):
# The problem is about changed repofiles, that leapp tring to install form packages.
# For example, when epel.repo file was changed, dnf will save the new one as epel.repo.rpmnew.
# I beleive there could be other files with the same problem, so lets iterate every .rpmnew file in /etc/yum.repos.d
fixed_list = []
for file in files.find_files_case_insensitive("/etc/yum.repos.d", ["*.rpmnew"]):
original_file = file[:-len(".rpmnew")]
if os.path.exists(original_file):
shutil.move(original_file, original_file + ".rpmsave")
fixed_list.append(original_file)

shutil.move(file, original_file)
fixed_list = rpm.handle_all_rpmnew_files("/etc/yum.repos.d")

if len(fixed_list) > 0:
motd.add_finish_ssh_login_message(CHANGED_REPOS_MSG_FMT.format(changed_files="\n\t".join(fixed_list)))
Expand Down
2 changes: 1 addition & 1 deletion common
Submodule common updated 2 files
+10 −0 src/rpm.py
+43 −0 tests/rpmtests.py
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def construct_actions(options: typing.Any, stage_flag: Stages) -> typing.Dict[in
actions.UpdatePlesk(),
actions.PostgresReinstallModernPackage(),
actions.FixNamedConfig(),
actions.RecreateAwstatConfigurationFiles(),
],
3: [
actions.DisablePleskSshBanner(),
Expand Down

0 comments on commit 9859d3d

Please sign in to comment.