U
    W¨+dù  ã                   @   sX   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	Z	dZ
G dd„ deƒZdS )	aR  
This installer will install mysql-server on an Ubuntu machine.
In addition to the normal installation done by apt-get, it will
also configure the new MySQL server to store it's data files in
a different location.  By default, this is /mnt but that can be
configured in the [MySQL] section of the boto config file passed
to the instance.
é    )Ú	InstallerN)ÚShellCommand)ÚConfigParserz‚
[MySQL]
root_password = <will be used as MySQL root password, default none>
data_dir = <new data dir for MySQL, default is /mnt>
c                   @   s&   e Zd Zdd„ Zddd„Zdd„ ZdS )	ÚMySQLc                 C   s   |   d¡ | j dddd d S )Nzapt-get updatezapt-get -y install mysql-serverT)ÚnotifyZexit_on_error)Úrun©Úself© r
   úF/tmp/pip-unpacked-wheel-dlxw5sjy/boto/pyami/installers/ubuntu/mysql.pyÚinstall-   s    
zMySQL.installNc           
      C   sŠ  t j ddd¡}d}tdƒ}| ¡  | ¡ dkr|t d¡ d}|  d¡dkrh|d	k rht d	¡ |d
 }q>|  d¡ |  d¡ tj	 
|d¡}tj	 |¡s¨|  d| ¡ d}|  d| ¡ tddƒ}| d¡ | d| ¡ | d¡ | d| ¡ | dtj	 
|d¡ ¡ | ¡  |r0|  d| ¡ |  d¡ nVtƒ }| d¡ | dd¡}|  d¡ t d¡ d| }	|  |	¡dkr†t d	¡ qhd S )Nr   Údata_dirz/mntFzmysqladmin pingr   é
   zecho 'quit' | mysql -u rooté   é   z/etc/init.d/mysql stopzpkill -9 mysqlZmysqlzmkdir %sTzchown -R mysql:mysql %sz/etc/mysql/conf.d/use_mnt.cnfÚwz# created by pyami
z# use the %s volume for data
z	[mysqld]
zdatadir = %s
zlog_bin = %s
zmysql-bin.logzcp -pr /var/lib/mysql/* %s/z/etc/mysql/debian.cnfÚclientÚpasswordzrecho "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '%s' WITH GRANT OPTION;" | mysql)ÚbotoÚconfigÚgetr   r   Z	getStatusÚtimeÚsleepÚosÚpathÚjoinÚexistsÚopenÚwriteÚcloseÚstartr   Úread)
r	   r   r   Zfresh_installZis_mysql_running_commandÚiZ
mysql_pathÚfpZconfig_parserZgrant_commandr
   r
   r   Úchange_data_dir8   sF    










zMySQL.change_data_dirc                 C   s   |   ¡  |  ¡  d S )N)r   r$   r   r
   r
   r   Úmaing   s    z
MySQL.main)N)Ú__name__Ú
__module__Ú__qualname__r   r$   r%   r
   r
   r
   r   r   +   s   
/r   )Ú__doc__Z&boto.pyami.installers.ubuntu.installerr   r   r   Z
boto.utilsr   Zboto.compatr   r   ZConfigSectionr   r
   r
   r
   r   Ú<module>   s   