Browse Source

adding log messages

bugfixes
shital.rtcamp 10 years ago
parent
commit
fe9bb101b6
  1. 129
      ee/cli/plugins/stack.py

129
ee/cli/plugins/stack.py

@ -73,11 +73,12 @@ class EEStackController(CementBaseController):
EEShellExec.cmd_exec("echo \"postfix postfix/mailname string "
"$(hostname -f)\" | debconf-set-selections")
if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
print("Adding repository for mysql ... ")
print("Adding repository for MySQL ... ")
EERepo.add(repo_url=EEVariables.ee_mysql_repo)
self.app.log.debug('Adding key of MySQL.')
EERepo.add_key('1C4CBDCDCD2EFD2A')
chars = ''.join(random.sample(string.ascii_letters, 8))
print("Pre-seeding mysql variables ... ")
print("Pre-seeding MySQL variables ... ")
EEShellExec.cmd_exec("echo \"percona-server-server-5.6 "
"percona-server-server/root_password "
"password {chars}\" | "
@ -93,29 +94,35 @@ class EEStackController(CementBaseController):
""".format(chars=chars)
config = configparser.ConfigParser()
config.read_string(mysql_config)
self.app.log.debug('writting configartion into MySQL file.')
with open(os.path.expanduser("~")+'/.my.cnf', 'w') as configfile:
config.write(configfile)
if set(EEVariables.ee_nginx).issubset(set(apt_packages)):
print("Adding repository for nginx ... ")
print("Adding repository for Nginx ... ")
if EEVariables.ee_platform_distro == 'Debian':
self.app.log.debug('Adding Dotdeb/nginx GPG key')
EERepo.add(repo_url=EEVariables.ee_nginx_repo)
else:
self.app.log.debug('Adding ppa of Nginx')
EERepo.add(ppa=EEVariables.ee_nginx_repo)
if set(EEVariables.ee_php).issubset(set(apt_packages)):
print("Adding repository for php ... ")
print("Adding repository for PHP ... ")
if EEVariables.ee_platform_distro == 'Debian':
self.app.log.debug('Adding repo_url of php for Debian')
EERepo.add(repo_url=EEVariables.ee_php_repo)
self.app.log.debug('Adding Dotdeb/php GPG key')
EERepo.add_key('89DF5277')
else:
self.app.log.debug('Adding ppa for PHP')
EERepo.add(ppa=EEVariables.ee_php_repo)
if set(EEVariables.ee_mail).issubset(set(apt_packages)):
if EEVariables.ee_platform_codename == 'squeeze':
print("Adding repository for dovecot ... ")
EERepo.add(repo_url=EEVariables.ee_dovecot_repo)
self.app.log.debug('Executing the command debconf-set-selections.')
EEShellExec.cmd_exec("echo \"dovecot-core dovecot-core/"
"create-ssl-cert boolean yes\" "
"| debconf-set-selections")
@ -132,6 +139,7 @@ class EEStackController(CementBaseController):
# Nginx core configuration change using configparser
nc = NginxConfig()
print('in nginx')
self.app.log.debug('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)
@ -140,10 +148,14 @@ class EEStackController(CementBaseController):
[('worker_connections', '4096'),
('multi_accept', 'on')]}, position=4)
nc.set([('http',), 'keepalive_timeout'], '30')
self.app.log.debug("Writting nginx configration to "
"file /etc/nginx/nginx.conf ")
nc.savef('/etc/nginx/nginx.conf')
# Custom Nginx configuration by EasyEngine
data = dict(version='EasyEngine 3.0.1')
self.app.log.debug('writting the nginx configration to file'
'/etc/nginx/conf.d/ee-nginx.conf ')
ee_nginx = open('/etc/nginx/conf.d/ee-nginx.conf', 'w')
self.app.render((data), 'nginx-core.mustache', out=ee_nginx)
ee_nginx.close()
@ -151,6 +163,7 @@ class EEStackController(CementBaseController):
if set(EEVariables.ee_php).issubset(set(apt_packages)):
# Parse etc/php5/fpm/php.ini
config = configparser.ConfigParser()
self.app.log.debug("configring 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'
@ -158,6 +171,8 @@ class EEStackController(CementBaseController):
config['PHP']['max_execution_time'] = '300'
config['PHP']['date.timezone'] = time.tzname[time.daylight]
with open('/etc/php5/fpm/php.ini', 'w') as configfile:
self.app.log.debug("writting configration of php in to"
"file /etc/php5/fpm/php.ini")
config.write(configfile)
# Prase /etc/php5/fpm/php-fpm.conf
@ -165,6 +180,8 @@ class EEStackController(CementBaseController):
config.read('/etc/php5/fpm/php-fpm.conf')
config['global']['error_log'] = '/var/log/php5/fpm.log'
with open('/etc/php5/fpm/php-fpm.conf', 'w') as configfile:
self.app.log.debug("writting php5 configartion into "
" /etc/php5/fpm/php-fpm.conf")
config.write(configfile)
# Parse /etc/php5/fpm/pool.d/www.conf
@ -181,6 +198,8 @@ class EEStackController(CementBaseController):
config['www']['pm'] = 'ondemand'
config['www']['listen'] = '127.0.0.1:9000'
with open('/etc/php5/fpm/pool.d/www.conf', 'w') as configfile:
self.app.log.debug("writting PHP5 configartion into "
" /etc/php5/fpm/pool.d/www.conf")
config.write(configfile)
if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
@ -193,6 +212,7 @@ class EEStackController(CementBaseController):
config.write(configfile)
if set(EEVariables.ee_mail).issubset(set(apt_packages)):
self.app.log.debug("Executing mail commands")
EEShellExec.cmd_exec("adduser --uid 5000 --home /var/vmail"
"--disabled-password --gecos '' vmail")
EEShellExec.cmd_exec("openssl req -new -x509 -days 3650 -nodes"
@ -201,10 +221,14 @@ class EEStackController(CementBaseController):
"pem -keyout /etc/ssl/private/dovecot.pem"
.format(HOSTNAME=EEVariables.ee_fqdn,
EMAIL=EEVariables.ee_email))
self.app.log.debug("Adding Privillages to file "
"/etc/ssl/private/dovecot.pem ")
EEShellExec.cmd_exec("chmod 0600 /etc/ssl/private/dovecot.pem")
# Custom Dovecot configuration by EasyEngine
data = dict()
self.app.log.debug("Writting configration into file"
"/etc/dovecot/conf.d/99-ee.conf ")
ee_dovecot = open('/etc/dovecot/conf.d/99-ee.conf', 'w')
self.app.render((data), 'dovecot.mustache', out=ee_dovecot)
ee_dovecot.close()
@ -266,16 +290,21 @@ class EEStackController(CementBaseController):
# Sieve configuration
if not os.path.exists('/var/lib/dovecot/sieve/'):
self.app.log.debug('Creating directory'
'/var/lib/dovecot/sieve/ ')
os.makedirs('/var/lib/dovecot/sieve/')
# Custom sieve configuration by EasyEngine
data = dict()
self.app.log.debug("Writting configaration of EasyEngine into"
"file /var/lib/dovecot/sieve/default.sieve")
ee_sieve = open('/var/lib/dovecot/sieve/default.sieve', 'w')
self.app.render((data), 'default-sieve.mustache',
out=ee_sieve)
ee_sieve.close()
# Compile sieve rules
self.app.log.debug("Privillages to dovecot ")
EEShellExec.cmd_exec("chown -R vmail:vmail /var/lib/dovecot")
EEShellExec.cmd_exec("sievec /var/lib/dovecot/sieve/"
"default.sieve")
@ -286,33 +315,52 @@ class EEStackController(CementBaseController):
if any('/tmp/pma.tar.gz' == x[1]
for x in packages):
EEExtract.extract('/tmp/pma.tar.gz', '/tmp/')
self.app.log.debug('Extracting file /tmp/pma.tar.gz to '
'loaction /tmp/')
if not os.path.exists('/var/www/22222/htdocs/db'):
self.app.log.debug("Creating new directory "
"/var/www/22222/htdocs/db")
os.makedirs('/var/www/22222/htdocs/db')
shutil.move('/tmp/phpmyadmin-STABLE/',
'/var/www/22222/htdocs/db/pma/')
self.app.log.debug('Privillages to www-data:www-data '
'/var/www/22222/htdocs/db/pma ')
EEShellExec.cmd_exec('chown -R www-data:www-data '
'/var/www/22222/htdocs/db/pma')
if any('/tmp/memcache.tar.gz' == x[1]
for x in packages):
self.app.log.debug("Extracting memcache.tar.gz to location"
" /var/www/22222/htdocs/cache/memcache ")
EEExtract.extract('/tmp/memcache.tar.gz',
'/var/www/22222/htdocs/cache/memcache')
self.app.log.debug("Privillages to"
" /var/www/22222/htdocs/cache/memcache")
EEShellExec.cmd_exec('chown -R www-data:www-data '
'/var/www/22222/htdocs/cache/memcache')
if any('/tmp/webgrind.tar.gz' == x[1]
for x in packages):
self.app.log.debug("Extracting file webgrind.tar.gz to "
"location /tmp/ ")
EEExtract.extract('/tmp/webgrind.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/php'):
self.app.log.debug("Creating directroy "
"/var/www/22222/htdocs/php")
os.makedirs('/var/www/22222/htdocs/php')
shutil.move('/tmp/webgrind-master/',
'/var/www/22222/htdocs/php/webgrind')
self.app.log.debug("Privillages www-data:www-data "
"/var/www/22222/htdocs/php/webgrind/ ")
EEShellExec.cmd_exec('chown -R www-data:www-data '
'/var/www/22222/htdocs/php/webgrind/')
if any('/tmp/anemometer.tar.gz' == x[1]
for x in packages):
self.app.log.debug("Extracting file anemometer.tar.gz to "
"location /tmp/ ")
EEExtract.extract('/tmp/anemometer.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/db/'):
self.app.log.debug("Creating directory")
os.makedirs('/var/www/22222/htdocs/db/')
shutil.move('/tmp/Anemometer-master',
'/var/www/22222/htdocs/db/anemometer')
@ -326,6 +374,7 @@ class EEStackController(CementBaseController):
' BY \''+chars+'\'')
# Custom Anemometer configuration
self.app.log.debug("configration Anemometer")
data = dict(host='localhost', port='3306', user='anemometer',
password=chars)
ee_anemometer = open('/var/www/22222/htdocs/db/anemometer'
@ -340,16 +389,23 @@ class EEStackController(CementBaseController):
if any('/tmp/vimbadmin.tar.gz' == x[1] for x in packages):
# Extract ViMbAdmin
self.app.log.debug("Extracting ViMbAdmin.tar.gz to "
"location /tmp/")
EEExtract.extract('/tmp/vimbadmin.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/'):
self.app.log.debug("Creating directory "
" /var/www/22222/htdocs/")
os.makedirs('/var/www/22222/htdocs/')
shutil.move('/tmp/ViMbAdmin-3.0.10/',
'/var/www/22222/htdocs/vimbadmin/')
# Donwload composer and install ViMbAdmin
self.app.log.debug("Downloading composer "
"https://getcomposer.org/installer | php ")
EEShellExec.cmd_exec("cd /var/www/22222/htdocs/vimbadmin; curl"
" -sS https://getcomposer.org/installer |"
" php")
self.app.log.debug("installation of composer")
EEShellExec.cmd_exec("cd /var/www/22222/htdocs/vimbadmin && "
"php composer.phar install --prefer-dist"
" --no-dev && rm -f /var/www/22222/htdocs"
@ -357,14 +413,16 @@ class EEStackController(CementBaseController):
# Configure vimbadmin database
vm_passwd = ''.join(random.sample(string.ascii_letters, 8))
self.app.log.debug("Creating vimbadmin database if not exist")
EEMysql.execute("create database if not exists vimbadmin")
self.app.log.debug("Granting all privileges on vimbadmin ")
EEMysql.execute("grant all privileges on vimbadmin.* to"
" vimbadmin@localhost IDENTIFIED BY"
" '{password}'".format(password=vm_passwd))
# Configure ViMbAdmin settings
config = configparser.ConfigParser(strict=False)
self.app.log.debug("configuring ViMbAdmin ")
config.read('/var/www/22222/htdocs/vimbadmin/application/'
'configs/application.ini.dist')
config['user']['defaults.mailbox.uid'] = '5000'
@ -395,6 +453,9 @@ class EEStackController(CementBaseController):
(string.ascii_letters
+ string.ascii_letters,
64)))
self.app.log.debug("Writting configration to file "
"/var/www/22222/htdocs/vimbadmin"
"/application/configs/application.ini ")
with open('/var/www/22222/htdocs/vimbadmin/application'
'/configs/application.ini', 'w') as configfile:
config.write(configfile)
@ -403,13 +464,20 @@ class EEStackController(CementBaseController):
".htaccess.dist",
"/var/www/22222/htdocs/vimbadmin/public/"
".htaccess")
self.app.log.debug("Executing command "
"/var/www/22222/htdocs/vimbadmin/bin"
"/doctrine2-cli.php orm:schema-tool:"
"create" ")
EEShellExec.cmd_exec("/var/www/22222/htdocs/vimbadmin/bin"
"/doctrine2-cli.php orm:schema-tool:"
"create")
# Copy Dovecot and Postfix templates which are depednet on
# Vimbadmin
if not os.path.exists('/etc/postfix/mysql/'):
self.app.log.debug("Creating directory "
"/etc/postfix/mysql/")
os.makedirs('/etc/postfix/mysql/')
data = dict(password=vm_passwd)
vm_config = open('/etc/postfix/mysql/virtual_alias_maps.cf',
@ -418,18 +486,25 @@ class EEStackController(CementBaseController):
out=vm_config)
vm_config.close()
self.app.log.debug("Configration of file "
"/etc/postfix/mysql"
"/virtual_domains_maps.cf")
vm_config = open('/etc/postfix/mysql/virtual_domains_maps.cf',
'w')
self.app.render((data), 'virtual_domains_maps.mustache',
out=vm_config)
vm_config.close()
self.app.log.debug("Configation of file "
"/etc/postfix/mysql"
"/virtual_mailbox_maps.cf ")
vm_config = open('/etc/postfix/mysql/virtual_mailbox_maps.cf',
'w')
self.app.render((data), 'virtual_mailbox_maps.mustache',
out=vm_config)
vm_config.close()
self.app.log.debug("Configration of file ")
vm_config = open('/etc/dovecot/dovecot-sql.conf.ext',
'w')
self.app.render((data), 'dovecot-sql-conf.mustache',
@ -438,15 +513,21 @@ class EEStackController(CementBaseController):
if any('/tmp/roundcube.tar.gz' == x[1] for x in packages):
# Extract RoundCubemail
self.app.log.debug("Extracting file /tmp/roundcube.tar.gz "
"to location /tmp/ ")
EEExtract.extract('/tmp/roundcube.tar.gz', '/tmp/')
if not os.path.exists('/var/www/roundcubemail'):
self.app.log.debug("Creating new directory "
" /var/www/roundcubemail/")
os.makedirs('/var/www/roundcubemail/')
shutil.move('/tmp/roundcubemail-1.0.4/',
'/var/www/roundcubemail/htdocs')
# Configure roundcube database
rc_passwd = ''.join(random.sample(string.ascii_letters, 8))
self.app.log.debug("Creating Database roundcubemail")
EEMysql.execute("create database if not exists roundcubemail")
self.app.log.debug("Grant all privileges on roundcubemail")
EEMysql.execute("grant all privileges on roundcubemail.* to "
" roundcube@localhost IDENTIFIED BY "
"'{password}'".format(password=rc_passwd))
@ -481,6 +562,8 @@ class EEStackController(CementBaseController):
packages = []
if self.app.pargs.web:
self.app.log.debug("Setting apt_packages variable for Nginx ,PHP"
" ,MySQL ")
apt_packages = (apt_packages + EEVariables.ee_nginx +
EEVariables.ee_php + EEVariables.ee_mysql)
@ -489,6 +572,7 @@ class EEStackController(CementBaseController):
# apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.mail:
apt_packages = apt_packages + EEVariables.ee_mail
self.app.log.debug("Setting apt_packages variable for mail")
packages = packages + [["https://github.com/opensolutions/ViMbAdmi"
"n/archive/3.0.10.tar.gz", "/tmp/vimbadmin"
".tar.gz"],
@ -499,28 +583,36 @@ class EEStackController(CementBaseController):
]
if self.app.pargs.nginx:
self.app.log.debug("Setting apt_packages variable for Nginx")
apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.php:
self.app.log.debug("Setting apt_packages variable for PHP")
apt_packages = apt_packages + EEVariables.ee_php
if self.app.pargs.mysql:
self.app.log.debug("Setting apt_packages variable for MySQL")
apt_packages = apt_packages + EEVariables.ee_mysql
if self.app.pargs.postfix:
self.app.log.debug("Setting apt_packages variable for PostFix")
apt_packages = apt_packages + EEVariables.ee_postfix
if self.app.pargs.wpcli:
self.app.log.debug("Setting packages variable for WPCLI")
packages = packages + [["https://github.com/wp-cli/wp-cli/releases"
"/download/v0.17.1/wp-cli.phar",
"/usr/bin/wp"]]
if self.app.pargs.phpmyadmin:
self.app.log.debug("Setting packages varible for phpMyAdmin ")
packages = packages + [["https://github.com/phpmyadmin/phpmyadmin"
"/archive/STABLE.tar.gz",
"/tmp/pma.tar.gz"]]
if self.app.pargs.adminer:
self.app.log.debug("Setting packages variable for Adminer ")
packages = packages + [["http://downloads.sourceforge.net/adminer"
"/adminer-4.1.0.php", "/var/www/22222/"
"htdocs/db/adminer/index.php"]]
if self.app.pargs.utils:
self.app.log.debug("Setting packages variable for utils")
packages = packages + [["http://phpmemcacheadmin.googlecode.com/"
"files/phpMemcachedAdmin-1.2.2"
"-r262.tar.gz", '/tmp/memcache.tar.gz'],
@ -553,12 +645,15 @@ class EEStackController(CementBaseController):
"/master.tar.gz",
'/tmp/anemometer.tar.gz']
]
self.app.log.debug("Calling pre_pref ")
self.pre_pref(apt_packages)
if len(apt_packages):
self.app.log.debug("Installing all apt_packages")
pkg.install(apt_packages)
if len(packages):
self.app.log.debug("Downloading all packages")
EEDownload.download(packages)
self.app.log.debug("Calling post_pref")
self.post_pref(apt_packages, packages)
@expose()
@ -568,6 +663,8 @@ class EEStackController(CementBaseController):
packages = []
if self.app.pargs.web:
self.app.log.debug("Removing apt_packages variable of Nginx "
",PHP,MySQL")
apt_packages = (apt_packages + EEVariables.ee_nginx +
EEVariables.ee_php + EEVariables.ee_mysql)
if self.app.pargs.admin:
@ -577,20 +674,28 @@ class EEStackController(CementBaseController):
pass
# apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.nginx:
self.app.log.debug("Removing apt_packages variable of Nginx")
apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.php:
self.app.log.debug("Removing apt_packages variable of PHP")
apt_packages = apt_packages + EEVariables.ee_php
if self.app.pargs.mysql:
self.app.log.debug("Removing apt_packages variable of MySQL")
apt_packages = apt_packages + EEVariables.ee_mysql
if self.app.pargs.postfix:
self.app.log.debug("Removing apt_packages variable of Postfix")
apt_packages = apt_packages + EEVariables.ee_postfix
if self.app.pargs.wpcli:
self.app.log.debug("Removing package variable of WPCLI ")
packages = packages + ['/usr/bin/wp']
if self.app.pargs.phpmyadmin:
self.app.log.debug("Removing package variable of phpMyAdmin ")
packages = packages + ['/var/www/22222/htdocs/db/pma']
if self.app.pargs.adminer:
self.app.log.debug("Removing package variable of Adminer ")
packages = packages + ['/var/www/22222/htdocs/db/adminer']
if self.app.pargs.utils:
self.app.log.debug("Removing package variable of utils ")
packages = packages + ['/var/www/22222/htdocs/php/webgrind/',
'/var/www/22222/htdocs/cache/opcache',
'/var/www/22222/htdocs/cache/nginx/'
@ -600,6 +705,7 @@ class EEStackController(CementBaseController):
'/var/www/22222/htdocs/db/anemometer']
if len(apt_packages):
self.app.log.debug("Removing apt_packages")
pkg.remove(apt_packages)
if len(packages):
EEFileUtils.remove(packages)
@ -611,6 +717,7 @@ class EEStackController(CementBaseController):
packages = []
if self.app.pargs.web:
self.app.log.debug("Purge Nginx,PHP,MySQL")
apt_packages = (apt_packages + EEVariables.ee_nginx
+ EEVariables.ee_php + EEVariables.ee_mysql)
if self.app.pargs.admin:
@ -620,20 +727,28 @@ class EEStackController(CementBaseController):
pass
# apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.nginx:
self.app.log.debug("Purge apt_packages variable of Nginx")
apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.php:
self.app.log.debug("Purge apt_packages variable PHP")
apt_packages = apt_packages + EEVariables.ee_php
if self.app.pargs.mysql:
self.app.log.debug("Purge apt_packages variable MySQL")
apt_packages = apt_packages + EEVariables.ee_mysql
if self.app.pargs.postfix:
self.app.log.debug("Purge apt_packages variable PostFix")
apt_packages = apt_packages + EEVariables.ee_postfix
if self.app.pargs.wpcli:
self.app.log.debug("Purge package variable WPCLI")
packages = packages + ['/usr/bin/wp']
if self.app.pargs.phpmyadmin:
packages = packages + ['/var/www/22222/htdocs/db/pma']
self.app.log.debug("Purge package variable phpMyAdmin")
if self.app.pargs.adminer:
self.app.log.debug("Purge package variable Adminer")
packages = packages + ['/var/www/22222/htdocs/db/adminer']
if self.app.pargs.utils:
self.app.log.debug("Purge package variable utils")
packages = packages + ['/var/www/22222/htdocs/php/webgrind/',
'/var/www/22222/htdocs/cache/opcache',
'/var/www/22222/htdocs/cache/nginx/'

Loading…
Cancel
Save