Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tamir added MySQL

  • Loading branch information...
commit f61a4392445339f3af232574fe26b3d8757c9d8c 1 parent 0a61179
@tamirko tamirko authored
View
131 services/mysql/README.md
@@ -0,0 +1,131 @@
+# tomcat
+
+**Status**: Tested
+**Description**: MySQL
+**Maintainer**: Cloudify
+**Maintainer email**: cloudifysource@gigaspaces.com
+**Contributors**: [tamirko](https://github.com/tamirko)
+**Homepage**: [http://www.cloudifysource.org](http://www.cloudifysource.org)
+**License**: Apache 2.0
+**Build**: [2.1.1 GA](http://repository.cloudifysource.org/org/cloudifysource/2.1.1/gigaspaces-cloudify-2.1.1-ga-b1400.zip)
+**Linux* sudoer permissions**: Mandatory
+**Windows* Admin permissions**: Not required
+**Release Date**: July 25th 2012
+
+
+Tested on:
+--------
+
+* <strong>EC2</strong>: Ubuntu and CentOs
+* <strong>OpenStack</strong>: CentOs
+* <strong>Rackspace</strong>: CentOs
+
+
+
+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 I 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)
+
+ActionType can be one of the four following: mysqladmin,mysql,mysqldump or import
+ Examples :
+
+ // In this case, dbName is a property which is defined in this properties file
+ // All the occurrences of MYSQLHOST in actionQuery, 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 this properties file
+ // All the occurrences of MYSQLHOST in actionQuery, 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:
+ // dbName,currDBZip,currImportSql are properties which are defined in this properties file
+ // currDBZip is the local name of the zip file ( after download )
+ // currImportSql is the name of the sql file which is stored in currDBZip.
+ / 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:
+ // dbName is a property which is defined in this properties file.
+ // if actionDbName is an empty string, then --all-databases will be used
+ // actionArgs contain the flags that you want to use with this mysqldump command
+ // Do NOT database flags, because they will be set according to the actionDbName.
+ // So do NOT use the following : --all-databases,-A,--databases
+ // 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 : <strong>invoke mysql mysqldump actionUser dumpPrefix [dbName]</strong>
+Example: <strong>invoke mysql mysqldump root myPrefix_ myDbName</strong>
+
+#query - This custom command enables users to invoke an SQL statement.
+
+Usage : <strong>invoke mysql query actionUser dbName query</strong>
+
+Examples
+
+1. If you want to update the users table in myDbName with the following statement :
+<strong>update users set name='James' where uid=1</strong>
+ - then you need to run the following custom command :
+<strong>invoke mysql query root myDbName \\"update users set name=\\'James\\' where uid=1\\"</strong>
+
+2. If you want to insert a new user named Dan, into the users table in myDbName, and you need the following SQL statement:
+<strong>INSERT INTO users VALUES (17,'Dan','hisPassword','hisemail@his.com',0)</strong>
+ - then you need to run the following custom command :
+<strong>invoke mysql query root tamirDB \\"INSERT INTO users VALUES \\(17,\\'Dan\\',\\'hisPassword\\',\\'hisemail@his.com\\',0\\)\\"</strong>
+
View
75 services/mysql/install.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+function killMySqlProcess {
+ ps -ef | grep -iE "mysql" | grep -ivE "gigaspaces|GSC|GSA|grep"
+ if [ $? -eq 0 ] ; then
+ ps -ef | grep -iE "mysql" | grep -ivE "gigaspaces|GSC|GSA|grep" | awk '{print $2}' | xargs sudo kill -9
+ fi
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+# The existence of the usingYum file in the ext folder will later serve as a flag that "we" are on Red Hat or CentOS or Fedora or Amazon
+echo "Using yum. Updating yum on one of the following : Red Hat, CentOS, Fedora, Amazon. " > usingYum
+sudo yum -y -q update || error_exit $? "Failed on: sudo yum -y -q update"
+
+echo "#1 Killing old mysql process if exists..."
+killMySqlProcess
+
+echo "Removing previous mysql installation if exists..."
+sudo yum -y -q remove mysql mysql-server
+
+# The following two statements are used since in some cases, there are leftovers after uninstall
+echo "Removing old stuff if exists..."
+sudo rm -rf /usr/lib/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/lib/mysql*"
+sudo rm -rf /var/lib/mysql* || error_exit $? "Failed on: sudo rm -rf /var/lib/mysql*"
+sudo rm -rf /usr/share/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/sharemysql*"
+sudo rm -rf /usr/bin/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/bin/mysql*"
+sudo rm -rf /var/run/mysql* || error_exit $? "Failed on: sudo rm -rf /var/run/mysql*"
+sudo rm -rf /var/bin/mysql* || error_exit $? "Failed on: sudo rm -rf /var/bin/mysql*"
+sudo rm -rf /etc/mysql* || error_exit $? "Failed on: sudo rm -rf /etc/mysql*"
+sudo rm -rf /etc/rc.d/init.d/mysql* || error_exit $? "Failed on: sudo rm -rf /etc/rc.d/init.d/mysql*"
+sudo rm -rf /usr/libexec/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/libexec/mysqld*"
+sudo rm -rf /etc/my.cnf || error_exit $? "Failed on: sudo rm -rf /etc/my.cnf"
+sudo rm -rf /var/log/mysql* || error_exit $? "Failed on: sudo rm -rf /var/log/mysql*"
+#sudo rm -f /home/`whoami`/{.,}*mysql* || error_exit $? "Failed on: sudo rm -f /home/`whoami`/{.,}*mysql*"
+
+echo "Using yum. Installing mysql on one of the following : Red Hat, CentOS, Fedora, Amazon"
+sudo yum install -y -q mysql mysql-server || error_exit $? "Failed on: sudo yum install -y -q mysql mysql-server "
+echo "Reinstalling mysql-libs ..."
+sudo yum reinstall -y -q mysql-libs || error_exit $? "Failed on: sudo yum install -y -q mysql mysql-server "
+
+echo "Killing old mysql process if exists b4 ending the installation..."
+killMySqlProcess
+
+
+myCnfPath=`sudo find / -name "my.cnf"`
+if [ -f "${myCnfPath}" ] ; then
+ allZeroes="0.0.0.0"
+ bindcount=`grep -c "bind-address" $myCnfPath`
+ if [ $bindcount -eq 0 ] ; then
+ bindStr="bind-address=${allZeroes}"
+ mysqldStr="\[mysqld\]"
+ jointStr="${mysqldStr}\n${bindStr}"
+ echo "Adding ${bindStr} $myCnfPath ... "
+ sudo sed -i -e "s/$mysqldStr/$jointStr/g" $myCnfPath
+ else
+ orig127="127.0.0.1"
+ echo "Replacing $orig127 with $allZeroes in $myCnfPath ... "
+ sudo sed -i -e "s/$orig127/$allZeroes/g" $myCnfPath
+ fi
+fi
+
+echo "End of $0"
+
+
View
72 services/mysql/installOnUbuntu.sh
@@ -0,0 +1,72 @@
+#!/bin/bash -x
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+function killMySqlProcess {
+ sudo service mysql stop
+ ps -ef | grep -iE "mysqld" | grep -ivE "gigaspaces|GSC|GSA|grep"
+ if [ $? -eq 0 ] ; then
+ ps -ef | grep -iE "mysqld" | grep -ivE "gigaspaces|GSC|GSA|grep" | awk '{print $2}' | xargs sudo kill -9
+ fi
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+if sudo grep -q -E '[^!]requiretty' /etc/sudoers; then
+ echo "Defaults:`whoami` !requiretty" | sudo tee /etc/sudoers.d/`whoami` >/dev/null
+ sudo chmod 0440 /etc/sudoers.d/`whoami`
+fi
+
+# The existence of the usingAptGet file in the ext folder will later serve as a flag that "we" are on Ubuntu or Debian or Mint
+echo "Using apt-get. Updating apt-get on one of the following : Ubuntu, Debian, Mint" > usingAptGet
+sudo apt-get -y -q update || error_exit $? "Failed on: sudo apt-get -y update"
+
+echo "#1 Killing old mysql process if exists..."
+killMySqlProcess
+
+# Removing previous mysql installation if exists
+echo "Purging previous mysql installation if exists..."
+sudo apt-get -y -q purge mysql-client* mysql-server* mysql-common*
+
+# The following two statements are used since in some cases, there are leftovers after uninstall
+echo "Removing old stuff if exists..."
+sudo rm -rf /etc/mysql || error_exit $? "Failed on: sudo rm -rf /etc/mysql"
+
+
+echo "Using apt-get. Updating apt-get on one of the following : Ubuntu, Debian, Mint"
+sudo DEBIAN_FRONTEND='noninteractive' apt-get -o Dpkg::Options::='--force-confnew' -q -y install mysql-server-core-5.1 mysql-server-5.1 mysql-client-core-5.1 mysql-client-5.1 mysql-common || error_exit $? "Failed on: sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q mysql-server ... "
+
+echo "Killing old mysql process if exists b4 ending the installation..."
+killMySqlProcess
+
+myCnfPath=`sudo find / -name "my.cnf"`
+if [ -f "${myCnfPath}" ] ; then
+ allZeroes="0.0.0.0"
+ bindcount=`grep -c "bind-address" $myCnfPath`
+ if [ $bindcount -eq 0 ] ; then
+ bindStr="bind-address=${allZeroes}"
+ mysqldStr="\[mysqld\]"
+ jointStr="${mysqldStr}\n${bindStr}"
+ echo "Adding ${bindStr} $myCnfPath ... "
+ sudo sed -i -e "s/$mysqldStr/$jointStr/g" $myCnfPath
+ else
+ orig127="127.0.0.1"
+ echo "Replacing $orig127 with $allZeroes in $myCnfPath ... "
+ sudo sed -i -e "s/$orig127/$allZeroes/g" $myCnfPath
+ fi
+fi
+
+echo "End of $0"
+
+
+
+#sudo service mysql stop
+#sudo service mysql start
View
1  services/mysql/killAllMysql.bat
@@ -0,0 +1 @@
+taskkill /t /im mysql* /f
View
156 services/mysql/mysql-service.groovy
@@ -0,0 +1,156 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import groovy.sql.*
+import com.mysql.jdbc.Driver
+
+service {
+
+ name "mysql"
+
+ icon "mysql.jpg"
+ type "DATABASE"
+
+ lifecycle{
+
+ install "mysql_install.groovy"
+
+ start "mysql_start.groovy"
+
+ startDetectionTimeoutSecs 900
+ startDetection "mysql_startDetection.groovy"
+
+ stopDetection {
+ !ServiceUtils.isPortOccupied(jdbcPort)
+ }
+
+ preStop ([
+ "Win.*":"killAllMysql.bat",
+ "Linux.*":"mysql_stop.groovy"
+ ])
+ shutdown ([
+ "Linux.*":"mysql_uninstall.groovy"
+ ])
+
+
+ locator {
+ //hack to avoid monitoring started processes by cloudify
+ //return [] as LinkedList
+
+ def myPids = ServiceUtils.ProcessUtils.getPidsWithQuery("State.Name.re=mysql.*\\.exe|mysqld")
+ println ":mysql-service.groovy: current PIDs: ${myPids}"
+ return myPids
+ }
+ }
+
+ customCommands ([
+ /*
+ 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
+ */
+
+ "mysqldump" : "mysql_dump.groovy" ,
+
+ /*
+ This custom command enables users to invoke an SQL statement
+ Usage : invoke mysql query actionUser dbName query
+ Example: invoke mysql query root myDbName "update users set city=\"NY\" where uid=15"
+ */
+ "query" : "mysql_query.groovy"
+ ])
+
+
+ userInterface {
+ metricGroups = ([
+ metricGroup {
+ name "server"
+
+ metrics([
+ "Server Uptime",
+ "Client Connections",
+ "Total Queries",
+ "Slow Queries",
+ "Opens",
+ "Current Open Tables",
+ "Queries Per Second"
+ ])
+ }
+ ])
+
+ widgetGroups = ([
+ widgetGroup {
+ name "Server Uptime"
+ widgets ([
+ barLineChart{
+ metric "Server Uptime"
+ axisYUnit Unit.REGULAR
+ },
+ ])
+
+ } ,
+ widgetGroup {
+ name "Client Connections"
+ widgets ([
+ barLineChart{
+ metric "Client Connections"
+ axisYUnit Unit.REGULAR
+ },
+ ])
+
+ } ,
+ widgetGroup {
+ name "Total Queries"
+ widgets ([
+ barLineChart{
+ metric "Total Queries"
+ axisYUnit Unit.REGULAR
+ },
+ ])
+
+ } ,
+ widgetGroup {
+ name "Opens"
+ widgets ([
+ barLineChart{
+ metric "Opens"
+ axisYUnit Unit.REGULAR
+ },
+ ])
+
+ } ,
+ widgetGroup {
+ name "Current Open Tables"
+ widgets ([
+ barLineChart{
+ metric "Current Open Tables"
+ axisYUnit Unit.REGULAR
+ },
+ ])
+
+ } ,
+ widgetGroup {
+ name "Queries Per Second"
+ widgets ([
+ barLineChart{
+ metric "Queries Per Second"
+ axisYUnit Unit.REGULAR
+ },
+ ])
+
+ } ,
+ ])
+ }
+}
View
175 services/mysql/mysql-service.properties
@@ -0,0 +1,175 @@
+jdbcPort=3306
+
+win64 {
+ mysqlHome="mysql-5.5.24-winx64"
+ mysqlD="mysqld.exe"
+ mysqlProgram="mysql.exe"
+ mysqladmin="mysqladmin.exe"
+ mysqldump="mysqldump.exe"
+ zipName="${mysqlHome}.zip"
+ /* http://downloads.skysql.com/archive/index/p/mysql/v/5.5.24 */
+ zipURL="http://downloads.skysql.com/archives/mysql-5.5/${zipName}"
+}
+
+linux {
+ mysqlD="mysqld"
+ mysqlProgram="mysql"
+ mysqladmin="mysqladmin"
+ mysqldump="mysqldump"
+}
+
+
+
+dbName="tamirDB"
+dbUser="tamir"
+dbPassW="1234"
+
+
+/* Use the following format - leave an empty string (startDetectionQuery="") for using the default startDetection ( by port ) :
+ startDetectionQuery="select count(XXX) as cc from table_name"
+*/
+startDetectionQuery=""
+
+
+/*
+ actionType can be one of the four following: mysqladmin,mysql,mysqldump or import
+ Examples :
+
+ // In this case, dbName is a property which is defined in this properties file
+ // All the occurrences of MYSQLHOST in actionQuery, 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 this properties file
+ // All the occurrences of MYSQLHOST in actionQuery, 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:
+ // dbName,currDBZip,currImportSql are properties which are defined in this properties file
+ // currDBZip is the local name of the zip file ( after download )
+ // currImportSql is the name of the sql file which is stored in currDBZip.
+ // 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:
+ // dbName is a property which is defined in this properties file.
+ // if actionDbName is an empty string, then --all-databases will be used
+ // actionArgs contain the flags that you want to use with this mysqldump command
+ // Do NOT database flags, because they will be set according to the actionDbName.
+ // So do NOT use the following : --all-databases,-A,--databases, -B
+ // 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 ..."
+ ]
+
+*/
+postStartActions = [
+ [
+ "actionType" : "mysqladmin",
+ "actionQuery" : "create" ,
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Creating db - Name : ${dbName} ... "
+ ],
+
+ [
+ "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... "
+ ],
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"CREATE USER '${dbUser}'@'MYSQLHOST' IDENTIFIED BY '${dbPassW}';\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Creating db user ${dbUser} at MYSQLHOST, passw ${dbPassW} in ${dbName} db... "
+ ],
+
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"CREATE USER '${dbUser}'@'%' IDENTIFIED BY '${dbPassW}';\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Creating db user ${dbUser} at all hosts, passw ${dbPassW} in ${dbName} db... "
+ ],
+
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"grant usage on *.* to ${dbUser}@localhost identified by '${dbPassW}';\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Granting usage to user ${dbUser} at localhost, passw ${dbPassW} in ${dbName} db..."
+ ],
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"grant usage on *.* to ${dbUser}@MYSQLHOST identified by '${dbPassW}';\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Granting usage to user ${dbUser} at MYSQLHOST, passw ${dbPassW} in ${dbName} db..."
+ ],
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"grant usage on *.* to ${dbUser}@'%' identified by '${dbPassW}';\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Granting usage to user ${dbUser} at all hosts, passw ${dbPassW} in ${dbName} db..."
+ ],
+
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"grant all privileges on *.* to ${dbUser}@'localhost' with grant option;\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Granting all privileges to user ${dbUser} in ${dbName} db at localhost... "
+ ],
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"grant all privileges on *.* to ${dbUser}@'MYSQLHOST' with grant option;\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Granting all privileges to user ${dbUser} in ${dbName} db at MYSQLHOST... "
+ ],
+
+ [
+ "actionType" : "mysql",
+ "actionQuery" : "\"grant all privileges on *.* to ${dbUser}@'%' with grant option;\"",
+ "actionUser" : "root",
+ "actionDbName" : "${dbName}",
+ "debugMsg" : "Granting all privileges to user ${dbUser} in ${dbName} db at all hosts ... "
+ ]
+
+]
View
BIN  services/mysql/mysql.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
86 services/mysql/mysql_dump.groovy
@@ -0,0 +1,86 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import org.hyperic.sigar.OperatingSystem
+import org.cloudifysource.usm.USMUtils
+import org.cloudifysource.dsl.context.ServiceContextFactory
+import static mysql_runner.*
+
+
+/*
+ This file enables users to create a database snapshot (mysqldump).
+ Usage : invoke mysql mysqldump actionUser dumpPrefix [dbName]
+ Example: invoke mysql mysqldump root myPrefix_ myDbName
+ actionUser ( usually root ) = args[0]
+ dumpPrefix = args[1]
+ dbName = args[2]
+
+*/
+
+config=new ConfigSlurper().parse(new File('mysql-service.properties').toURL())
+osConfig=USMUtils.isWindows() ? config.win64 : config.linux
+context = ServiceContextFactory.getServiceContext()
+mysqlHost=context.attributes.thisInstance["dbHost"]
+binFolder=context.attributes.thisInstance["binFolder"]
+println "mysql_dump.groovy: mysqlHost is ${mysqlHost} "
+
+def currActionQuery
+def currOsName
+
+def os = OperatingSystem.getInstance()
+def currVendor=os.getVendor()
+switch (currVendor) {
+ case ["Ubuntu", "Debian", "Mint"]:
+ currOsName="unix"
+ break
+ case ["Red Hat", "CentOS", "Fedora", "Amazon",""]:
+ currOsName="unix"
+ break
+ case ~/.*(?i)(Microsoft|Windows).*/:
+ currOsName="windows"
+ break
+ default: throw new Exception("Support for ${currVendor} is not implemented")
+}
+
+
+if (args.length < 2) {
+ println "mysql_dump.groovy: mysqldump error: Missing parameters\nUsage: invoke mysql mysqldump actionUser dumpPrefix [dbName]"
+ System.exit(-1)
+}
+
+
+def currActionUser = args[0]
+def currDumpPrefix = args[1]
+def currActionDbName
+def currDebugMsg
+
+if (args.length < 3) {
+ currActionDbName = ""
+ currDebugMsg = "Invoking mysqldump on all the databases in ${mysqlHost} ..."
+}
+else {
+ currActionDbName = args[2]
+ currDebugMsg = "Invoking mysqldump on db ${currActionDbName} in ${mysqlHost} ..."
+}
+
+
+
+def currActionArgs = "--add-drop-database -c --lock-all-tables -F"
+
+def dumpFolder = System.properties["user.home"]
+runMysqlDump(binFolder,osConfig.mysqldump,currOsName,currActionArgs,currActionDbName,currActionUser,currDebugMsg,dumpFolder,currDumpPrefix)
+println "mysql_dump.groovy: End"
+
+
View
97 services/mysql/mysql_install.groovy
@@ -0,0 +1,97 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import org.cloudifysource.dsl.context.ServiceContextFactory
+import org.cloudifysource.usm.USMUtils
+import org.hyperic.sigar.OperatingSystem
+
+
+def installLinuxMysql(context,builder,currVendor,installScript) {
+ builder.sequential {
+ echo(message:"mysql_install.groovy: Chmodding +x ${context.serviceDirectory} ...")
+ chmod(dir:"${context.serviceDirectory}", perm:"+x", includes:"*.sh")
+
+ echo(message:"mysql_install.groovy: Running ${context.serviceDirectory}/${installScript} os is ${currVendor}...")
+ exec(executable: "${context.serviceDirectory}/${installScript}",failonerror: "true")
+ }
+}
+
+def installWindowsMysql(config,osConfig,unzipDir,zipFullPath,builder) {
+ builder.sequential {
+ mkdir(dir:"${unzipDir}")
+ echo(message:"mysql_install.groovy get ${osConfig.zipURL} ... ")
+ get(src:"${osConfig.zipURL}", dest:"${zipFullPath}", skipexisting:true)
+ echo(message:"mysql_install.groovy: Unzipping ${zipFullPath} to ${context.serviceDirectory}...")
+ unzip(src:"${zipFullPath}", dest:"${context.serviceDirectory}", overwrite:true)
+ }
+}
+
+config=new ConfigSlurper().parse(new File('mysql-service.properties').toURL())
+osConfig=USMUtils.isWindows() ? config.win64 : config.linux
+
+context = ServiceContextFactory.getServiceContext()
+
+def mysqlHost
+
+if ( context.isLocalCloud() ) {
+ mysqlHost =InetAddress.getLocalHost().getHostAddress()
+}
+else {
+ mysqlHost =System.getenv()["CLOUDIFY_AGENT_ENV_PRIVATE_IP"]
+}
+
+
+println "mysql_install.groovy: mysqlHost is ${mysqlHost}"
+context.attributes.thisInstance["dbHost"] = "${mysqlHost}"
+
+context.attributes.thisInstance["dbName"] = "${config.dbName}"
+println "mysql_install.groovy: dbName is ${config.dbName}"
+
+context.attributes.thisInstance["dbUser"] = "${config.dbUser}"
+println "mysql_install.groovy: dbUser is ${config.dbUser}"
+
+context.attributes.thisInstance["dbPassW"] = "${config.dbPassW}"
+println "mysql_install.groovy: dbPassW is ${config.dbPassW}"
+
+context.attributes.thisInstance["dbPort"] = "${config.jdbcPort}"
+println "mysql_install.groovy: dbPort is ${config.jdbcPort}"
+
+context.attributes.thisInstance["postStartRequired"] = true
+
+
+builder = new AntBuilder()
+
+def os = OperatingSystem.getInstance()
+def currVendor=os.getVendor()
+switch (currVendor) {
+ case ["Ubuntu", "Debian", "Mint"]:
+ context.attributes.thisInstance["binFolder"]="/usr/bin"
+ installLinuxMysql(context,builder,currVendor,"installOnUbuntu.sh")
+ break
+ case ["Red Hat", "CentOS", "Fedora", "Amazon",""]:
+ context.attributes.thisInstance["binFolder"]="/usr/bin"
+ installLinuxMysql(context,builder,currVendor,"install.sh")
+ break
+ case ~/.*(?i)(Microsoft|Windows).*/:
+ context.attributes.thisInstance["binFolder"]="${osConfig.mysqlHome}/bin"
+ unzipDir = System.properties["user.home"]+ "/.cloudify/mysql"
+ zipFullPath="${unzipDir}/${osConfig.zipName}"
+ installWindowsMysql(config,osConfig,unzipDir,zipFullPath,builder)
+ break
+ default: throw new Exception("Support for ${currVendor} is not implemented")
+}
+
+println "mysql_install.groovy: End"
+
View
69 services/mysql/mysql_query.groovy
@@ -0,0 +1,69 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import org.hyperic.sigar.OperatingSystem
+import org.cloudifysource.usm.USMUtils
+import org.cloudifysource.dsl.context.ServiceContextFactory
+import static mysql_runner.*
+
+
+/*
+ This file enables users to invoke an SQL statement
+ Usage : invoke mysql query actionUser dbName query
+ Example: invoke mysql query root myDbName "update users set city=\"NY\" where uid=15"
+*/
+
+config=new ConfigSlurper().parse(new File('mysql-service.properties').toURL())
+osConfig=USMUtils.isWindows() ? config.win64 : config.linux
+context = ServiceContextFactory.getServiceContext()
+mysqlHost=context.attributes.thisInstance["dbHost"]
+binFolder=context.attributes.thisInstance["binFolder"]
+println "mysql_query.groovy: mysqlHost is ${mysqlHost} "
+
+def currActionQuery
+def currOsName
+
+def os = OperatingSystem.getInstance()
+def currVendor=os.getVendor()
+switch (currVendor) {
+ case ["Ubuntu", "Debian", "Mint"]:
+ currOsName="unix"
+ break
+ case ["Red Hat", "CentOS", "Fedora", "Amazon",""]:
+ currOsName="unix"
+ break
+ case ~/.*(?i)(Microsoft|Windows).*/:
+ currOsName="windows"
+ break
+ default: throw new Exception("Support for ${currVendor} is not implemented")
+}
+
+
+if (args.length < 3) {
+ println "mysql_query.groovy: query error: Missing parameters\nUsage: invoke mysql query actionUser dbName query"
+ System.exit(-1)
+}
+
+
+def currActionUser = args[0]
+def currActionDbName = args[1]
+def currQuery = "\"" + args[2] + "\""
+def currDebugMsg = "Invoking query: ${currQuery}"
+
+runMysqlQuery(binFolder,osConfig.mysqlProgram,currOsName,currQuery,currActionDbName,currActionUser,currDebugMsg)
+
+println "mysql_query.groovy: End"
+
+
View
138 services/mysql/mysql_runner.groovy
@@ -0,0 +1,138 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import java.text.SimpleDateFormat
+def static runMysqlQuery(binFolder,execFile,osName,currQuery,dbName,dbUser,debugMsg) {
+
+ try {
+ def builder = new AntBuilder()
+ builder.sequential {
+ echo(message:"runMysqlQuery: os ${osName}: ${debugMsg}")
+ echo(message:"runMysqlQuery: ${binFolder}/${execFile} -u ${dbUser} -D ${dbName} -e ${currQuery}")
+ exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}") {
+ arg(line:"-u ${dbUser} -D ${dbName} -e ${currQuery}")
+ }
+ }
+ }
+ catch (Exception ioe) {
+ println "runMysqlQuery: Connection Failed!"
+ ioe.printStackTrace();
+ }
+
+ println "runMysqlQuery: Ended"
+}
+
+
+def static importMysqlDB(binFolder,execFile,osName,importedFile,dbName,dbUser,debugMsg) {
+
+ try {
+ def builder = new AntBuilder()
+ builder.sequential {
+ echo(message:"importMysqlDB: ${debugMsg}")
+ exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}" ,input:"${importedFile}") {
+ arg(value:"-u")
+ arg(value:"${dbUser}")
+ arg(value:"${dbName}")
+ }
+ }
+ }
+ catch (Exception ioe) {
+ println "importMysqlDB: Connection Failed!"
+ ioe.printStackTrace();
+ }
+
+ println "importMysqlDB: Ended"
+}
+
+
+def static runMysqlAdmin(binFolder,execFile,osName,actionName,dbName,dbUser,debugMsg) {
+
+ try {
+ def builder = new AntBuilder()
+ builder.sequential {
+ echo(message:"runMysqlAdmin: ${debugMsg}")
+ exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}") {
+ arg(value:"-u")
+ arg(value:"${dbUser}")
+ arg(value:"${actionName}")
+ arg(value:"${dbName}")
+ }
+ }
+ }
+ catch (Exception ioe) {
+ println "runMysqlAdmin: Connection Failed!"
+ ioe.printStackTrace();
+ }
+
+ println "runMysqlAdmin: Ended"
+}
+
+def static runMysqlDump(binFolder,execFile,osName,actionArgs,dbName,dbUser,debugMsg,dumpFolder,dumpPrefix) {
+
+ try {
+
+ def dbFlag
+ if ( "${dbName}" == "" ) {
+ dbFlag = "--all-databases"
+ }
+ else {
+ dbFlag = "--databases ${dbName}"
+ }
+
+ def argsLine = "-u ${dbUser} ${actionArgs} ${dbFlag} "
+
+ def currMillis=System.currentTimeMillis()
+ def currTime = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(currMillis)
+
+ def baseDumpName = "${dumpPrefix}${currTime}"
+ def sqlFileName = "${baseDumpName}.sql"
+ def baseRootName = "${dumpFolder}/${baseDumpName}"
+ def dumpSqlFullPath = "${baseRootName}.sql"
+ def dumpZipFullPath = "${baseRootName}.zip"
+
+ def builder = new AntBuilder()
+ builder.sequential {
+ echo(message:"runMysqlDump: ${debugMsg}")
+ exec(executable:"${binFolder}/${execFile}", osfamily:"${osName}", output:"${dumpSqlFullPath}") {
+ arg(line:"${argsLine}")
+ }
+ zip(destFile:"${dumpZipFullPath}", basedir: "${dumpFolder}" ,includes:"${sqlFileName}", update:true )
+ delete(file:"${dumpSqlFullPath}")
+ }
+ }
+ catch (Exception ioe) {
+ println "runMysqlDump: Connection Failed!"
+ ioe.printStackTrace();
+ }
+
+ println "runMysqlDump: Ended"
+}
+
+def static importFileToDB(binFolder,osConfig,currOsName,currActionDbName,currImportZip,importedFile,importedFileUrl,builder,context,currActionUser,currDebugMsg,config) {
+ builder.sequential {
+ echo(message:"importFileToDB: Getting ${importedFileUrl} to ${currImportZip} ...")
+ get(src:"${importedFileUrl}", dest:"${currImportZip}", skipexisting:true)
+ echo(message:"importFileToDB: Unzipping ${currImportZip} to ${context.serviceDirectory} ...")
+ unzip(src:"${currImportZip}", dest:"${context.serviceDirectory}", overwrite:true)
+ }
+
+ def fullPathToImport="${context.serviceDirectory}/${importedFile}"
+ def currImportFile = new File(fullPathToImport)
+ def importText = currImportFile.text
+ println "groovy: Replacing REPLACE_WITH_DB_NAME with ${config.dbName} in ${context.serviceDirectory}/${importedFile} ..."
+ currImportFile.text = importText.replace("REPLACE_WITH_DB_NAME",currActionDbName)
+
+ importMysqlDB(binFolder,osConfig.mysqlProgram,currOsName,fullPathToImport,currActionDbName,currActionUser,currDebugMsg)
+}
View
120 services/mysql/mysql_start.groovy
@@ -0,0 +1,120 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import org.hyperic.sigar.OperatingSystem
+import org.cloudifysource.usm.USMUtils
+import org.cloudifysource.dsl.context.ServiceContextFactory
+import static mysql_runner.*
+
+config=new ConfigSlurper().parse(new File('mysql-service.properties').toURL())
+osConfig=USMUtils.isWindows() ? config.win64 : config.linux
+context = ServiceContextFactory.getServiceContext()
+mysqlHost=context.attributes.thisInstance["dbHost"]
+binFolder=context.attributes.thisInstance["binFolder"]
+println "mysql_start.groovy: mysqlHost is ${mysqlHost} "
+
+
+
+
+def runPostStartActions(config,binFolder,osConfig,currOsName,builder,context,mysqlHost) {
+ def currActionQuery
+ def actionCounter = 1
+
+ for ( currActionObj in config.postStartActions ) {
+ println "mysql_start.runPostStartActions: postStartActions #${actionCounter}:"
+ def currActionType = currActionObj["actionType"]
+ def currActionUser = currActionObj["actionUser"]
+ def currActionDbName = currActionObj["actionDbName"]
+ def currDebugMsg = currActionObj["debugMsg"]
+ currDebugMsg = currDebugMsg.replaceAll("MYSQLHOST",mysqlHost)
+
+ switch (currActionType) {
+ case "mysqladmin":
+ currActionQuery = currActionObj["actionQuery"]
+ currActionQuery = currActionQuery.replaceAll("MYSQLHOST",mysqlHost)
+ runMysqlAdmin(binFolder,osConfig.mysqladmin,currOsName,currActionQuery,currActionDbName,currActionUser,currDebugMsg)
+ break
+ case "mysql":
+ currActionQuery = currActionObj["actionQuery"]
+ currActionQuery = currActionQuery.replaceAll("MYSQLHOST",mysqlHost)
+ runMysqlQuery(binFolder,osConfig.mysqlProgram,currOsName,currActionQuery,currActionDbName,currActionUser,currDebugMsg)
+ break
+ case "import":
+ def currImportZip="${context.serviceDirectory}/"+currActionObj["importedZip"]
+ def importedFile=currActionObj["importedFile"]
+ def importedFileUrl=currActionObj["importedFileUrl"]
+ importFileToDB(binFolder,osConfig,currOsName,currActionDbName,currImportZip,importedFile,importedFileUrl,builder,context,currActionUser,currDebugMsg,config)
+ break
+ case "mysqldump":
+ currActionArgs = currActionObj["actionArgs"]
+ currDumpPrefix = currActionObj["dumpPrefix"]
+ def dumpFolder = System.properties["user.home"]
+ runMysqlDump(binFolder,osConfig.mysqldump,currOsName,currActionArgs,currActionDbName,currActionUser,currDebugMsg,dumpFolder,currDumpPrefix)
+ break
+ default:
+ println "Ignoring Action Type ${currActionType} ... "
+ break
+ }
+
+ actionCounter++
+ }
+}
+
+builder = new AntBuilder()
+
+def os = OperatingSystem.getInstance()
+def currVendor=os.getVendor()
+switch (currVendor) {
+ case ["Ubuntu", "Debian", "Mint"]:
+ script="${context.serviceDirectory}/runOnUbuntu.sh"
+ currOsName="unix"
+ break
+ case ["Red Hat", "CentOS", "Fedora", "Amazon",""]:
+ script="${context.serviceDirectory}/run.sh"
+ currOsName="unix"
+ break
+ case ~/.*(?i)(Microsoft|Windows).*/:
+ script="${binFolder}/${osConfig.mysqlD}"
+ currOsName="windows"
+ break
+ default: throw new Exception("Support for ${currVendor} is not implemented")
+}
+
+
+builder.sequential {
+ echo(message:"mysql_start.groovy: Running ${script} on ${currOsName} ...")
+ exec(executable:"${script}", osfamily:"${currOsName}",failonerror: "true")
+}
+
+/* Restart does not require postStart, so if attr postStartRequired is false , postStart will NOT be executed. */
+def postStartRequired = context.attributes.thisInstance["postStartRequired"]
+
+println "mysql_start.groovy: postStartRequired is ${postStartRequired}"
+
+if ( postStartRequired ) {
+ try {
+ println "mysql_start.groovy: postStart"
+ runPostStartActions(config,binFolder,osConfig,currOsName,builder,context,mysqlHost)
+ }
+ catch (Exception ioe) {
+ println "mysql_start.groovy: Connection Failed!"
+ println ioe
+ }
+}
+
+context.attributes.thisInstance["postStartRequired"] = false
+println "mysql_start.groovy: End"
+
+
View
74 services/mysql/mysql_startDetection.groovy
@@ -0,0 +1,74 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import org.cloudifysource.dsl.context.ServiceContextFactory
+import groovy.sql.*
+import org.cloudifysource.dsl.utils.ServiceUtils;
+import com.mysql.jdbc.Driver
+
+config=new ConfigSlurper().parse(new File('mysql-service.properties').toURL())
+
+context = ServiceContextFactory.getServiceContext()
+
+println "mysql_startDetection.groovy: jdbcPort is ${config.jdbcPort} ..."
+if ( ServiceUtils.isPortOccupied(config.jdbcPort) ) {
+ println "mysql_startDetection: port ${config.jdbcPort} is now occupied ..."
+ if ( config.startDetectionQuery.length() == 0 ) {
+ println "mysql_startDetection: startDetectionQuery is empty - service is up "
+ System.exit(0)
+ }
+ try {
+ def mysqlHost
+ if ( context.isLocalCloud() ) {
+ mysqlHost =InetAddress.getLocalHost().getHostAddress()
+ }
+ else {
+ mysqlHost =System.getenv()["CLOUDIFY_AGENT_ENV_PRIVATE_IP"]
+ }
+ def connUrl="jdbc:mysql://${mysqlHost}:${config.jdbcPort}/${config.dbName}"
+ println "mysql_startDetection: connUrl is ${connUrl}"
+ def sql = Sql.newInstance("${connUrl}", "${config.dbUser}","${config.dbPassW}", "com.mysql.jdbc.Driver")
+ println "mysql_startDetection: ran query ${config.startDetectionQuery}"
+ rows = sql.rows(config.startDetectionQuery)
+ println "mysql_startDetection: rows value is ${rows}"
+ if ( rows.size > 0 ) {
+ println "mysql_startDetection: Rows size " + rows.size
+ def row0 = rows[0]
+ println "mysql_startDetection: row0 is ${row0}"
+ if ( row0 != null ) {
+ def cc = row0["cc"] as int
+ context.attributes.thisInstance["cc"] = cc
+ println "mysql_startDetection: Count " + cc
+ //return cc > 0
+ if ( cc > 0 ) {
+ System.exit(0)
+ }
+ else {
+ System.exit(-1);
+ }
+ }
+ println "mysql_startDetection: row0 is null"
+ }
+ println "mysql_startDetection: rows.size is zero"
+
+ }
+ catch (Exception e) {
+ //println e.getMessage()
+ System.exit(-1);
+ }
+
+}
+//return false;
+System.exit(-1);
View
42 services/mysql/mysql_stop.groovy
@@ -0,0 +1,42 @@
+/*******************************************************************************
+* Copyright (c) 2011 GigaSpaces Technologies Ltd. All rights reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+import org.cloudifysource.usm.USMUtils
+import org.cloudifysource.dsl.context.ServiceContextFactory
+
+
+config=new ConfigSlurper().parse(new File('mysql-service.properties').toURL())
+osConfig=USMUtils.isWindows() ? config.win64 : config.linux
+
+context = ServiceContextFactory.getServiceContext()
+
+println "mysql_stop.groovy: About to stop ... "
+
+binFolder=context.attributes.thisInstance["binFolder"]
+
+println "mysql_stop.groovy: binFolder is ${binFolder} ..."
+
+new AntBuilder().sequential {
+ echo(message:"mysql_stop.groovy: Running ${binFolder}/mysqladmin -u root shutdown ...")
+ exec(executable:"${binFolder}/${osConfig.mysqladmin}") {
+ arg(value:"-u")
+ arg(value:"root")
+ arg(value:"shutdown")
+ }
+}
+
+
+
+println "mysql_stop.groovy: End"
View
18 services/mysql/run.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+sudo /etc/rc.d/init.d/mysqld start || error_exit $? "Failed on: sudo /etc/rc.d/init.d/mysqld start"
+
+ps -ef | grep -i mysql | grep -ivE "gigaspaces|GSC|GSA|grep"
+
View
18 services/mysql/runOnUbuntu.sh
@@ -0,0 +1,18 @@
+#!/bin/bash -x
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+sudo service mysql start || error_exit $? "Failed on: sudo service mysql start"
+
+ps -ef | grep -i mysql | grep -ivE "gigaspaces|GSC|GSA|grep"
+
View
18 services/mysql/stop.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+sudo /etc/rc.d/init.d/mysqld stop || error_exit $? "Failed on: sudo /etc/rc.d/init.d/mysqld stop"
+
+ps -ef | grep -i mysql | grep -ivE "gigaspaces|GSC|GSA|grep"
+
View
18 services/mysql/stopOnUbuntu.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+sudo service mysql stop || error_exit $? "Failed on: sudo service mysql stop"
+
+ps -ef | grep -i mysql | grep -ivE "gigaspaces|GSC|GSA|grep"
+
View
44 services/mysql/uninstall.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+function killMySqlProcess {
+ ps -ef | grep -iE "mysql" | grep -ivE "gigaspaces|GSC|GSA|grep"
+ if [ $? -eq 0 ] ; then
+ ps -ef | grep -iE "mysql" | grep -ivE "gigaspaces|GSC|GSA|grep" | awk '{print $2}' | xargs sudo kill -9
+ fi
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+echo "#1 Killing old mysql process if exists..."
+killMySqlProcess
+
+echo "Removing previous mysql installation if exists..."
+sudo yum -y -q remove mysql mysql-server
+
+# The following two statements are used since in some cases, there are leftovers after uninstall
+echo "Removing old stuff if exists..."
+sudo rm -rf /usr/lib/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/lib/mysql*"
+sudo rm -rf /var/lib/mysql* || error_exit $? "Failed on: sudo rm -rf /var/lib/mysql*"
+sudo rm -rf /usr/share/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/sharemysql*"
+sudo rm -rf /usr/bin/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/bin/mysql*"
+sudo rm -rf /var/run/mysql* || error_exit $? "Failed on: sudo rm -rf /var/run/mysql*"
+sudo rm -rf /var/bin/mysql* || error_exit $? "Failed on: sudo rm -rf /var/bin/mysql*"
+sudo rm -rf /etc/mysql* || error_exit $? "Failed on: sudo rm -rf /etc/mysql*"
+sudo rm -rf /etc/rc.d/init.d/mysql* || error_exit $? "Failed on: sudo rm -rf /etc/rc.d/init.d/mysql*"
+sudo rm -rf /usr/libexec/mysql* || error_exit $? "Failed on: sudo rm -rf /usr/libexec/mysqld*"
+sudo rm -rf /etc/my.cnf || error_exit $? "Failed on: sudo rm -rf /etc/my.cnf"
+sudo rm -rf /var/log/mysql* || error_exit $? "Failed on: sudo rm -rf /var/log/mysql*"
+sudo rm -f /home/`whoami`/{.,}*mysql* || error_exit $? "Failed on: sudo rm -f /home/`whoami`/{.,}*mysql*"
+
+
+echo "End of $0"
View
55 services/mysql/uninstallOnUbuntu.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# args:
+# $1 the error code of the last command (should be explicitly passed)
+# $2 the message to print in case of an error
+#
+# an error message is printed and the script exists with the provided error code
+function error_exit {
+ echo "$2 : error code: $1"
+ exit ${1}
+}
+
+function killMySqlProcess {
+ ps -ef | grep -iE "mysql" | grep -ivE "gigaspaces|GSC|GSA|grep"
+ if [ $? -eq 0 ] ; then
+ ps -ef | grep -iE "mysql" | grep -ivE "gigaspaces|GSC|GSA|grep" | awk '{print $2}' | xargs sudo kill -9
+ fi
+}
+
+export PATH=$PATH:/usr/sbin:/sbin:/usr/bin || error_exit $? "Failed on: export PATH=$PATH:/usr/sbin:/sbin"
+
+if grep -q -E '[^!]requiretty' /etc/sudoers; then
+ echo "Defaults:`whoami` !requiretty" | sudo tee /etc/sudoers.d/`whoami` >/dev/null
+ sudo chmod 0440 /etc/sudoers.d/`whoami`
+fi
+
+# The existence of the usingAptGet file in the ext folder will later serve as a flag that "we" are on Ubuntu or Debian or Mint
+echo "Using apt-get. Updating apt-get on one of the following : Ubuntu, Debian, Mint" > usingAptGet
+sudo apt-get -y -q update || error_exit $? "Failed on: sudo apt-get -y update"
+
+echo "#1 Killing old mysql process if exists..."
+killMySqlProcess
+
+# Removing previous mysql installation if exists
+echo "Purging previous mysql installation if exists..."
+sudo apt-get -y -q purge mysql-client* mysql-server* mysql-common*
+
+# The following two statements are used since in some cases, there are leftovers after uninstall
+echo "Removing old stuff if exists..."
+sudo rm -rf /etc/mysql || error_exit $? "Failed on: sudo rm -rf /etc/mysql"
+
+
+echo "Using apt-get. Updating apt-get on one of the following : Ubuntu, Debian, Mint"
+sudo DEBIAN_FRONTEND='noninteractive' apt-get -o Dpkg::Options::='--force-confnew' -q -y install mysql-server-core-5.1 mysql-server-5.1 mysql-client-core-5.1 mysql-client-5.1 mysql-common || error_exit $? "Failed on: sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q mysql-server ... "
+
+echo "Killing old mysql process if exists b4 ending the installation..."
+killMySqlProcess
+
+
+echo "End of $0"
+
+
+
+#sudo service mysql stop
+#sudo service mysql start
View
BIN  services/mysql/usmlib/mysql-admin-1.0-SNAPSHOT.jar
Binary file not shown
View
BIN  services/mysql/usmlib/mysql-connector-java-5.1.17-bin.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.