Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117757620
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/pykolab/setup/setup_mysql.py b/pykolab/setup/setup_mysql.py
index d1f1fd9..377a3aa 100644
--- a/pykolab/setup/setup_mysql.py
+++ b/pykolab/setup/setup_mysql.py
@@ -1,234 +1,230 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
#
# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from glob import glob
from os.path import exists, join
from subprocess import call, Popen, PIPE
import os
import components
import pykolab
from pykolab import utils
from pykolab.constants import *
from pykolab.setup.services import *
from pykolab.translate import _
log = pykolab.getLogger('pykolab.setup')
conf = pykolab.getConf()
def __init__():
components.register('mysql', execute, description=description())
def cli_options():
mysql_group = conf.add_cli_parser_option_group(_("MySQL Options"))
mysql_group.add_option(
"--reset-mysql-config",
dest = "reset_mysql_config",
action = "store_true",
default = False,
help = _("Reset the MySQL configuration.")
)
def description():
return _("Setup MySQL.")
def execute(*args, **kw):
# Signal that interaction may occur. This will involve debconf and similar
# system-specific mechanisms if available.
start_interaction("kolab-conf/title-mysql")
try:
_execute(*args, **kw)
finally:
stop_interaction()
def _execute(*args, **kw):
mysql = is_debian() and 'mysql' or 'mysqld'
# Stop if MySQL is not actually installed.
if not have_mysql():
if conf.check_only:
utils.setup_status("mysql", _("not installed"))
else:
log.error(_("MySQL not installed."))
return
# Test MySQL daemon process availability.
if not conf.check_only and not exists('/var/run/mysqld/mysqld.sock'):
if not control_service(mysql, 'start'):
log.error(_("Could not start the MySQL database service."))
# Ensure that the service is started at boot.
if not conf.check_only and not configure_service(mysql, True):
log.error(_("Could not configure to start on boot, the " + \
"MySQL database service."))
# Defaults files exist in the distributions for various tasks, but such a
# file is used to avoid providing a password on the command line.
defaults_file = get_mysql_defaults()
if need_mysql_root():
# If a root user can be found without any credentials being supplied, the
# MySQL installation probably needs a root password setting.
if have_mysql_user(None, 'root'):
if conf.check_only:
utils.setup_status("mysql", _("needs setup"))
return
mysql_root_password = ask_question("kolab-conf/mysql-root-new",
- _(create_root_password_message),
+ _("""
+ Please supply a root password for MySQL. This password
+ will be the administrative user for this MySQL server,
+ and it should be kept a secret. After this setup process
+ has completed, Kolab is going to discard and forget
+ about this password, but you will need it for
+ administrative tasks in MySQL.
+ """),
_("MySQL root password"),
default=utils.generate_password(),
password=True,
confirm=True
)
p1 = Popen(['echo', "update mysql.user set Password=PASSWORD('%s') where User='root'" %
mysql_root_password.replace("'", "''")], stdout=PIPE)
p2 = Popen(['mysql'], stdin=p1.stdout)
p2.communicate()
call(['mysql', '-e', 'flush privileges'])
# For an installation where the root password is still needed, it is
# obtained here.
else:
mysql_root_password = ask_question("kolab-conf/mysql-root-existing",
- _(existing_root_password_message),
+ _("""
+ Please supply the root password for MySQL, so we can set
+ up user accounts for other components that use MySQL.
+ """),
_("MySQL root password"),
password=True
)
# Write the defaults file in order to be able to connect in future.
data = mysql_defaults % mysql_root_password
fp = open(defaults_file, 'w')
os.chmod(defaults_file, 0600)
fp.write(data)
fp.close()
# Find the schema file for the database.
schema_file = find_schema_file()
if schema_file is not None:
# Test for the database.
if not have_mysql_database(defaults_file, 'kolab'):
if conf.check_only:
utils.setup_status("mysql", _("needs setup"))
return
call(['mysql', '--defaults-file=%s' % defaults_file, '-e', 'create database kolab'])
# Populate the schema.
p1 = Popen(['cat', schema_file], stdout=PIPE)
p2 = Popen(['mysql', '--defaults-file=%s' % defaults_file, 'kolab'], stdin=p1.stdout)
p2.communicate()
elif not conf.check_only:
log.info(_("A database called %s already exists. Not creating another one.") % 'kolab')
else:
log.error(_("Could not find the MySQL Kolab schema file"))
# Test for a MySQL user. Reset the user and configuration if explicitly
# requested or if the configuration has not been modified.
wap_url_needs_setting = conf.get('kolab_wap', 'sql_uri') == 'mysql://user:pass@localhost/database'
if have_mysql_user(defaults_file, 'kolab') and not conf.reset_mysql_config and not wap_url_needs_setting:
if not conf.check_only:
print >> sys.stderr, _("Kolab database account already exists and will not be configured.")
log.info(_("A user called %s already exists. Not creating another one.") % 'kolab')
else:
if conf.check_only:
utils.setup_status("mysql", _("needs setup"))
return
mysql_kolab_password = ask_question("kolab-conf/mysql-kolab",
_("""
Please supply a password for the MySQL user 'kolab'.
This password will be used by Kolab services, such as
the Web Administration Panel.
"""),
_("MySQL kolab password"),
default=utils.generate_password(),
password=True,
confirm=True
)
if not have_mysql_user(defaults_file, 'kolab'):
p1 = Popen(['echo', "grant all privileges on kolab.* to 'kolab'@'localhost' identified by '%s'" %
mysql_kolab_password.replace("'", "''")], stdout=PIPE)
p2 = Popen(['mysql', '--defaults-file=%s' % defaults_file], stdin=p1.stdout)
p2.communicate()
if wap_url_needs_setting or conf.reset_mysql_config:
conf.command_set('kolab_wap', 'sql_uri', 'mysql://kolab:%s@localhost/kolab' % mysql_kolab_password)
# If nothing needed updating, assume that the setup was done.
if conf.check_only:
utils.setup_status("mysql", _("setup done"))
def find_schema_file():
for webadmin_dir in glob('/usr/share/doc/kolab*'):
for root, directories, filenames in os.walk(webadmin_dir):
for filename in filenames:
if filename.startswith('kolab_wap') and filename.endswith('.sql'):
return join(root,filename)
return None
# Data used by the code above.
-existing_root_password_message = """\
-Please supply the root password for MySQL, so we can set
-up user accounts for other components that use MySQL.
-"""
-
-create_root_password_message = """\
-Please supply a root password for MySQL. This password
-will be the administrative user for this MySQL server,
-and it should be kept a secret. After this setup process
-has completed, Kolab is going to discard and forget
-about this password, but you will need it for
-administrative tasks in MySQL.
-"""
-
mysql_defaults = """\
[mysql]
user=root
password='%s'
"""
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 4, 9:20 AM (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823436
Default Alt Text
(9 KB)
Attached To
Mode
rP pykolab
Attached
Detach File
Event Timeline