From 87a4c04fe9e23f6943bd37b711094dbf5d482b2b Mon Sep 17 00:00:00 2001 From: ALinuxNinja Date: Fri, 5 May 2017 22:31:52 -0400 Subject: [PATCH] make container more versatile --- wrapper.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 wrapper.sh diff --git a/wrapper.sh b/wrapper.sh new file mode 100755 index 0000000..c5cd71a --- /dev/null +++ b/wrapper.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +## Refresh config +cp -R /opt/postal/config-original/* /opt/postal/config + +## Generate keys +/opt/postal/bin/postal initialize-config + +if [[ $(cat /opt/postal/config/postal.yml| grep -i web_server |wc -l) == 0 ]]; then +cat >> /opt/postal/config/postal.yml << EOF +web_server: + bind_address: 0.0.0.0 +EOF +fi + +## Set MySQL/RabbitMQ usernames/passwords +### MySQL Main DB +sed -i -e '/main_db:/!b' -e ':a' -e "s/host.*/host: mysql/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e'/main_db:/!b' -e ':a' -e "s/username.*/username: root/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e'/main_db:/!b' -e ':a' -e "s/password.*/password: $MYSQL_ROOT_PASSWORD/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e'/main_db:/!b' -e ':a' -e "s/database.*/database: $MYSQL_DATABASE/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +### MySQL Message DB +sed -i -e '/message_db:/!b' -e ':a' -e "s/host.*/host: mysql/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e'/message_db:/!b' -e ':a' -e "s/username.*/username: root/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e'/message_db:/!b' -e ':a' -e "s/password.*/password: $MYSQL_ROOT_PASSWORD/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +### RabbitMQ +sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/host.*/host: rabbitmq/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/username.*/username: $RABBITMQ_DEFAULT_USER/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/password.*/password: $RABBITMQ_DEFAULT_PASS/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml +sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/vhost.*/vhost: \/$RABBITMQ_DEFAULT_VHOST/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml + +## Clean Up +rm -rf /opt/postal/tmp/pids/* + +## Start Postal +/opt/postal/bin/postal "$@"