diff --git a/manifest.yml b/manifest.yml index d0888f5c..8a86271a 100644 --- a/manifest.yml +++ b/manifest.yml @@ -7,6 +7,7 @@ categories: - apps/clustered-dbs - apps/popular - apps/clusters + - apps/databases description: text: "/texts/description.md?_r=1" diff --git a/scripts/common.yml b/scripts/common.yml index 79fdd542..69498905 100644 --- a/scripts/common.yml +++ b/scripts/common.yml @@ -1,7 +1,18 @@ globals: + db_cluster_path: https://raw.githubusercontent.com/jelastic-jps/mysql-cluster/v3.0.0 customConfigFile: /etc/mysql/conf.d/my_custom.cnf actions: + + isEnvRunning: + script: | + import com.hivext.api.server.system.service.utils.EnvironmentStatus; + var resp = jelastic.env.control.GetEnvInfo('${env.envName}', session); + if (resp.result != 0) return resp; + var status = resp.env.status; + var isEnvRunning = status == EnvironmentStatus['ENV_STATUS_TYPE_RUNNING'].getValue() ? true : false; + return {result: 0, isEnvRunning: isEnvRunning} + getReplicaUser: - env.control.GetContainerEnvVarsByGroup[sqldb] - setGlobals: @@ -64,7 +75,7 @@ actions: setupAdminUser: - cmd[${this.id}]: |- - wget ${baseUrl}/scripts/setupUser.sh -O ~/setupUser.sh &>> /var/log/run.log; + wget ${globals.db_cluster_path}/scripts/setupUser.sh -O ~/setupUser.sh; bash ~/setupUser.sh ${globals.DB_USER} ${globals.DB_PASS} &>> /var/log/run.log; user: root @@ -77,7 +88,7 @@ actions: pswd: ${globals.REPLICA_PSWD} addCustomConfig: - - cmd[sqldb]: wget ${baseUrl}/configs/custom.cnf -O ${globals.customConfigFile} &>> /var/log/run.log; + - cmd[sqldb]: wget ${globals.db_cluster_path}/configs/custom.cnf -O ${globals.customConfigFile}; - env.file.AddFavorite: nodeGroup: sqldb path: ${globals.customConfigFile} diff --git a/scripts/galera.jps b/scripts/galera.jps index 4593ac1d..5fab6d73 100644 --- a/scripts/galera.jps +++ b/scripts/galera.jps @@ -38,7 +38,21 @@ onAfterScaleOut[sqldb]: - cmd[${@i.id}]: jem service restart onAfterScaleIn[sqldb]: setupSeeds - + +onBeforeMigrate: + - isEnvRunning + - if (!${response.isEnvRunning}): + - stopEvent: + type: warning + message: "Please run the environment before migration, otherwise the database cluster will be broken." + +onBeforeClone: + - isEnvRunning + - if (!${response.isEnvRunning}): + - stopEvent: + type: warning + message: "Please run the environment before cloning, otherwise the database cluster will be broken." + onAfterMigrate: - script: delete MANIFEST.id; return {result:0, jps:MANIFEST}; - install: ${response.jps} @@ -137,6 +151,7 @@ actions: [ -f /var/lib/mysql/grastate.dat ] && rm -f /var/lib/mysql/grastate.dat [ -f /var/lib/mysql/gvwstate.dat ] && rm -f /var/lib/mysql/gvwstate.dat [ -f /var/lib/mysql/galera.cache ] && rm -f /var/lib/mysql/galera.cache + [ -f /var/lib/mysql/tc.log ] && rm -f /var/lib/mysql/tc.log pgrep mysql 1>/dev/null && pkill -9 mysql; pgrep mariadb 1>/dev/null && pkill -9 mariadb || true user: root diff --git a/scripts/master-master.jps b/scripts/master-master.jps index 29db36f3..6ba2f33f 100644 --- a/scripts/master-master.jps +++ b/scripts/master-master.jps @@ -19,6 +19,20 @@ globals: DB_USER: ${settings.db_user:user-[fn.random]} DB_PASS: ${settings.db_pass:[fn.password(20)]} +onBeforeMigrate: + - isEnvRunning + - if (!${response.isEnvRunning}): + - stopEvent: + type: warning + message: "Please run the environment before migration, otherwise the database cluster will be broken." + +onBeforeClone: + - isEnvRunning + - if (!${response.isEnvRunning}): + - stopEvent: + type: warning + message: "Please run the environment before cloning, otherwise the database cluster will be broken." + onAfterScaleOut[sqldb]: - forEach(event.response.nodes): - syncCustomConfig: diff --git a/scripts/master-slave.jps b/scripts/master-slave.jps index 73d9becf..2a69a53a 100644 --- a/scripts/master-slave.jps +++ b/scripts/master-slave.jps @@ -19,6 +19,20 @@ globals: DB_USER: ${settings.db_user:user-[fn.random]} DB_PASS: ${settings.db_pass:[fn.password(20)]} +onBeforeMigrate: + - isEnvRunning + - if (!${response.isEnvRunning}): + - stopEvent: + type: warning + message: "Please run the environment before migration, otherwise the database cluster will be broken." + +onBeforeClone: + - isEnvRunning + - if (!${response.isEnvRunning}): + - stopEvent: + type: warning + message: "Please run the environment before cloning, otherwise the database cluster will be broken." + onAfterScaleOut[sqldb]: - forEach(event.response.nodes): - syncCustomConfig: diff --git a/scripts/proxy-common.yml b/scripts/proxy-common.yml index abe1d32b..dda8f914 100644 --- a/scripts/proxy-common.yml +++ b/scripts/proxy-common.yml @@ -1,3 +1,6 @@ +globals: + db_cluster_path: https://raw.githubusercontent.com/jelastic-jps/mysql-cluster/v3.0.0 + actions: setupOrchestrator: - log: Orchestrator configuration @@ -11,7 +14,7 @@ actions: mysql -h 127.0.0.1 -P3360 -uroot -e "SET PASSWORD FOR 'admin'@'127.0.0.1' = PASSWORD('${globals.ORCH_PASS}');" fi mysql -h 127.0.0.1 -P3360 -uroot -e "FLUSH PRIVILEGES;" - wget ${baseUrl}/configs/orchestrator.conf.json -O /etc/orchestrator.conf.json &>> /var/log/run.log + wget ${globals.db_cluster_path}/configs/orchestrator.conf.json -O /etc/orchestrator.conf.json &>> /var/log/run.log sed -i -e 's|orc_client_user|${globals.DB_USER}|g' /etc/orchestrator.conf.json sed -i -e 's|orc_client_password|${globals.DB_PASS}|g' /etc/orchestrator.conf.json sed -i -e 's|orc_server_user|admin|g' /etc/orchestrator.conf.json diff --git a/scripts/xtradb.jps b/scripts/xtradb.jps index 1bb1b995..ebe634eb 100644 --- a/scripts/xtradb.jps +++ b/scripts/xtradb.jps @@ -132,6 +132,7 @@ actions: [ -f /var/lib/mysql/grastate.dat ] && rm -f /var/lib/mysql/grastate.dat [ -f /var/lib/mysql/gvwstate.dat ] && rm -f /var/lib/mysql/gvwstate.dat [ -f /var/lib/mysql/galera.cache ] && rm -f /var/lib/mysql/galera.cache + [ -f /var/lib/mysql/tc.log ] && rm -f /var/lib/mysql/tc.log pgrep mysql 1>/dev/null && pkill -9 mysql; pgrep mariadb 1>/dev/null && pkill -9 mariadb || true user: root