Skip to content

Commit

Permalink
php: convert python2 code and remove old hhvm references
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu committed Jun 18, 2024
1 parent ca5e439 commit e81fc5d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 98 deletions.
10 changes: 5 additions & 5 deletions php/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import os
import shutil
from utils import replace
from vars import php_versions, default_version
from .utils import replace
from .vars import php_versions, default_version

class Frontend(object):
def __init__(self, configuration, application):
Expand Down Expand Up @@ -38,7 +38,7 @@ def configure(self, interpretor=None):
# Set apache virtual host
vhost_directory = '/etc/apache2/sites-enabled'
confs_directory = '/etc/apache2/conf-available'
map(os.unlink, [os.path.join(vhost_directory, f) for f in os.listdir(vhost_directory)])
list(map(os.unlink, [os.path.join(vhost_directory, f) for f in os.listdir(vhost_directory)]))
vhost_path = os.path.join(vhost_directory, 'tsuru-vhost.conf')
security_dst_file = os.path.join(confs_directory, 'security.conf')
shutil.copyfile(self.get_vhost_filepath(), vhost_path)
Expand Down Expand Up @@ -76,7 +76,7 @@ def configure(self, interpretor=None):
if not os.path.exists(directory):
os.makedirs(directory)

map(os.unlink, [os.path.join(logs_directory, f) for f in os.listdir(logs_directory)])
list(map(os.unlink, [os.path.join(logs_directory, f) for f in os.listdir(logs_directory)]))
for log_file in ['access.log', 'error.log']:
log_file_path = os.path.join(logs_directory, log_file)
open(log_file_path, 'a').close()
Expand Down Expand Up @@ -138,7 +138,7 @@ def configure(self, interpretor=None):
if not os.path.exists(logs_directory):
os.makedirs(logs_directory)

map(os.unlink, [os.path.join(logs_directory, f) for f in os.listdir(logs_directory)])
list(map(os.unlink, [os.path.join(logs_directory, f) for f in os.listdir(logs_directory)]))
for log_file in ['access.log', 'error.log']:
log_file_path = os.path.join(logs_directory, log_file)
open(log_file_path, 'a').close()
Expand Down
74 changes: 5 additions & 69 deletions php/interpretor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import os
import shutil
import subprocess
from utils import replace
from vars import php_versions
from .utils import replace
from .vars import php_versions

class Interpretor(object):
def __init__(self, configuration, application):
Expand All @@ -27,13 +27,13 @@ def configure(self, frontend):
removed_fpm_files = []
for f in os.listdir('/etc/php/{}/fpm/pool.d'.format(version)):
removed_fpm_files.append(os.path.join('/etc/php/{}/fpm/pool.d'.format(version), f))
map(os.unlink, removed_fpm_files)
list(map(os.unlink, removed_fpm_files))
templates_mapping = {
'pool.conf': '/etc/php/{}/fpm/pool.d/tsuru.conf',
'php-fpm.conf': '/etc/php/{}/fpm/php-fpm.conf'
}

for template, target in templates_mapping.iteritems():
for template, target in templates_mapping.items():
shutil.copyfile(
os.path.join(self.application.get('source_directory'), 'php', 'interpretor', 'fpm',
template.format(version)),
Expand Down Expand Up @@ -72,7 +72,7 @@ def setup_environment(self):
target = '/etc/php/{}/fpm/environment.conf'
for version in php_versions:
with open(target.format(version), 'w') as f:
for (k, v) in self.application.get('env', {}).items():
for (k, v) in list(self.application.get('env', {}).items()):
if v:
f.write('env[%s] = %s\n' % (k, v))

Expand All @@ -99,70 +99,6 @@ def post_install(self):
for version in php_versions:
os.system('service php{}-fpm stop'.format(version))

class HHVM(Interpretor):
def __init__(self, configuration, application):
self.phpversion = ''
super(HHVM, self).__init__(configuration, application)

def configure(self, frontend):
# If frontend supports unix sockets, use them by default
self.socket_address = 'unix:/var/run/hhvm/sock'
if not frontend.supports_unix_proxy():
self.socket_address = '127.0.0.1:9000'

# Clear pre-configured pools
map(os.unlink, [os.path.join('/etc/hhvm', f) for f in os.listdir('/etc/hhvm')])
templates_mapping = {
'php.ini': '/etc/hhvm/php.ini',
'server.ini': '/etc/hhvm/server.ini'
}

for template, target in templates_mapping.iteritems():
shutil.copyfile(
os.path.join(self.application.get('source_directory'), 'php', 'interpretor', 'hhvm', template),
target
)

# Replace pool listen address
listen_address = 'hhvm.server.port = 9000'
if self.socket_address[0:5] == 'unix:':
listen_address = 'hhvm.server.file_socket = ' + self.socket_address[5:]

replace(templates_mapping['server.ini'], '_FPM_POOL_LISTEN_', listen_address)

if 'ini_file' in self.configuration:
shutil.copyfile(
os.path.join(self.application.get('directory'), self.configuration.get('ini_file')),
'/etc/hhvm/php.ini'
)

# Clean and touch some files
for file_path in ['/var/log/hhvm/error.log']:
open(file_path, 'a').close()
os.system('chown %s %s' % (self.application.get('user'), file_path))

# Clean run directory
run_directory = '/var/run/hhvm'
if not os.path.exists(run_directory):
os.makedirs(run_directory)

# Fix user rights
os.system('chown -R %s /etc/hhvm /var/run/hhvm' % self.application.get('user'))

def get_packages_extensions(self):
return []

def post_install(self):
# Set up HHVM fastcgi and remove autostart
os.system('/usr/share/hhvm/install_fastcgi.sh')
os.system('service hhvm stop')

def setup_environment(self):
pass

def get_startup_cmd(self, version):
return '/usr/bin/hhvm --config /etc/hhvm/php.ini --config /etc/hhvm/server.ini --user %s --mode daemon -vPidFile=/var/run/hhvm/pid' % self.application.get('user')

interpretors = {
'fpm': FPM,
'fpm54': FPM,
Expand Down
10 changes: 0 additions & 10 deletions php/interpretor/hhvm/php.ini

This file was deleted.

12 changes: 0 additions & 12 deletions php/interpretor/hhvm/server.ini

This file was deleted.

4 changes: 2 additions & 2 deletions php/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def replace(source_file_path, pattern, substring):

def parse_env(configuration):
return dict(
os.environ.items() +
parse_envs_from_configuration(configuration).items()
list(os.environ.items()) +
list(parse_envs_from_configuration(configuration).items())
)


Expand Down

0 comments on commit e81fc5d

Please sign in to comment.