#! /bin/bash

[[ "$TRACE" ]] && set -x
set -eo pipefail

[[ -x /usr/bin/about ]] && echo "
# short info about application
about"

echo "
# debug container if it cannot activate
TRACE=yes /app/qloud/entrypoint.sh

# dump application config
config-dumper /app/config/config.yml -yml

# stop application
portoctl stop app/sub_main

# kill application
killall -9 app

# start application
portoctl start app/sub_main
"
# Print paths to log files from application config.
if [[ -x /usr/bin/config-dumper && -f /app/config/config.yml ]]; then
    echo "logs: "
    /usr/bin/config-dumper /app/config/config.yml -yml \
        | grep -oP 'path\s*:.*\.(log|tskv)' \
        | sed -e 's/^path\s*:\s*//'
fi

# Print app-specific welcome, if any.
/app/doc/welcome 2>/dev/null || true

echo "
# repeat this message
welcome
"
