services:
  - type: org.apache.brooklyn.entity.software.base.WorkflowSoftwareProcess
    name: MariaDB
    brooklyn.config:
      db.port: 3306
      install.workflow:
        steps:
          - ssh sudo apt install -y mariadb-server
          - ssh sudo sed -i s/127.0.0.1/0.0.0.0/ /etc/mysql/mariadb.conf.d/50-server.cnf
          - ssh sudo service mariadb restart

      customize.workflow:
        steps:
          - step: ssh curl -L "${entity.config.creation_script_sql_url}" | sudo mariadb -u root
            condition:
              target: ${entity.config.creation_script_sql_url}

      launch.workflow:
        steps:
          - ssh sudo service mariadb start

      stop.workflow:
        steps:
          - ssh sudo service mariadb stop

    brooklyn.initializers:
      - type: workflow-sensor
        brooklyn.config:
          name: db.queries_per_sec
          steps:
            - ssh sudo mysqladmin status | awk '{print $NF}'
            - return ${stdout}
          period: 10s

brooklyn.parameters:
  - name: creation_script_sql_url
    description: SQL to run to initialize the DB when it is created
    pinned: true
