o
    ȷe                     @   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)notifyexit_on_error)runself r   Y/var/www/ideatree/venv/lib/python3.10/site-packages/boto/pyami/installers/ubuntu/mysql.pyinstall-   s   
zMySQL.installNc           
      C   s  t jddd}d}td}|  | dkrHtd d}| ddkr>|d	k r>td	 |d
 }| ddkr>|d	k s*| d | d tj	
|d}tj	|s^| d|  d}| d|  tdd}|d |d|  |d |d|  |dtj	
|d  |  |r| d|  | d d S t }|d |dd}| d td d| }	| |	dkrtd	 | |	dksd S d S )Nr   data_dirz/mntFzmysqladmin pingr   
   zecho 'quit' | mysql -u root      z/etc/init.d/mysql stopzpkill -9 mysql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   	getStatustimesleepospathjoinexistsopenwriteclosestartr   read)
r
   r   r   fresh_installis_mysql_running_commandi
mysql_pathfpconfig_parsergrant_commandr   r   r   change_data_dir8   sJ   










zMySQL.change_data_dirc                 C   s   |    |   d S N)r   r,   r	   r   r   r   maing   s   z
MySQL.mainr-   )__name__
__module____qualname__r   r,   r.   r   r   r   r   r   +   s    
/r   )__doc__&boto.pyami.installers.ubuntu.installerr   r   r   
boto.utilsr   boto.compatr   r   ConfigSectionr   r   r   r   r   <module>   s   