Browse Source

updated

bugfixes
shital.rtcamp 10 years ago
parent
commit
f7a1fca684
  1. 122
      ee/cli/plugins/stack.py
  2. 28
      ee/cli/plugins/stack_services.py
  3. 4
      ee/core/aptget.py
  4. 25
      ee/core/download.py
  5. 5
      ee/core/extract.py
  6. 17
      ee/core/fileutils.py
  7. 8
      ee/core/mysql.py
  8. 4
      ee/core/services.py
  9. 6
      ee/core/shellexec.py
  10. 1
      ee/core/variables.py

122
ee/cli/plugins/stack.py

@ -67,10 +67,10 @@ class EEStackController(CementBaseController):
def pre_pref(self, apt_packages): def pre_pref(self, apt_packages):
if set(EEVariables.ee_postfix).issubset(set(apt_packages)): if set(EEVariables.ee_postfix).issubset(set(apt_packages)):
print("Pre-seeding postfix variables ... ") print("Pre-seeding postfix variables ... ")
EEShellExec.cmd_exec("echo \"postfix postfix/main_mailer_type " EEShellExec.cmd_exec(self, "echo \"postfix postfix "
"string 'Internet Site'\" | " "/main_mailer_typestring 'Internet Site'\" | "
"debconf-set-selections") "debconf-set-selections")
EEShellExec.cmd_exec("echo \"postfix postfix/mailname string " EEShellExec.cmd_exec(self, "echo \"postfix postfix/mailname string"
"$(hostname -f)\" | debconf-set-selections") "$(hostname -f)\" | debconf-set-selections")
if set(EEVariables.ee_mysql).issubset(set(apt_packages)): if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
print("Adding repository for MySQL ... ") print("Adding repository for MySQL ... ")
@ -79,11 +79,11 @@ class EEStackController(CementBaseController):
EERepo.add_key('1C4CBDCDCD2EFD2A') EERepo.add_key('1C4CBDCDCD2EFD2A')
chars = ''.join(random.sample(string.ascii_letters, 8)) 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 " EEShellExec.cmd_exec(self, "echo \"percona-server-server-5.6 "
"percona-server-server/root_password " "percona-server-server/root_password "
"password {chars}\" | " "password {chars}\" | "
"debconf-set-selections".format(chars=chars)) "debconf-set-selections".format(chars=chars))
EEShellExec.cmd_exec("echo \"percona-server-server-5.6 " EEShellExec.cmd_exec(self, "echo \"percona-server-server-5.6 "
"percona-server-server/root_password_again " "percona-server-server/root_password_again "
"password {chars}\" | " "password {chars}\" | "
"debconf-set-selections".format(chars=chars)) "debconf-set-selections".format(chars=chars))
@ -101,7 +101,8 @@ class EEStackController(CementBaseController):
if set(EEVariables.ee_nginx).issubset(set(apt_packages)): 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': if EEVariables.ee_platform_distro == 'Debian':
self.app.log.debug('Adding Dotdeb/nginx GPG key') s
elf.app.log.debug('Adding Dotdeb/nginx GPG key')
EERepo.add(repo_url=EEVariables.ee_nginx_repo) EERepo.add(repo_url=EEVariables.ee_nginx_repo)
else: else:
self.app.log.debug('Adding ppa of Nginx') self.app.log.debug('Adding ppa of Nginx')
@ -123,11 +124,11 @@ class EEStackController(CementBaseController):
print("Adding repository for dovecot ... ") print("Adding repository for dovecot ... ")
EERepo.add(repo_url=EEVariables.ee_dovecot_repo) EERepo.add(repo_url=EEVariables.ee_dovecot_repo)
self.app.log.debug('Executing the command debconf-set-selections.') self.app.log.debug('Executing the command debconf-set-selections.')
EEShellExec.cmd_exec("echo \"dovecot-core dovecot-core/" EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core/"
"create-ssl-cert boolean yes\" " "create-ssl-cert boolean yes\" "
"| debconf-set-selections") "| debconf-set-selections")
EEShellExec.cmd_exec("echo \"dovecot-core dovecot-core/ssl-cert-" EEShellExec.cmd_exec(self, "echo \"dovecot-core dovecot-core"
"name string $(hostname -f)\"" "/ssl-cert-name string $(hostname -f)\""
" | debconf-set-selections") " | debconf-set-selections")
@expose(hide=True) @expose(hide=True)
@ -213,17 +214,20 @@ class EEStackController(CementBaseController):
if set(EEVariables.ee_mail).issubset(set(apt_packages)): if set(EEVariables.ee_mail).issubset(set(apt_packages)):
self.app.log.debug("Executing mail commands") self.app.log.debug("Executing mail commands")
EEShellExec.cmd_exec("adduser --uid 5000 --home /var/vmail" EEShellExec.cmd_exec(self, "adduser --uid 5000 --home /var"
"--disabled-password --gecos '' vmail") "/vmail--disabled-password --gecos ''"
EEShellExec.cmd_exec("openssl req -new -x509 -days 3650 -nodes" " vmail")
" -subj /commonName={HOSTNAME}/emailAddre" EEShellExec.cmd_exec(self, "openssl req -new -x509 -days 3650 "
"ss={EMAIL} -out /etc/ssl/certs/dovecot." "-nodes -subj /commonName={HOSTNAME}"
"/emailAddre ss={EMAIL} -out /etc/ssl"
"/certs/dovecot."
"pem -keyout /etc/ssl/private/dovecot.pem" "pem -keyout /etc/ssl/private/dovecot.pem"
.format(HOSTNAME=EEVariables.ee_fqdn, .format(HOSTNAME=EEVariables.ee_fqdn,
EMAIL=EEVariables.ee_email)) EMAIL=EEVariables.ee_email))
self.app.log.debug("Adding Privillages to file " self.app.log.debug("Adding Privillages to file "
"/etc/ssl/private/dovecot.pem ") "/etc/ssl/private/dovecot.pem ")
EEShellExec.cmd_exec("chmod 0600 /etc/ssl/private/dovecot.pem") EEShellExec.cmd_exec(self, "chmod 0600 /etc/ssl/private"
"/dovecot.pem")
# Custom Dovecot configuration by EasyEngine # Custom Dovecot configuration by EasyEngine
data = dict() data = dict()
@ -236,24 +240,28 @@ class EEStackController(CementBaseController):
# Custom Postfix configuration needed with Dovecot # Custom Postfix configuration needed with Dovecot
# Changes in master.cf # Changes in master.cf
# TODO: Find alternative for sed in Python # TODO: Find alternative for sed in Python
EEShellExec.cmd_exec("sed -i \'s/#submission/submission/\'" EEShellExec.cmd_exec(self, "sed -i \'s/#submission/submission"
"/\'"
" /etc/postfix/master.cf") " /etc/postfix/master.cf")
EEShellExec.cmd_exec("sed -i \'s/#smtps/smtps/\'" EEShellExec.cmd_exec(self, "sed -i \'s/#smtps/smtps/\'"
" /etc/postfix/master.cf") " /etc/postfix/master.cf")
EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_type = " EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_type = "
"dovecot\"") "dovecot\"")
EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_path = " EEShellExec.cmd_exec(self, "postconf -e \"smtpd_sasl_path = "
"private/auth\"") "private/auth\"")
EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_auth_enable = " EEShellExec.cmd_exec(self, "postconf -e \""
"smtpd_sasl_auth_enable = "
"yes\"") "yes\"")
EEShellExec.cmd_exec("postconf -e \"smtpd_relay_restrictions =" EEShellExec.cmd_exec(self, "postconf -e \""
" permit_sasl_authenticated, " "smtpd_relay_restrictions ="
"permit_mynetworks, " "permit_sasl_authenticated, "
"reject_unauth_destination\"") "permit_mynetworks, "
EEShellExec.cmd_exec("postconf -e \"smtpd_tls_mandatory_" "reject_unauth_destination\"")
"protocols = !SSLv2,!SSLv3\"") "protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec("postconf -e \"smtp_tls_mandatory_" EEShellExec.cmd_exec(self, "postconf -e \""
"smtpd_tls_mandatory_")
EEShellExec.cmd_exec(self, "postconf -e \"smtp_tls_mandatory_"
"protocols = !SSLv2,!SSLv3\"") "protocols = !SSLv2,!SSLv3\"")
EEShellExec.cmd_exec("postconf -e \"smtpd_tls_protocols " EEShellExec.cmd_exec("postconf -e \"smtpd_tls_protocols "
"= !SSLv2,!SSLv3\"") "= !SSLv2,!SSLv3\"")
@ -348,7 +356,7 @@ class EEStackController(CementBaseController):
EEShellExec.cmd_exec("chmod +x /usr/bin/wp") EEShellExec.cmd_exec("chmod +x /usr/bin/wp")
if any('/tmp/pma.tar.gz' == x[1] if any('/tmp/pma.tar.gz' == x[1]
for x in packages): for x in packages):
EEExtract.extract('/tmp/pma.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/pma.tar.gz', '/tmp/')
self.app.log.debug('Extracting file /tmp/pma.tar.gz to ' self.app.log.debug('Extracting file /tmp/pma.tar.gz to '
'loaction /tmp/') 'loaction /tmp/')
if not os.path.exists('/var/www/22222/htdocs/db'): if not os.path.exists('/var/www/22222/htdocs/db'):
@ -365,7 +373,7 @@ class EEStackController(CementBaseController):
for x in packages): for x in packages):
self.app.log.debug("Extracting memcache.tar.gz to location" self.app.log.debug("Extracting memcache.tar.gz to location"
" /var/www/22222/htdocs/cache/memcache ") " /var/www/22222/htdocs/cache/memcache ")
EEExtract.extract('/tmp/memcache.tar.gz', EEExtract.extract(self, '/tmp/memcache.tar.gz',
'/var/www/22222/htdocs/cache/memcache') '/var/www/22222/htdocs/cache/memcache')
self.app.log.debug("Privillages to" self.app.log.debug("Privillages to"
" /var/www/22222/htdocs/cache/memcache") " /var/www/22222/htdocs/cache/memcache")
@ -376,7 +384,7 @@ class EEStackController(CementBaseController):
for x in packages): for x in packages):
self.app.log.debug("Extracting file webgrind.tar.gz to " self.app.log.debug("Extracting file webgrind.tar.gz to "
"location /tmp/ ") "location /tmp/ ")
EEExtract.extract('/tmp/webgrind.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/webgrind.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/php'): if not os.path.exists('/var/www/22222/htdocs/php'):
self.app.log.debug("Creating directroy " self.app.log.debug("Creating directroy "
"/var/www/22222/htdocs/php") "/var/www/22222/htdocs/php")
@ -392,7 +400,7 @@ class EEStackController(CementBaseController):
for x in packages): for x in packages):
self.app.log.debug("Extracting file anemometer.tar.gz to " self.app.log.debug("Extracting file anemometer.tar.gz to "
"location /tmp/ ") "location /tmp/ ")
EEExtract.extract('/tmp/anemometer.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/anemometer.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/db/'): if not os.path.exists('/var/www/22222/htdocs/db/'):
self.app.log.debug("Creating directory") self.app.log.debug("Creating directory")
os.makedirs('/var/www/22222/htdocs/db/') os.makedirs('/var/www/22222/htdocs/db/')
@ -401,9 +409,9 @@ class EEStackController(CementBaseController):
chars = ''.join(random.sample(string.ascii_letters, 8)) chars = ''.join(random.sample(string.ascii_letters, 8))
EEShellExec.cmd_exec('mysql < /var/www/22222/htdocs/db' EEShellExec.cmd_exec('mysql < /var/www/22222/htdocs/db'
'/anemometer/install.sql') '/anemometer/install.sql')
EEMysql.execute('grant select on *.* to \'anemometer\'' EEMysql.execute(self, 'grant select on *.* to \'anemometer\''
'@\'localhost\'') '@\'localhost\'')
EEMysql.execute('grant all on slow_query_log.* to' EEMysql.execute(self, 'grant all on slow_query_log.* to'
'\'anemometer\'@\'localhost\' IDENTIFIED' '\'anemometer\'@\'localhost\' IDENTIFIED'
' BY \''+chars+'\'') ' BY \''+chars+'\'')
@ -425,7 +433,7 @@ class EEStackController(CementBaseController):
# Extract ViMbAdmin # Extract ViMbAdmin
self.app.log.debug("Extracting ViMbAdmin.tar.gz to " self.app.log.debug("Extracting ViMbAdmin.tar.gz to "
"location /tmp/") "location /tmp/")
EEExtract.extract('/tmp/vimbadmin.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/vimbadmin.tar.gz', '/tmp/')
if not os.path.exists('/var/www/22222/htdocs/'): if not os.path.exists('/var/www/22222/htdocs/'):
self.app.log.debug("Creating directory " self.app.log.debug("Creating directory "
" /var/www/22222/htdocs/") " /var/www/22222/htdocs/")
@ -448,9 +456,10 @@ class EEStackController(CementBaseController):
# Configure vimbadmin database # Configure vimbadmin database
vm_passwd = ''.join(random.sample(string.ascii_letters, 8)) vm_passwd = ''.join(random.sample(string.ascii_letters, 8))
self.app.log.debug("Creating vimbadmin database if not exist") self.app.log.debug("Creating vimbadmin database if not exist")
EEMysql.execute("create database if not exists vimbadmin") EEMysql.execute(self, "create database if not exists"
" vimbadmin")
self.app.log.debug("Granting all privileges on vimbadmin ") self.app.log.debug("Granting all privileges on vimbadmin ")
EEMysql.execute("grant all privileges on vimbadmin.* to" EEMysql.execute(self, "grant all privileges on vimbadmin.* to"
" vimbadmin@localhost IDENTIFIED BY" " vimbadmin@localhost IDENTIFIED BY"
" '{password}'".format(password=vm_passwd)) " '{password}'".format(password=vm_passwd))
@ -502,8 +511,8 @@ class EEStackController(CementBaseController):
"/var/www/22222/htdocs/vimbadmin/bin" "/var/www/22222/htdocs/vimbadmin/bin"
"/doctrine2-cli.php orm:schema-tool:" "/doctrine2-cli.php orm:schema-tool:"
"create") "create")
EEShellExec.cmd_exec("/var/www/22222/htdocs/vimbadmin/bin" EEShellExec.cmd_exec(self, "/var/www/22222/htdocs/vimbadmin"
"/doctrine2-cli.php orm:schema-tool:" "/bin/doctrine2-cli.php orm:schema-tool:"
"create") "create")
# Copy Dovecot and Postfix templates which are depednet on # Copy Dovecot and Postfix templates which are depednet on
@ -558,7 +567,7 @@ class EEStackController(CementBaseController):
# Extract RoundCubemail # Extract RoundCubemail
self.app.log.debug("Extracting file /tmp/roundcube.tar.gz " self.app.log.debug("Extracting file /tmp/roundcube.tar.gz "
"to location /tmp/ ") "to location /tmp/ ")
EEExtract.extract('/tmp/roundcube.tar.gz', '/tmp/') EEExtract.extract(self, '/tmp/roundcube.tar.gz', '/tmp/')
if not os.path.exists('/var/www/roundcubemail'): if not os.path.exists('/var/www/roundcubemail'):
self.app.log.debug("Creating new directory " self.app.log.debug("Creating new directory "
" /var/www/roundcubemail/") " /var/www/roundcubemail/")
@ -569,12 +578,14 @@ class EEStackController(CementBaseController):
# Configure roundcube database # Configure roundcube database
rc_passwd = ''.join(random.sample(string.ascii_letters, 8)) rc_passwd = ''.join(random.sample(string.ascii_letters, 8))
self.app.log.debug("Creating Database roundcubemail") self.app.log.debug("Creating Database roundcubemail")
EEMysql.execute("create database if not exists roundcubemail") EEMysql.execute(self, "create database if not exists "
" roundcubemail")
self.app.log.debug("Grant all privileges on roundcubemail") self.app.log.debug("Grant all privileges on roundcubemail")
EEMysql.execute("grant all privileges on roundcubemail.* to " EEMysql.execute(self, "grant all privileges"
" on roundcubemail.* to "
" roundcube@localhost IDENTIFIED BY " " roundcube@localhost IDENTIFIED BY "
"'{password}'".format(password=rc_passwd)) "'{password}'".format(password=rc_passwd))
EEShellExec.cmd_exec("mysql roundcubemail < /var/www/" EEShellExec.cmd_exec(self, "mysql roundcubemail < /var/www/"
"roundcubemail/htdocs/SQL/mysql" "roundcubemail/htdocs/SQL/mysql"
".initial.sql") ".initial.sql")
@ -582,21 +593,22 @@ class EEStackController(CementBaseController):
"config.inc.php.sample", "config.inc.php.sample",
"/var/www/roundcubemail/htdocs/config/" "/var/www/roundcubemail/htdocs/config/"
"config.inc.php") "config.inc.php")
EEShellExec.cmd_exec("sed -i \"s\'mysql://roundcube:pass@" EEShellExec.cmd_exec(self, "sed -i \"s\'mysql://roundcube:"
"localhost/roundcubemail\'mysql://" "pass@localhost/roundcubemail\'mysql://"
"roundcube:{password}@localhost/" "roundcube:{password}@localhost/"
"roundcubemail\'\" /var/www/roundcubemail" "roundcubemail\'\" /var/www/roundcubemail"
"/htdocs/config/config." "/htdocs/config/config."
"inc.php".format(password=rc_passwd)) "inc.php".format(password=rc_passwd))
# Sieve plugin configuration in roundcube # Sieve plugin configuration in roundcube
EEShellExec.cmd_exec("sed -i \"s:\$config\['plugins'\] = array" EEShellExec.cmd_exec(self, "sed -i \"s:\$config\['plugins'\] "
"(:\$config\['plugins'\] = array(\n " "= array(:\$config\['plugins'\] = "
"'sieverules',:\" /var/www/roundcubemail" "array(\n'sieverules',:\" /var/www"
"/roundcubemail/htdocs/config"
"/config.inc.php")
EEShellExec.cmd_exec(self, "echo \"\$config['sieverules_port']"
"=4190;\" >> /var/www/roundcubemail"
"/htdocs/config/config.inc.php") "/htdocs/config/config.inc.php")
EEShellExec.cmd_exec("echo \"\$config['sieverules_port'] = "
"4190;\" >> /var/www/roundcubemail/htdocs"
"/config/config.inc.php")
@expose() @expose()
def install(self): def install(self):
@ -697,7 +709,7 @@ class EEStackController(CementBaseController):
pkg.install(apt_packages) pkg.install(apt_packages)
if len(packages): if len(packages):
self.app.log.debug("Downloading all packages") self.app.log.debug("Downloading all packages")
EEDownload.download(packages) EEDownload.download(self, packages)
self.app.log.debug("Calling post_pref") self.app.log.debug("Calling post_pref")
self.post_pref(apt_packages, packages) self.post_pref(apt_packages, packages)
@ -751,9 +763,9 @@ class EEStackController(CementBaseController):
if len(apt_packages): if len(apt_packages):
self.app.log.debug("Removing apt_packages") self.app.log.debug("Removing apt_packages")
pkg.remove(apt_packages) pkg.remove(self, apt_packages)
if len(packages): if len(packages):
EEFileUtils.remove(packages) EEFileUtils.remove(self, packages)
@expose() @expose()
def purge(self): def purge(self):
@ -804,9 +816,9 @@ class EEStackController(CementBaseController):
] ]
if len(apt_packages): if len(apt_packages):
pkg.remove(apt_packages, purge=True) pkg.remove(self, apt_packages, purge=True)
if len(packages): if len(packages):
EEFileUtils.remove(packages) EEFileUtils.remove(self, packages)
def load(app): def load(app):

28
ee/cli/plugins/stack_services.py

@ -20,18 +20,25 @@ class EEStackStatusController(CementBaseController):
def start(self): def start(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service start")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service start")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service start")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
self.app.log.debug("postfix service start")
services = services + ['postfix'] services = services + ['postfix']
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service start")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service start")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
self.app.log.debug("nginx,php5-fpm,mysql,postfix services start")
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
EEService.start_service(self, service) EEService.start_service(self, service)
@ -40,19 +47,26 @@ class EEStackStatusController(CementBaseController):
def stop(self): def stop(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service stop")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service stop")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service stop")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
self.app.log.debug("postfix service stop")
services = services + ['postfix'] services = services + ['postfix']
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service stop")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service stop")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
self.app.log.debug("nginx,php5-fpm,mysql,postfix services stop")
for service in services: for service in services:
EEService.stop_service(self, service) EEService.stop_service(self, service)
@ -60,38 +74,52 @@ class EEStackStatusController(CementBaseController):
def restart(self): def restart(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service restart")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service restart")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service restart")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
self.app.log.debug("postfix service restart")
services = services + ['postfix'] services = services + ['postfix']
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service restart")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service restart")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
self.app.log.debug("nginx,php5-fpm,mysql,postfix services restart")
EEService.restart_service(self, service) EEService.restart_service(self, service)
@expose(help="get stack status") @expose(help="get stack status")
def status(self): def status(self):
services = [] services = []
if self.app.pargs.nginx: if self.app.pargs.nginx:
self.app.log.debug("nginx service status")
services = services + ['nginx'] services = services + ['nginx']
elif self.app.pargs.php: elif self.app.pargs.php:
self.app.log.debug("php5-fpm service status")
services = services + ['php5-fpm'] services = services + ['php5-fpm']
elif self.app.pargs.mysql: elif self.app.pargs.mysql:
self.app.log.debug("mysql service status")
services = services + ['mysql'] services = services + ['mysql']
elif self.app.pargs.postfix: elif self.app.pargs.postfix:
services = services + ['postfix'] services = services + ['postfix']
self.app.log.debug("postfix service status")
elif self.app.pargs.memcache: elif self.app.pargs.memcache:
self.app.log.debug("memcached service status")
services = services + ['memcached'] services = services + ['memcached']
elif self.app.pargs.dovecot: elif self.app.pargs.dovecot:
self.app.log.debug("dovecot service status")
services = services + ['dovecot'] services = services + ['dovecot']
else: else:
self.app.log.debug("nginx,php5-fpm,mysql,postfix services status")
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
if EEService.get_service_status(self, service): if EEService.get_service_status(self, service):

4
ee/core/aptget.py

@ -13,6 +13,7 @@ class EEAptGet:
def update(self): def update(self):
"""Similar to apt-get update""" """Similar to apt-get update"""
self.app.log.debug("Update cache")
self.cache.update(self.fprogress) self.cache.update(self.fprogress)
self.cache.open() self.cache.open()
@ -201,16 +202,19 @@ class EEAptGet:
# Check if packages available for remove/update. # Check if packages available for remove/update.
if self.cache.delete_count > 0: if self.cache.delete_count > 0:
self.app.log.debug('packages will be REMOVED ')
print("The following packages will be REMOVED:" print("The following packages will be REMOVED:"
"\n {pkg_name}" "\n {pkg_name}"
.format(pkg_name=my_selected_packages)) .format(pkg_name=my_selected_packages))
print("{pkg_remove_count} to remove." print("{pkg_remove_count} to remove."
.format(pkg_remove_count=self.cache.delete_count)) .format(pkg_remove_count=self.cache.delete_count))
self.app.log.debug('bytes disk space will be freed')
print("After this operation, {space} bytes disk spac" print("After this operation, {space} bytes disk spac"
"e will be freed.".format(space=self.cache.required_space)) "e will be freed.".format(space=self.cache.required_space))
try: try:
self.cache.commit(self.fprogress, self.iprogress) self.cache.commit(self.fprogress, self.iprogress)
except Exception as e: except Exception as e:
self.app.log.error('Sorry, package installation failed ')
print("Sorry, package installation failed [{err}]" print("Sorry, package installation failed [{err}]"
.format(err=str(e))) .format(err=str(e)))
return(False) return(False)

25
ee/core/download.py

@ -9,7 +9,7 @@ class EEDownload():
def __init__(): def __init__():
pass pass
def download(packages): def download(self, packages):
for package in packages: for package in packages:
url = package[0] url = package[0]
filename = package[1] filename = package[1]
@ -17,18 +17,25 @@ class EEDownload():
directory = os.path.dirname(filename) directory = os.path.dirname(filename)
if not os.path.exists(directory): if not os.path.exists(directory):
os.makedirs(directory) os.makedirs(directory)
print("Downloading "+os.path.basename(url)+" ...") self.app.log.info("Downloading "+os.path.basename(url)+" ...")
urllib.request.urlretrieve(url, filename) urllib.request.urlretrieve(url, filename)
print("Done") self.app.log.info("Done")
except urllib.error.URLError as e: except urllib.error.URLError as e:
print("Unable to donwload file, [{err}]" self.app.log.error("Error is :"
.format(err=str(e.reason))) + os.path.basename(url)+e.reason())
self.app.log.info("Unable to donwload file, [{err}]"
.format(err=str(e.reason)))
return False return False
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
print("Package download failed. [{err}]" self.app.log.error("Package download failed", e.reason())
.format(err=str(e.reason))) self.app.log.info("Package download failed. [{err}]"
.format(err=str(e.reason)))
return False return False
except urllib.error.ContentTooShortError as e: except urllib.error.ContentTooShortError as e:
print("Package download failed. The amount of the" self.app.log.error("Package download failed. The amount of the"
"downloaded data is less than the expected amount") " downloaded data is less than "
"the expected amount"+e.reason())
self.app.log.info("Package download failed. The amount of the"
"downloaded data is less than"
" the expected amount")
return False return False

5
ee/core/extract.py

@ -6,7 +6,7 @@ import os
class EEExtract(): class EEExtract():
"""Method to extract from tar.gz file""" """Method to extract from tar.gz file"""
def extract(file, path): def extract(self, file, path):
try: try:
tar = tarfile.open(file) tar = tarfile.open(file)
tar.extractall(path=path) tar.extractall(path=path)
@ -14,5 +14,6 @@ class EEExtract():
os.remove(file) os.remove(file)
return True return True
except tarfile.TarError as e: except tarfile.TarError as e:
print("Unable to extract file "+file) self.app.log.error('Unable to extract file', e.reason())
self.app.log.info("Unable to extract file "+file)
return False return False

17
ee/core/fileutils.py

@ -8,18 +8,23 @@ class EEFileUtils():
def __init__(): def __init__():
pass pass
def remove(filelist): def remove(self, filelist):
for file in filelist: for file in filelist:
if os.path.isfile(file): if os.path.isfile(file):
print("Removing "+os.path.basename(file)+" ...") self.app.log.debug('Removing file')
self.app.log.info("Removing "+os.path.basename(file)+" ...")
os.remove(file) os.remove(file)
print("Done") self.app.log.debug('file Removed')
self.app.log.info("Done")
if os.path.isdir(file): if os.path.isdir(file):
try: try:
self.app.log.debug('Removing file')
print("Removing "+os.path.basename(file)+" ...") print("Removing "+os.path.basename(file)+" ...")
shutil.rmtree(file) shutil.rmtree(file)
print("Done") self.app.log.info("Done")
except shutil.Error as e: except shutil.Error as e:
print("Unable to remove file, [{err}]" self.app.log.error('Unable to Remove file'
.format(err=str(e.reason))) + os.path.basename(file)+e.reason())
self.app.log.info("Unable to remove file, [{err}]"
.format(err=str(e.reason)))
return False return False

8
ee/core/mysql.py

@ -7,7 +7,7 @@ from os.path import expanduser
class EEMysql(): class EEMysql():
"""Method for MySQL connection""" """Method for MySQL connection"""
def execute(statement): def execute(self, statement):
config = configparser.RawConfigParser() config = configparser.RawConfigParser()
cnfpath = expanduser("~")+"/.my.cnf" cnfpath = expanduser("~")+"/.my.cnf"
if [cnfpath] == config.read(cnfpath): if [cnfpath] == config.read(cnfpath):
@ -28,13 +28,15 @@ class EEMysql():
user=user, passwd=passwd) user=user, passwd=passwd)
cur = conn.cursor() cur = conn.cursor()
except Exception as e: except Exception as e:
print("Unable to connect to database") self.app.log.error('Unable to connect to database', e.reason())
self.app.log.info("Unable to connect to database")
return False return False
try: try:
cur.execute(statement) cur.execute(statement)
except Exception as e: except Exception as e:
print("Error occured while executing "+statement) self.app.log.error('Error occured while executing', e.reason())
self.app.log.info("Error occured while executing "+statement)
cur.close() cur.close()
conn.close() conn.close()
return False return False

4
ee/core/services.py

@ -16,7 +16,7 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} start' retcode = subprocess.getstatusoutput('service {0} start'
.format(service_name)) .format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
print("Started : {0}".format(service_name)) self.app.log.info("Started : {0}".format(service_name))
else: else:
self.app.log.error(retcode[1]) self.app.log.error(retcode[1])
except OSError as e: except OSError as e:
@ -28,7 +28,7 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} stop' retcode = subprocess.getstatusoutput('service {0} stop'
.format(service_name)) .format(service_name))
if retcode[0] == 0: if retcode[0] == 0:
print("Stopped : {0}".format(service_name)) self.app.log.info("Stopped : {0}".format(service_name))
return True return True
else: else:
return False return False

6
ee/core/shellexec.py

@ -10,14 +10,14 @@ class EEShellExec():
def __init__(): def __init__():
pass pass
def cmd_exec(command): def cmd_exec(self, command):
try: try:
retcode = subprocess.getstatusoutput(command) retcode = subprocess.getstatusoutput(command)
if retcode[0] == 0: if retcode[0] == 0:
return True return True
else: else:
print(retcode[1]) self.app.log.info(retcode[1])
return False return False
except OSError as e: except OSError as e:
print(e) self.app.log.info(e)
return False return False

1
ee/core/variables.py

@ -25,6 +25,7 @@ class EEVariables():
ee_user = config['user']['name'] ee_user = config['user']['name']
ee_email = config['user']['email'] ee_email = config['user']['email']
except KeyError as e: except KeyError as e:
self.app.log.error('Unable to find GIT user name and Email', e)
print("Unable to find GIT user name and Email") print("Unable to find GIT user name and Email")
sys.exit(1) sys.exit(1)

Loading…
Cancel
Save