classes/plugins/MysqlPlugin.tmpl
{{ header }}
if [ "$START_{{softwareComponentName|upper}}" = "YES" ]; then
{{ preparecomp }}
{{ getsource }}
{{ prestart }}
if [ "${{typeSourceVarName}}" == "docker" ]; then
# run in docker
if [ ! -f "{{pidFile}}" ]; then
startDockerNetwork
{{writeDockerConnectionLogic}}
{{writeConfigFiles}}
verbosePrint "docker run --rm -d -p {{ExposedPort}}:{{ExposedPort}} {% if Mysql.RootPassword %} -e MYSQL_ROOT_PASSWORD="{{Mysql.RootPassword}}" {% else %} -e MYSQL_ALLOW_EMPTY_PASSWORD=true {% endif %} {% if DockerMemory %}-m {{DockerMemory}}{% endif %} --net={{systemName|lower}}net --name={{softwareComponentName}} {{AllEnvVarsDocker}} {{mountToDocker}} {{DockerImage}}:${{typeSourceVarName}}_VERSION"
dockerContainerID{{softwareComponentName}}=$(docker run --rm -d -p {{ExposedPort}}:{{ExposedPort}} \
{% if Mysql.RootPassword %} -e MYSQL_ROOT_PASSWORD="{{Mysql.RootPassword}}" {% else %} -e MYSQL_ALLOW_EMPTY_PASSWORD=true {% endif %} \
{% if DockerMemory %}-m {{DockerMemory}}{% endif %} \
--net={{systemName|lower}}net --name={{softwareComponentName}} $ADD_HOST_INTERNAL \
{{AllEnvVarsDocker}} \
{{mountToDocker}} {{DockerImage}}:${{typeSourceVarName}}_VERSION)
echo "$dockerContainerID{{softwareComponentName}}">{{pidFile}}
else
dockerContainerID{{softwareComponentName}}=$(<{{pidFile}})
echo "Reusing already running instance $dockerContainerID{{softwareComponentName}}"
fi
fi
if [ "${{typeSourceVarName}}" == "local" ]; then
if [ -f "{{pidFile}}" ]; then
echo "mysql running but started from different source type"
exit 1
fi
fi
{% if Mysql.RootPassword %}
export MYSQL_PWD="{{Mysql.RootPassword}}"
{% endif %}
while ! mysql -uroot --protocol=tcp -e "select 1" 1>/dev/null 2>&1; do
echo "waiting for mysql..."
sleep 3
done
{% if Mysql.Schema %}
mysql -uroot --protocol=tcp -NB -e "create database if not exists {{Mysql.Schema}}"
{% for sql in Mysql.Create %}
mysql -uroot --protocol=tcp {{Mysql.Schema}} < {{sql}}
{% endfor %}
{% endif %}
{{ poststart }}
{{ leavecomp }}
fi