Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 2.2.0_m5_build…

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
usmlib
README.md
install.sh
installOnUbuntu.sh
killAllMysql.bat
mysql-service.groovy
mysql-service.properties
mysql.png
mysql_dump.groovy
mysql_install.groovy
mysql_query.groovy
mysql_runner.groovy
mysql_start.groovy
mysql_startDetection.groovy
mysql_stop.groovy
mysql_uninstall.groovy
run.sh
runOnUbuntu.sh
stop.sh
stopOnUbuntu.sh
uninstall.sh
uninstallOnUbuntu.sh

README.md

MySQL

Status: Tested
Description: MySQL
Maintainer: Cloudify
Maintainer email: cloudifysource@gigaspaces.com
Contributors: tamirko
Homepage: http://www.cloudifysource.org
License: Apache 2.0
Build: Cloudify 2.1.1 GA , Cloudify 2.2.0 M2 and Cloudify 2.2.0 M4
Linux* sudoer permissions: Mandatory
Windows* Admin permissions: Not required
Release Date: July 25th 2012

Tested on:

  • EC2:
    • CentOs 5 imageId "us-east-1/ami-76f0061f", hardwareId "m1.small", locationId "us-east-1"
    • Ubuntu 11.10: "us-east-1/ami-e1aa7388", hardwareId "m1.small", locationId "us-east-1"
    • Ubuntu 12.04: imageId "us-east-1/ami-82fa58eb", hardwareId "m1.small", locationId "us-east-1"
      .
  • OpenStack:
    • CentOs 5: imageId "1234" CentOS 5.6 64-bit, hardwareId "103" standard.large - 4 vCPU / 8 GB RAM / 240 GB HD , az-1.region-a.geo-1 .
  • Rackspace:

    • CentOs 6: imageId "118", hardwareId "4" (2GB server = 2G RAM 80 GB HD).

    We disable the requiretty flag in /etc/sudoers on the installed VMs, so that Cloudify will be able to invoke remote ssh commands as a sudoer. This feature will be a part of Cloudify in the near future. Until then, please use the Cloud Drivers Repository.

Synopsis

This folder contains a service recipe for MySQL.

Its default port is 3306, but it can be modified in the mysql-service.properties.

You can inherit and extend this recipe very easily, just by changing the mysql-service.properties file, without changing even one line of code in the recipe.

This is achieved thanks to the following :

1: A Start Detection Query

In most of our recipes, we use something like : ServiceUtils.isPortOccupied(port).
In this case, it is usually NOT enough, because the port just means that the DB is up, but we also need the schema to be ready.
So we added a startDetectionQuery property (to the properties file) in which you can insert an SQL query.
The service instance is alive only if the port is occupied AND the startDetectionQuery result is true.

2: Post Start Actions

In the properties file you can insert an array of postStart commands (as many commands as you want).
These post start commands will be invoked during the... postStart lifecycle event.
There are four types of postStart commands :
a) mysqladmin : for invoking any administrative command ( for example : creating a new DB )
b) mysql : for invoking any SQL statement: insert, update, grant permissions etc.
c) import : for importing a DB schema ( by providing a full URL of the zip file that contains the schema )
d) mysqldump : for creating a db dump (snapshot)

Examples :

   
   /* In this case, dbName is a property which is defined in mysql-service.properties    
      a) All the occurrences of MYSQLHOST in actionQuery, 
      b) will be replaced with the private IP address on which this service instance resides.   
   */ 
   [    
        "actionType" : "mysqladmin",   
        "actionQuery" : "create",  
        "actionUser"  : "root",  
        "actionDbName" : "${dbName}",  
        "debugMsg" : "Creating db - Name  : ${dbName} ... "  
    ]  
 
    /* In this case, dbUser and dbPassW are properties which are defined in mysql-service.properties   
       a) All the occurrences of MYSQLHOST in actionQuery, 
       b) will be replaced with the private IP address on which this service instance resides.   
    */  
    [   
        "actionType" : "mysql",           
        "actionQuery" : "\"CREATE USER '${dbUser}'@'localhost' IDENTIFIED BY '${dbPassW}';\"",  
        "actionUser"  : "root",  
        "actionDbName" : "${dbName}",  
        "debugMsg" : "Creating db user ${dbUser} at localhost, passw ${dbPassW} in ${dbName} db... "   
    ]  
   
   /* In this case:  
        a) dbName,currDBZip,currImportSql are properties which are defined in mysql-service.properties   
        b) currDBZip is the local name of the zip file ( after download )  
        c) currImportSql is the name of the sql file which is stored in currDBZip.   
        d) All the occurrences of REPLACE_WITH_DB_NAME in currImportSql, will be replaced with ${dbName}   
   */
   [   
        "actionType" : "import",   
        "importedZip" : "${currDBZip}",  
        "importedFile" : "${currImportSql}",  
        "importedFileUrl" : "http://dropbox/1/222/mysql.zip",  
        "actionUser"  : "root",  
        "actionDbName" : "${dbName}",  
        "debugMsg" : "Importing  to ${dbName} ..."  
    ]   
 
   /* In this case:  
        a) dbName is a property which is defined in mysql-service.properties.  
        b) If actionDbName is an empty string,  then --all-databases will be used. 
        c) actionArgs contain the flags that you want to use with this mysqldump command  
        d) Do NOT database flags, because they will be set according to the actionDbName.  
           i.e: Do NOT use the following  : --all-databases,-A,--databases  
        e) Do NOT -u flag flags, because it will be set according to the actionUser  
   */
   [   
        "actionType" : "mysqldump",   
        "actionArgs" : "--add-drop-database -c --lock-all-tables -F",  
        "actionUser"  : "root",  
        "actionDbName" : "${dbName}",  
        "dumpPrefix" : "myDumpFile_",  
        "debugMsg" : "Invoking mysqldump ..."   
    ]   

Custom Commands

mysqldump:

This custom command enables users to create a database snapshot (mysqldump).
Usage : invoke mysql mysqldump actionUser dumpPrefix [dbName]
Example: invoke mysql mysqldump root myPrefix_ myDbName

query:

This custom command enables users to invoke an SQL statement.
Usage : invoke mysql query actionUser dbName query
Examples:

  1. If you want to update the users table in myDbName with the following statement :
    update users set name='James' where uid=1
    then you need to run the following custom command :
    invoke mysql query root myDbName \\"update users set name=\\'James\\' where uid=1\\"

  2. If you want to insert a new user named Dan, into the users table in myDbName, and you need the following SQL statement:
    INSERT INTO users VALUES (17,'Dan','hisPassword','hisemail@his.com',0)
    then you need to run the following custom command :
    invoke mysql query root tamirDB \\"INSERT INTO users VALUES \\(17,\\'Dan\\',\\'hisPassword\\',\\'hisemail@his.com\\',0\\)\\"

Something went wrong with that request. Please try again.