Browse Source

added post install functions

feature/plugin
harshadyeola 10 years ago
parent
commit
b7c3175917
  1. 88
      ee/cli/plugins/hhvmstack.py
  2. 2
      ee/cli/plugins/mysqlstack.py
  3. 286
      ee/cli/plugins/nginxstack.py
  4. 147
      ee/cli/plugins/phpstack.py
  5. 6
      ee/cli/plugins/postfixstack.py

88
ee/cli/plugins/hhvmstack.py

@ -4,14 +4,20 @@ from ee.core.variables import EEVariables
from ee.core.aptget import EEAptGet
from ee.core.apt_repo import EERepo
from ee.cli.plugins.eestack import EEStack
from ee.core.shellexec import EEShellExec
from ee.core.services import EEService
from ee.core.shellexec import CommandExecutionError
from ee.core.fileutils import EEFileUtils
from ee.core.git import EEGit
from ee.cli.main import app
class EEHhvmStack(EEStack):
"""
EasyEngine HHVM stack
"""
packages_name = EEVariables.ee_hhvm
app = app
log = app.log
packages_name = EEVariables.ee_hhvm
def __init__(self, packages_name=None):
"""
@ -52,7 +58,85 @@ class EEHhvmStack(EEStack):
"""
Defines activities done after installing hhvm stack
"""
pass
EEShellExec.cmd_exec(self, "update-rc.d hhvm defaults")
EEFileUtils.searchreplace(self, "/etc/hhvm/server.ini",
"9000", "8000")
EEFileUtils.searchreplace(self, "/etc/nginx/hhvm.conf",
"9000", "8000")
with open("/etc/hhvm/php.ini", "a") as hhvm_file:
hhvm_file.write("hhvm.log.header = true\n"
"hhvm.log.natives_stack_trace = true\n"
"hhvm.mysql.socket = "
"/var/run/mysqld/mysqld.sock\n"
"hhvm.pdo_mysql.socket = "
"/var/run/mysqld/mysqld.sock\n"
"hhvm.mysqli.socket = "
"/var/run/mysqld/mysqld.sock\n")
if os.path.isfile("/etc/nginx/conf.d/fastcgi.conf"):
if not EEFileUtils.grep(self, "/etc/nginx/conf.d/"
"fastcgi.conf",
"fastcgi_keep_conn"):
with open("/etc/nginx/conf.d/fastcgi.conf",
"a") as hhvm_file:
hhvm_file.write("fastcgi_keep_conn on;\n")
if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
if not EEFileUtils.grep(self, "/etc/nginx/conf.d/"
"upstream.conf",
"hhvm"):
with open("/etc/nginx/conf.d/upstream.conf",
"a") as hhvm_file:
hhvm_file.write("upstream hhvm {\nserver "
"127.0.0.1:8000;\n"
"server 127.0.0.1:9000 backup;\n}"
"\n")
EEGit.add(self, ["/etc/hhvm"], msg="Adding HHVM into Git")
EEService.restart_service(self, 'hhvm')
if os.path.isfile("/etc/nginx/nginx.conf") and (not
os.path.isfile("/etc/nginx/common/php-hhvm.conf")):
data = dict()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php-hhvm.conf')
ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'php-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/w3tc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'w3tc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpfc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpfc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpsc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
if not EEService.reload_service(self, 'nginx'):
self.log.error(self, "Failed to reload Nginx, please check "
"output of `nginx -t`")
def install_stack(self):
"""

2
ee/cli/plugins/mysqlstack.py

@ -51,7 +51,7 @@ class EEMysqlStack(EEStack):
.format(EEVariables.ee_mysql_repo))
EERepo.add_key(self, '0xcbcb082a1bb943db',
keyserver="keyserver.ubuntu.com")
EEAptGet.update(self)
EEAptGet.update(self)
def _pre_install_stack(self):
"""

286
ee/cli/plugins/nginxstack.py

@ -3,11 +3,15 @@ import sys
import random
import string
import configparser
from pynginxconfig import NginxConfig
from ee.core.variables import EEVariables
from ee.core.aptget import EEAptGet
from ee.core.apt_repo import EERepo
from ee.core.fileutils import EEFileUtils
from ee.core.git import EEGit
from ee.cli.plugins.eestack import EEStack
from ee.core.shellexec import EEShellExec
from ee.core.services import EEService
from ee.core.shellexec import CommandExecutionError
from ee.core.logging import Log
from ee.cli.main import app
@ -18,8 +22,10 @@ class EENginxStack(EEStack):
EasyEngine NGINX stack
"""
packages_name = EEVariables.ee_nginx
app = app
log = app.log
def __init__(self, packages_name=None):
"""
Initialize packages list in stack
@ -57,7 +63,285 @@ class EENginxStack(EEStack):
"""
Defines activities done after installing nginx stack
"""
pass
if ((not EEShellExec.cmd_exec(self, "grep -q -Hr EasyEngine "
"/etc/nginx")) and os.path.isfile('/etc/nginx/nginx.conf')):
nc = NginxConfig()
self.log.debug(self, 'Loading file /etc/nginx/nginx.conf ')
nc.loadf('/etc/nginx/nginx.conf')
nc.set('worker_processes', 'auto')
nc.append(('worker_rlimit_nofile', '100000'), position=2)
nc.remove(('events', ''))
nc.append({'name': 'events', 'param': '', 'value':
[('worker_connections', '4096'),
('multi_accept', 'on')]}, position=4)
nc.set([('http',), 'keepalive_timeout'], '30')
self.log.debug(self, "Writting nginx configuration to "
"file /etc/nginx/nginx.conf ")
nc.savef('/etc/nginx/nginx.conf')
# Custom Nginx configuration by EasyEngine
if EEVariables.ee_platform_distro == 'ubuntu':
data = dict(version=EEVariables.ee_version,
Ubuntu=True)
else:
data = dict(version=EEVariables.ee_version,
Debian=True)
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/ee-nginx.conf ')
ee_nginx = open('/etc/nginx/conf.d/ee-nginx.conf',
encoding='utf-8', mode='w')
app.render((data), 'nginx-core.mustache',
out=ee_nginx)
ee_nginx.close()
data = dict()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/blockips.conf')
ee_nginx = open('/etc/nginx/conf.d/blockips.conf',
encoding='utf-8', mode='w')
app.render((data), 'blockips.mustache', out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/fastcgi.conf')
ee_nginx = open('/etc/nginx/conf.d/fastcgi.conf',
encoding='utf-8', mode='w')
app.render((data), 'fastcgi.mustache', out=ee_nginx)
ee_nginx.close()
data = dict(php="9000", debug="9001", hhvm="8000")
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/conf.d/upstream.conf ')
ee_nginx = open('/etc/nginx/conf.d/upstream.conf',
encoding='utf-8', mode='w')
app.render((data), 'upstream.mustache', out=ee_nginx)
ee_nginx.close()
# Setup Nginx common directory
if not os.path.exists('/etc/nginx/common'):
self.log.debug(self, 'Creating directory'
'/etc/nginx/common')
os.makedirs('/etc/nginx/common')
data = dict(webroot=EEVariables.ee_webroot)
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/acl.conf')
ee_nginx = open('/etc/nginx/common/acl.conf',
encoding='utf-8', mode='w')
app.render((data), 'acl.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/locations.conf')
ee_nginx = open('/etc/nginx/common/locations.conf',
encoding='utf-8', mode='w')
app.render((data), 'locations.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php-hhvm.conf')
ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'php-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/w3tc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'w3tc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpfc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpfc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsc-hhvm.conf')
ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpsc-hhvm.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php.conf')
ee_nginx = open('/etc/nginx/common/php.conf',
encoding='utf-8', mode='w')
app.render((data), 'php.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/w3tc.conf')
ee_nginx = open('/etc/nginx/common/w3tc.conf',
encoding='utf-8', mode='w')
app.render((data), 'w3tc.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpcommon.conf')
ee_nginx = open('/etc/nginx/common/wpcommon.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpcommon.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpfc.conf')
ee_nginx = open('/etc/nginx/common/wpfc.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpfc.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsc.conf')
ee_nginx = open('/etc/nginx/common/wpsc.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpsc.mustache',
out=ee_nginx)
ee_nginx.close()
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpsubdir.conf')
ee_nginx = open('/etc/nginx/common/wpsubdir.conf',
encoding='utf-8', mode='w')
app.render((data), 'wpsubdir.mustache',
out=ee_nginx)
ee_nginx.close()
# Fix whitescreen of death beacuse of missing value
# fastcgi_param SCRIPT_FILENAME $request_filename; in file
# /etc/nginx/fastcgi_params
if not EEFileUtils.grep(self, '/etc/nginx/fastcgi_params',
'SCRIPT_FILENAME'):
with open('/etc/nginx/fastcgi_params',
encoding='utf-8', mode='a') as ee_nginx:
ee_nginx.write('fastcgi_param \tSCRIPT_FILENAME '
'\t$request_filename;\n')
# Pagespeed configuration
self.log.debug(self, 'Writting the Pagespeed Global '
'configuration to file /etc/nginx/conf.d/'
'pagespeed.conf')
ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf',
encoding='utf-8', mode='w')
app.render((data), 'pagespeed-global.mustache',
out=ee_nginx)
ee_nginx.close()
# 22222 port settings
self.log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/sites-available/'
'22222')
ee_nginx = open('/etc/nginx/sites-available/22222',
encoding='utf-8', mode='w')
app.render((data), '22222.mustache',
out=ee_nginx)
ee_nginx.close()
passwd = ''.join([random.choice
(string.ascii_letters + string.digits)
for n in range(6)])
try:
EEShellExec.cmd_exec(self, "printf \"easyengine:"
"$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\""
"> /etc/nginx/htpasswd-ee "
"2>/dev/null"
.format(password=passwd))
except CommandExecutionError as e:
self.log.error(self, "Failed to save HTTP Auth")
# Create Symbolic link for 22222
EEFileUtils.create_symlink(self, ['/etc/nginx/'
'sites-available/'
'22222',
'/etc/nginx/'
'sites-enabled/'
'22222'])
# Create log and cert folder and softlinks
if not os.path.exists('{0}22222/logs'
.format(EEVariables.ee_webroot)):
self.log.debug(self, "Creating directory "
"{0}22222/logs "
.format(EEVariables.ee_webroot))
os.makedirs('{0}22222/logs'
.format(EEVariables.ee_webroot))
if not os.path.exists('{0}22222/cert'
.format(EEVariables.ee_webroot)):
self.log.debug(self, "Creating directory "
"{0}22222/cert"
.format(EEVariables.ee_webroot))
os.makedirs('{0}22222/cert'
.format(EEVariables.ee_webroot))
EEFileUtils.create_symlink(self, ['/var/log/nginx/'
'22222.access.log',
'{0}22222/'
'logs/access.log'
.format(EEVariables.ee_webroot)]
)
EEFileUtils.create_symlink(self, ['/var/log/nginx/'
'22222.error.log',
'{0}22222/'
'logs/error.log'
.format(EEVariables.ee_webroot)]
)
try:
EEShellExec.cmd_exec(self, "openssl genrsa -out "
"{0}22222/cert/22222.key 2048"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl req -new -batch "
"-subj /commonName=127.0.0.1/ "
"-key {0}22222/cert/22222.key "
"-out {0}22222/cert/"
"22222.csr"
.format(EEVariables.ee_webroot))
EEFileUtils.mvfile(self, "{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot),
"{0}22222/cert/"
"22222.key.org"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl rsa -in "
"{0}22222/cert/"
"22222.key.org -out "
"{0}22222/cert/22222.key"
.format(EEVariables.ee_webroot))
EEShellExec.cmd_exec(self, "openssl x509 -req -days "
"3652 -in {0}22222/cert/"
"22222.csr -signkey {0}"
"22222/cert/22222.key -out "
"{0}22222/cert/22222.crt"
.format(EEVariables.ee_webroot))
except CommandExecutionError as e:
self.log.error(self, "Failed to generate SSL for 22222")
# Nginx Configation into GIT
EEGit.add(self,
["/etc/nginx"], msg="Adding Nginx into Git")
EEService.reload_service(self, 'nginx')
# self.msg = (self.msg + ["HTTP Auth User Name: easyengine"]
# + ["HTTP Auth Password : {0}".format(passwd)])
def install_stack(self):
"""

147
ee/cli/plugins/phpstack.py

@ -2,6 +2,7 @@ import os
import sys
import random
import string
import codecs
import configparser
from ee.core.variables import EEVariables
from ee.core.aptget import EEAptGet
@ -9,6 +10,9 @@ from ee.core.apt_repo import EERepo
from ee.cli.plugins.eestack import EEStack
from ee.core.shellexec import EEShellExec
from ee.core.shellexec import CommandExecutionError
from ee.core.fileutils import EEFileUtils
from ee.core.git import EEGit
from ee.core.services import EEService
from ee.core.logging import Log
from ee.cli.main import app
@ -18,6 +22,7 @@ class EEPhpStack(EEStack):
EasyEngine PHP stack
"""
packages_name = EEVariables.ee_php
app = app
log = app.log
def __init__(self, packages_name=None):
@ -60,7 +65,147 @@ class EEPhpStack(EEStack):
"""
Defines activities done after installing php stack
"""
pass
# Create log directories
if not os.path.exists('/var/log/php5/'):
self.log.debug(self, 'Creating directory /var/log/php5/')
os.makedirs('/var/log/php5/')
# For debian install xdebug
if (EEVariables.ee_platform_distro == "debian" and
EEVariables.ee_platform_codename == 'wheezy'):
EEShellExec.cmd_exec(self, "pecl install xdebug")
with open("/etc/php5/mods-available/xdebug.ini",
encoding='utf-8', mode='a') as myfile:
myfile.write("zend_extension=/usr/lib/php5/20131226/"
"xdebug.so\n")
EEFileUtils.create_symlink(self, ["/etc/php5/"
"mods-available/xdebug.ini",
"/etc/php5/fpm/conf.d"
"/20-xedbug.ini"])
# Parse etc/php5/fpm/php.ini
config = configparser.ConfigParser()
self.log.debug(self, "configuring php file /etc/php5/fpm/php.ini")
config.read('/etc/php5/fpm/php.ini')
config['PHP']['expose_php'] = 'Off'
config['PHP']['post_max_size'] = '100M'
config['PHP']['upload_max_filesize'] = '100M'
config['PHP']['max_execution_time'] = '300'
config['PHP']['date.timezone'] = EEVariables.ee_timezone
with open('/etc/php5/fpm/php.ini',
encoding='utf-8', mode='w') as configfile:
self.log.debug(self, "Writting php configuration into "
"/etc/php5/fpm/php.ini")
config.write(configfile)
# Prase /etc/php5/fpm/php-fpm.conf
config = configparser.ConfigParser()
self.log.debug(self, "configuring php file"
"/etc/php5/fpm/php-fpm.conf")
config.read_file(codecs.open("/etc/php5/fpm/php-fpm.conf",
"r", "utf8"))
config['global']['error_log'] = '/var/log/php5/fpm.log'
config.remove_option('global', 'include')
config['global']['log_level'] = 'notice'
config['global']['include'] = '/etc/php5/fpm/pool.d/*.conf'
with codecs.open('/etc/php5/fpm/php-fpm.conf',
encoding='utf-8', mode='w') as configfile:
self.log.debug(self, "writting php5 configuration into "
"/etc/php5/fpm/php-fpm.conf")
config.write(configfile)
# Parse /etc/php5/fpm/pool.d/www.conf
config = configparser.ConfigParser()
config.read_file(codecs.open('/etc/php5/fpm/pool.d/www.conf',
"r", "utf8"))
config['www']['ping.path'] = '/ping'
config['www']['pm.status_path'] = '/status'
config['www']['pm.max_requests'] = '500'
config['www']['pm.max_children'] = '100'
config['www']['pm.start_servers'] = '20'
config['www']['pm.min_spare_servers'] = '10'
config['www']['pm.max_spare_servers'] = '30'
config['www']['request_terminate_timeout'] = '300'
config['www']['pm'] = 'ondemand'
config['www']['listen'] = '127.0.0.1:9000'
with codecs.open('/etc/php5/fpm/pool.d/www.conf',
encoding='utf-8', mode='w') as configfile:
self.log.debug(self, "writting PHP5 configuration into "
"/etc/php5/fpm/pool.d/www.conf")
config.write(configfile)
# Generate /etc/php5/fpm/pool.d/debug.conf
EEFileUtils.copyfile(self, "/etc/php5/fpm/pool.d/www.conf",
"/etc/php5/fpm/pool.d/debug.conf")
EEFileUtils.searchreplace(self, "/etc/php5/fpm/pool.d/"
"debug.conf", "[www]", "[debug]")
config = configparser.ConfigParser()
config.read('/etc/php5/fpm/pool.d/debug.conf')
config['debug']['listen'] = '127.0.0.1:9001'
config['debug']['rlimit_core'] = 'unlimited'
config['debug']['slowlog'] = '/var/log/php5/slow.log'
config['debug']['request_slowlog_timeout'] = '10s'
with open('/etc/php5/fpm/pool.d/debug.conf',
encoding='utf-8', mode='w') as confifile:
self.log.debug(self, "writting PHP5 configuration into "
"/etc/php5/fpm/pool.d/debug.conf")
config.write(confifile)
with open("/etc/php5/fpm/pool.d/debug.conf",
encoding='utf-8', mode='a') as myfile:
myfile.write("php_admin_value[xdebug.profiler_output_dir] "
"= /tmp/ \nphp_admin_value[xdebug.profiler_"
"output_name] = cachegrind.out.%p-%H-%R "
"\nphp_admin_flag[xdebug.profiler_enable"
"_trigger] = on \nphp_admin_flag[xdebug."
"profiler_enable] = off\n")
# Disable xdebug
EEFileUtils.searchreplace(self, "/etc/php5/mods-available/"
"xdebug.ini",
"zend_extension",
";zend_extension")
# PHP and Debug pull configuration
if not os.path.exists('{0}22222/htdocs/fpm/status/'
.format(EEVariables.ee_webroot)):
self.log.debug(self, 'Creating directory '
'{0}22222/htdocs/fpm/status/ '
.format(EEVariables.ee_webroot))
os.makedirs('{0}22222/htdocs/fpm/status/'
.format(EEVariables.ee_webroot))
open('{0}22222/htdocs/fpm/status/debug'
.format(EEVariables.ee_webroot),
encoding='utf-8', mode='a').close()
open('{0}22222/htdocs/fpm/status/php'
.format(EEVariables.ee_webroot),
encoding='utf-8', mode='a').close()
# Write info.php
if not os.path.exists('{0}22222/htdocs/php/'
.format(EEVariables.ee_webroot)):
self.log.debug(self, 'Creating directory '
'{0}22222/htdocs/php/ '
.format(EEVariables.ee_webroot))
os.makedirs('{0}22222/htdocs/php'
.format(EEVariables.ee_webroot))
with open("{0}22222/htdocs/php/info.php"
.format(EEVariables.ee_webroot),
encoding='utf-8', mode='w') as myfile:
myfile.write("<?php\nphpinfo();\n?>")
EEFileUtils.chown(self, "{0}22222"
.format(EEVariables.ee_webroot),
EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git")
EEService.restart_service(self, 'php5-fpm')
def install_stack(self):
"""

6
ee/cli/plugins/postfixstack.py

@ -5,6 +5,8 @@ from ee.core.aptget import EEAptGet
from ee.core.apt_repo import EERepo
from ee.cli.plugins.eestack import EEStack
from ee.core.shellexec import EEShellExec
from ee.core.services import EEService
from ee.core.git import EEGit
from ee.core.shellexec import CommandExecutionError
from ee.cli.main import app
@ -57,7 +59,9 @@ class EEPostfixStack(EEStack):
"""
Defines activities done after installing hhvm stack
"""
pass
EEGit.add(self, ["/etc/postfix"],
msg="Adding Postfix into Git")
EEService.reload_service(self, 'postfix')
def install_stack(self):
"""

Loading…
Cancel
Save