#! /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 /usr/sbin/entrypoint.sh

# dump $APPLICATION config
config-dumper /etc/$APPLICATION/config.yml -yml

# stop $APPLICATION
portoctl stop app/sub_main

# kill $APPLICATION
killall -9 $APPLICATION

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

# Print app-specific welcome, if any.
/usr/share/$APPLICATION/entrypoint.d/welcome 2>/dev/null || true

echo "
# repeat this message
welcome
"
