Skip to content

Commit

Permalink
multiple bug fixes to apache manager on al9
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Sep 26, 2024
1 parent dcf8967 commit a989d99
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 110 deletions.
6 changes: 6 additions & 0 deletions ApachController/ApacheController.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ApacheController:

if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:


serverRootPath = '/etc/httpd'
configBasePath = '/etc/httpd/conf.d/'
php54Path = '/opt/remi/php54/root/etc/php-fpm.d/'
Expand All @@ -28,6 +29,7 @@ class ApacheController:
php82Path = '/etc/opt/remi/php82/php-fpm.d/'
php83Path = '/etc/opt/remi/php83/php-fpm.d/'
php84Path = '/etc/opt/remi/php84/php-fpm.d/'
php85Path = '/etc/opt/remi/php85/php-fpm.d/'

serviceName = 'httpd'

Expand All @@ -48,6 +50,10 @@ class ApacheController:
php81Path = '/etc/php/8.1/fpm/pool.d/'
php82Path = '/etc/php/8.2/fpm/pool.d/'

php83Path = '/etc/php/8.3/fpm/pool.d/'
php84Path = '/etc/php/8.4/fpm/pool.d/'
php85Path = '/etc/php/8.5/fpm/pool.d/'

serviceName = 'apache2'

mpmConfigs = """# Select the MPM module which should be used by uncommenting exactly
Expand Down
13 changes: 13 additions & 0 deletions ApachController/ApacheVhosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class ApacheVhost:
php80Path = '/etc/opt/remi/php80/php-fpm.d/'
php81Path = '/etc/opt/remi/php81/php-fpm.d/'
php82Path = '/etc/opt/remi/php82/php-fpm.d/'
php83Path = '/etc/opt/remi/php83/php-fpm.d/'
php84Path = '/etc/opt/remi/php84/php-fpm.d/'
php85Path = '/etc/opt/remi/php85/php-fpm.d/'

serviceName = 'httpd'

Expand All @@ -54,6 +57,7 @@ class ApacheVhost:
php82Path = '/etc/php/8.2/fpm/pool.d/'
php83Path = '/etc/php/8.3/fpm/pool.d/'
php84Path = '/etc/php/8.4/fpm/pool.d/'
php85Path = '/etc/php/8.5/fpm/pool.d/'

serviceName = 'apache2'

Expand Down Expand Up @@ -528,6 +532,7 @@ def deletePHPPath(virtualHostName):
@staticmethod
def changePHP(phpVersion, vhFile):
try:
logging.writeToFile(f"PHP version passed to Apache function: {phpVersion}")

if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
sockPath = '/var/run/php-fpm/'
Expand Down Expand Up @@ -569,6 +574,14 @@ def changePHP(phpVersion, vhFile):

confFile.write(currentConf)

### minor bug fix of updating default php conf user in selected fpm

if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
defaultConfPath = finalConfPath.replace(virtualHostName, 'www')

command = f"sed -i 's/www-data/apache/g' {defaultConfPath}"
ProcessUtilities.executioner(command)

phpService = ApacheVhost.DecideFPMServiceName(phpVersion)

command = f"systemctl stop {phpService}"
Expand Down
3 changes: 2 additions & 1 deletion plogical/phpUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ def WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile):
@staticmethod
def FindIfSaidPHPIsAvaiableOtherwiseMaketheNextOneAvailableToUse(vhFile, phpVersion):
if vhFile != None:
result = phpUtilities.GetPHPVersionFromFile(vhFile)
virtualHostName = vhFile.split('/')[6]
result = phpUtilities.GetPHPVersionFromFile(vhFile, virtualHostName)

if os.path.exists(result):
return phpVersion
Expand Down
2 changes: 1 addition & 1 deletion plogical/renew.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def SSLObtainer(self):

## For Non-suspended websites only

for website in Websites.objects.filter(status=1):
for website in Websites.objects.filter(state=1):
logging.writeToFile('Checking SSL for %s.' % (website.domain), 0)
filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (website.domain)

Expand Down
61 changes: 0 additions & 61 deletions plogical/test.py
Original file line number Diff line number Diff line change
@@ -1,61 +0,0 @@
import os
import shutil
import subprocess


def edit_fstab(mount_point, options_to_add):
# Backup the original fstab file
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'

if not os.path.exists(backup_path):
shutil.copy(fstab_path, backup_path)


# Read the fstab file
with open(fstab_path, 'r') as file:
lines = file.readlines()

# Modify the appropriate line
WriteToFile = open(fstab_path, 'w')
for i, line in enumerate(lines):

if line.find('\t') > -1:
parts = line.split('\t')
else:
parts = line.split(' ')

#print(parts)
try:
if parts[1] == '/' and parts[3].find('usrquota,grpquota') == -1:
parts[3] = f'{parts[3]},usrquota,grpquota'
finalString = '\t'.join(parts)
#print(finalString)
WriteToFile.write(finalString)
else:
WriteToFile.write(line)
except:
WriteToFile.write(line)
WriteToFile.close()


try:
command = "find /lib/modules/ -type f -name '*quota_v*.ko*'"
result = subprocess.run(command, capture_output=True, text=True, shell=True)
print(repr(result.stdout))

# Only if the first command works, run the rest
if result.returncode == 0:
command = "echo '{}' | sed -n 's|/lib/modules/\\([^/]*\\)/.*|\\1|p' | sort -u".format(result.stdout)
result = subprocess.run(command, capture_output=True, text=True, shell=True)
print(repr(result.stdout.rstrip('\n')))

except subprocess.CalledProcessError as e:
print("Error:", e.output.decode())


edit_fstab('/', '/')




Loading

0 comments on commit a989d99

Please sign in to comment.