Skip to content

Commit 367d6b7

Browse files
author
gau1991
committed
Merge branch 'python'
2 parents a18b7b5 + 4746912 commit 367d6b7

File tree

8 files changed

+74
-22
lines changed

8 files changed

+74
-22
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ notifications:
33
webhooks:
44
urls:
55
- https://webhooks.gitter.im/e/bd77a26eab56de803949
6+
- https://webhooks.gitter.im/e/e3e2feb8384c77bf1a8a
67
on_success: always # options: [always|never|change] default: always
78
on_failure: always # options: [always|never|change] default: always
89
on_start: false # default: false

config/bash_completion.d/ee_auto.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ _ee_complete()
1111
# SETUP THE BASE LEVEL (everything after "ee")
1212
if [ $COMP_CWORD -eq 1 ]; then
1313
COMPREPLY=( $(compgen \
14-
-W "stack site debug clean secure" \
14+
-W "stack site debug clean secure import-slow-log" \
1515
-- $cur) )
1616

1717

ee/cli/plugins/site.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ def default(self):
886886
'DB_PASSWORD')
887887
.split(',')[1]
888888
.split(')')[0].strip())
889+
data['ee_db_host'] = (EEFileUtils.grep(self, config_file,
890+
'DB_HOST')
891+
.split(',')[1]
892+
.split(')')[0].strip())
889893

890894
# Setup WordPress if old sites are html/php/mysql sites
891895
if data['wp'] and oldsitetype in ['html', 'php', 'mysql']:

ee/cli/plugins/stack.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import pwd
2626
import grp
27+
import codecs
2728
from ee.cli.plugins.stack_services import EEStackStatusController
2829
from ee.core.logging import Log
2930

@@ -93,14 +94,24 @@ def pre_pref(self, apt_packages):
9394
keyserver="keyserver.ubuntu.com")
9495
chars = ''.join(random.sample(string.ascii_letters, 8))
9596
Log.debug(self, "Pre-seeding MySQL")
97+
Log.debug(self, "echo \"percona-server-server-5.6 "
98+
"percona-server-server/root_password "
99+
"password \" | "
100+
"debconf-set-selections")
96101
EEShellExec.cmd_exec(self, "echo \"percona-server-server-5.6 "
97102
"percona-server-server/root_password "
98103
"password {chars}\" | "
99-
"debconf-set-selections".format(chars=chars))
104+
"debconf-set-selections".format(chars=chars),
105+
log=False)
106+
Log.debug(self, "echo \"percona-server-server-5.6 "
107+
"percona-server-server/root_password_again "
108+
"password \" | "
109+
"debconf-set-selections")
100110
EEShellExec.cmd_exec(self, "echo \"percona-server-server-5.6 "
101111
"percona-server-server/root_password_again "
102112
"password {chars}\" | "
103-
"debconf-set-selections".format(chars=chars))
113+
"debconf-set-selections".format(chars=chars),
114+
log=False)
104115
mysql_config = """
105116
[client]
106117
user = root
@@ -366,7 +377,6 @@ def post_pref(self, apt_packages, packages):
366377
EEService.reload_service(self, 'nginx')
367378
self.msg = (self.msg + ["HTTP Auth User Name: easyengine"]
368379
+ ["HTTP Auth Password : {0}".format(passwd)])
369-
370380
if set(EEVariables.ee_php).issubset(set(apt_packages)):
371381
# Create log directories
372382
if not os.path.exists('/var/log/php5/'):
@@ -390,20 +400,24 @@ def post_pref(self, apt_packages, packages):
390400

391401
# Prase /etc/php5/fpm/php-fpm.conf
392402
config = configparser.ConfigParser()
393-
config.read('/etc/php5/fpm/php-fpm.conf')
403+
Log.debug(self, "configuring php file"
404+
"/etc/php5/fpm/php-fpm.conf")
405+
config.read_file(codecs.open("/etc/php5/fpm/php-fpm.conf",
406+
"r", "utf8"))
394407
config['global']['error_log'] = '/var/log/php5/fpm.log'
395408
config.remove_option('global', 'include')
396409
config['global']['log_level'] = 'notice'
397410
config['global']['include'] = '/etc/php5/fpm/pool.d/*.conf'
398-
with open('/etc/php5/fpm/php-fpm.conf',
399-
encoding='utf-8', mode='w') as configfile:
411+
with codecs.open('/etc/php5/fpm/php-fpm.conf',
412+
encoding='utf-8', mode='w') as configfile:
400413
Log.debug(self, "writting php5 configuration into "
401414
"/etc/php5/fpm/php-fpm.conf")
402415
config.write(configfile)
403416

404417
# Parse /etc/php5/fpm/pool.d/www.conf
405418
config = configparser.ConfigParser()
406-
config.read('/etc/php5/fpm/pool.d/www.conf')
419+
config.read_file(codecs.open('/etc/php5/fpm/pool.d/www.conf',
420+
"r", "utf8"))
407421
config['www']['ping.path'] = '/ping'
408422
config['www']['pm.status_path'] = '/status'
409423
config['www']['pm.max_requests'] = '500'
@@ -414,8 +428,8 @@ def post_pref(self, apt_packages, packages):
414428
config['www']['request_terminate_timeout'] = '300'
415429
config['www']['pm'] = 'ondemand'
416430
config['www']['listen'] = '127.0.0.1:9000'
417-
with open('/etc/php5/fpm/pool.d/www.conf',
418-
encoding='utf-8', mode='w') as configfile:
431+
with codecs.open('/etc/php5/fpm/pool.d/www.conf',
432+
encoding='utf-8', mode='w') as configfile:
419433
Log.debug(self, "writting PHP5 configuration into "
420434
"/etc/php5/fpm/pool.d/www.conf")
421435
config.write(configfile)
@@ -628,7 +642,7 @@ def post_pref(self, apt_packages, packages):
628642
Log.debug(self, "Setting Privileges to dovecot ")
629643
# EEShellExec.cmd_exec(self, "chown -R vmail:vmail /var/lib"
630644
# "/dovecot")
631-
EEFileUtils.chown(self, "/var/lig/dovecot", 'vmail', 'vmail',
645+
EEFileUtils.chown(self, "/var/lib/dovecot", 'vmail', 'vmail',
632646
recursive=True)
633647
EEShellExec.cmd_exec(self, "sievec /var/lib/dovecot/sieve/"
634648
"default.sieve")
@@ -809,11 +823,14 @@ def post_pref(self, apt_packages, packages):
809823
EEMysql.execute(self, 'grant select on *.* to \'anemometer\''
810824
'@\'{0}\''.format(self.app.config.get('mysql',
811825
'grant-host')))
826+
Log.debug(self, "grant all on slow-query-log.*"
827+
" to anemometer@root_user IDENTIFIED BY password ")
812828
EEMysql.execute(self, 'grant all on slow_query_log.* to'
813829
'\'anemometer\'@\'{0}\' IDENTIFIED'
814830
' BY \'{1}\''.format(self.app.config.get(
815831
'mysql', 'grant-host'),
816-
chars))
832+
chars),
833+
errormsg="cannot grant privillages", log=False)
817834

818835
# Custom Anemometer configuration
819836
Log.debug(self, "configration Anemometer")
@@ -870,11 +887,14 @@ def post_pref(self, apt_packages, packages):
870887
Log.debug(self, "Creating vimbadmin database if not exist")
871888
EEMysql.execute(self, "create database if not exists"
872889
" vimbadmin")
873-
Log.debug(self, "Granting all privileges on vimbadmin ")
890+
Log.debug(self, "Granting all privileges on vimbadmin.* to "
891+
"vimbadmin@root IDENTIFIED BY password ")
874892
EEMysql.execute(self, "grant all privileges on vimbadmin.* to"
875893
" vimbadmin@{0} IDENTIFIED BY"
876894
" '{1}'".format(self.app.config.get('mysql',
877-
'grant-host'), vm_passwd))
895+
'grant-host'), vm_passwd),
896+
errormsg="Cannot grant "
897+
"user privileges", log=False)
878898
vm_salt = (''.join(random.sample(string.ascii_letters +
879899
string.ascii_letters, 64)))
880900

ee/core/fileutils.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def create_symlink(self, paths, errormsg=''):
4242
dst = paths[1]
4343
if not os.path.islink(dst):
4444
try:
45+
Log.debug(self, "Creating Symbolic link, Source:{0}, Dest:{1}"
46+
.format(src, dst))
4547
os.symlink(src, dst)
4648
except Exception as e:
4749
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
@@ -54,6 +56,7 @@ def remove_symlink(self, filepath):
5456
Removes symbolic link for the path provided with filepath
5557
"""
5658
try:
59+
Log.debug(self, "Removing symbolic link: {0}".format(filepath))
5760
os.unlink(filepath)
5861
except Exception as e:
5962
Log.debug(self, "{0}".format(e))
@@ -66,6 +69,8 @@ def copyfile(self, src, dest):
6669
dest : destination path
6770
"""
6871
try:
72+
Log.debug(self, "Copying file, Source:{0}, Dest:{1}"
73+
.format(src, dest))
6974
shutil.copy2(src, dest)
7075
except shutil.Error as e:
7176
Log.debug(self, "{0}".format(e))
@@ -84,6 +89,9 @@ def searchreplace(self, fnm, sstr, rstr):
8489
rstr: replace string
8590
"""
8691
try:
92+
Log.debug(self, "Doning search and replace, File:{0},"
93+
"Source string:{1}, Dest String:{2}"
94+
.format(fnm, sstr, rstr))
8795
for line in fileinput.input(fnm, inplace=True):
8896
print(line.replace(sstr, rstr), end='')
8997
fileinput.close()
@@ -112,6 +120,8 @@ def chdir(self, path):
112120
Path : path for destination directory
113121
"""
114122
try:
123+
Log.debug(self, "Changing directory to {0}"
124+
.format(path))
115125
os.chdir(path)
116126
except OSError as e:
117127
Log.debug(self, "{err}".format(err=e.strerror))
@@ -129,6 +139,10 @@ def chown(self, path, user, group, recursive=False):
129139
userid = pwd.getpwnam(user)[2]
130140
groupid = pwd.getpwnam(user)[3]
131141
try:
142+
Log.debug(self, "Changing ownership of {0}, Userid:{1},Groupid:{2}"
143+
.format(path, userid, groupid))
144+
# Change inside files/directory permissions only if recursive flag
145+
# is set
132146
if recursive:
133147
for root, dirs, files in os.walk(path):
134148
for d in dirs:
@@ -137,8 +151,7 @@ def chown(self, path, user, group, recursive=False):
137151
for f in files:
138152
os.chown(os.path.join(root, f), userid,
139153
groupid)
140-
else:
141-
os.chown(path, userid, groupid)
154+
os.chown(path, userid, groupid)
142155
except shutil.Error as e:
143156
Log.debug(self, "{0}".format(e))
144157
Log.error(self, "Unable to change owner : {0}".format(path))
@@ -154,6 +167,8 @@ def chmod(self, path, perm, recursive=False):
154167
recursive: change permission recursively for all files
155168
"""
156169
try:
170+
Log.debug(self, "Changing permission of {0}, Perm:{1}"
171+
.format(path, perm))
157172
if recursive:
158173
for root, dirs, files in os.walk(path):
159174
for d in dirs:
@@ -173,6 +188,8 @@ def mkdir(self, path):
173188
Similar to `mkdir -p`
174189
"""
175190
try:
191+
Log.debug(self, "Creating directories: {0}"
192+
.format(path))
176193
os.makedirs(path)
177194
except OSError as e:
178195
Log.debug(self, "{0}".format(e.strerror))
@@ -196,6 +213,8 @@ def grep(self, fnm, sstr):
196213
Searches for string in file and returns the matched line.
197214
"""
198215
try:
216+
Log.debug(self, "Finding string {0} to file {1}"
217+
.format(sstr, fnm))
199218
for line in open(fnm, encoding='utf-8'):
200219
if sstr in line:
201220
return line
@@ -208,6 +227,7 @@ def rm(self, path):
208227
"""
209228
Remove files
210229
"""
230+
Log.debug(self, "Removing {0}".format(path))
211231
if EEFileUtils.isexist(self, path):
212232
try:
213233
if os.path.isdir(path):

ee/core/shellexec.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""EasyEngine shell executaion functions."""
2-
from subprocess import Popen
32
from ee.core.logging import Log
43
import os
54
import sys
@@ -16,11 +15,19 @@ def cmd_exec(self, command, errormsg='', log=True):
1615
try:
1716
if log:
1817
Log.debug(self, "Running command: {0}".format(command))
19-
retcode = subprocess.getstatusoutput(command)
20-
if retcode[0] == 0:
18+
with subprocess.Popen([command], stdout=subprocess.PIPE,
19+
stderr=subprocess.PIPE, shell=True) as proc:
20+
(cmd_stdout_bytes, cmd_stderr_bytes) = proc.communicate()
21+
(cmd_stdout, cmd_stderr) = (cmd_stdout_bytes.decode('utf-8',
22+
"replace"),
23+
cmd_stderr_bytes.decode('utf-8',
24+
"replace"))
25+
26+
if proc.returncode == 0:
2127
return True
2228
else:
23-
Log.debug(self, retcode[1])
29+
Log.debug(self, "Command Output: {0}, Command Error: {1}"
30+
.format(cmd_stdout, cmd_stderr))
2431
return False
2532
except OSError as e:
2633
if errormsg:

install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,6 @@ else
319319
fi
320320
else
321321
ee_lib_echo_fail "You allready have EasyEngine $new_ee_version" | tee -ai $EE_INSTALL_LOG
322+
exit 1
322323
fi
323-
exit 1
324324
fi

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@
104104
source /etc/bash_completion.d/ee_auto.rc
105105
\033[94m
106106
EasyEngine (ee) installed successfully
107-
EasyEngine (ee) help: https://rtcamp.com/easyengine/docs/
107+
EasyEngine (ee) help: http://docs.rtcamp.com/easyengine/
108108
\033[0m
109109
""")

0 commit comments

Comments
 (0)