Thanks for your feedback!

Custom Scripts

You can write your custom scripts in Java or JavaScript. Inside these scripts, a set of client libraries for Jelastic API methods calling is available. You can bind your scripts to the onAfterReturn event to execute the required actions.

Intercontainer Scripts

In order to execute a shell script inside of a container, use the ExecuteShellCommands (cmd) action.

Examples:

  • Executing bash script from URL.

      cmd [cp]: curl -fsS http://example.com/script.sh | /bin/bash -s arg1 arg2
      
      {
        "cmd [cp]": "curl -fsS http://example.com/script.sh | /bin/bash -s arg1 arg2"
      }
      

  • Restoring MySQL database.

      cmd [mysql5]: curl -fsS http://example.com/script.sh | /bin/bash -s '${nodes.sqldb.password}' 'http://example.com/dump.sql' '${user.appPassword}'
      
      {
        "cmd [mysql5]": "curl -fsS http://example.com/script.sh | /bin/bash -s '${nodes.sqldb.password}' 'http://example.com/dump.sql' '${user.appPassword}'"
      }
      

script.sh:

#!/bin/bash
USER="root"
PASSWORD="$1"

DUMP_URL="$2"
DUMP_PATH="/var/lib/mysql/dump.sql"

NEW_USER_NAME="test"
NEW_USER_PASS="$3"
NEW_DB_NAME="test"


curl -fs ${DUMP_URL} -o ${DUMP_PATH} 2>&1

mysql -u${USER} -p${PASSWORD} << END 
    CREATE DATABASE ${NEW_DB_NAME};
    GRANT USAGE ON *.* TO ${NEW_USER_NAME}@localhost  IDENTIFIED BY '${NEW_USER_PASS}';
    GRANT ALL PRIVILEGES ON ${NEW_USER_NAME}.* to ${NEW_DB_NAME}@localhost;
    USE ${NEW_DB_NAME};

\. ${DUMP_PATH}
END

Here, ${nodes.sqldb.password} is available only for the install installation type when a SQL node is created.

Top Level Scripts

Using a script action.

Java

    script:
      - type: java
        params:
          greeting: Hello World!
        script: |
          return hivext.local.GetParam("greeting");
    
    {
      "script": [
        {
            "type" : "java",        
            "params" : {
                "greeting" : "Hello World!"
            },
            "script" : "return hivext.local.GetParam(\"greeting\");"
        }
      ]
    }
    

JavaScript

    script: |
      return getParam('greeting');
    greeting: Hello World!
    
    {
      "script": "return getParam('greeting');",
      "greeting": "Hello World!"
    }
    

What's next?

v: 8.8.1