#!/bin/bash

#judgement
if [[ -a /etc/supervisor/conf.d/supervisord.conf ]]; then
  exit 0
fi

#[program:mysqld]
#command=/entrypoint.sh mysqld

#supervisor
cat > /etc/supervisor/conf.d/supervisord.conf <<EOF
[supervisord]
nodaemon=true

[program:rsyslog]
command=/usr/sbin/rsyslogd -n

[program:apache2]
command=/opt/apache2.sh

[program:mysqld]
command=/docker-entrypoint.sh mysqld

[program:wildfly]
command=/usr/local/handelion/wildfly/bin/standalone.sh

EOF

############
#  apache2
############
cat >> /opt/apache2.sh <<EOF
#!/bin/bash
#sed 's/coin-validator.local/'"$maildomain"'/' -i /etc/apache2/sites-available/000-default.conf

service apache2 start
tail -f /var/log/apache2/error.log
EOF
chmod +x /opt/apache2.sh
chmod +x /usr/local/handelion/wildfly/bin/standalone.sh
