test/fstack/lib/listmonk.sh

106 lines
2.6 KiB
Bash

#!/bin/bash
#
# Federated Computer Control Postgresql Service
PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
config_listmonk() {
echo -ne "\n* Configuring fstack/listmonk container.."
spin &
SPINPID=$!
if [ ! -d "fstack/listmonk" ]; then
mkdir -p fstack/listmonk/static
fi
DOMAIN_ARRAY=(${DOMAIN//./ })
DOMAIN_FIRST=${DOMAIN_ARRAY[0]}
DOMAIN_LAST=${DOMAIN_ARRAY[1]}
cat > fstack/listmonk/docker-compose.yml <<EOF
version: "3.7"
services:
listmonk:
image: listmonk/listmonk:latest
container_name: listmonk
hostname: listmonk.$DOMAIN
domainname: $DOMAIN
restart: always
command: [sh, -c, "yes | ./listmonk --install --config config.toml && ./listmonk --config config.toml"]
networks:
fstack:
ipv4_address: 172.99.0.39
environment:
- VIRTUAL_PROTO=http
- VIRTUAL_PORT=9000
- VIRTUAL_HOST=listmonk.$DOMAIN
- TZ=Etc/UTC
volumes:
- ./data/listmonk/config.toml:/listmonk/config.toml
- ./data/listmonk/static:/listmonk/static
networks:
fstack:
external: true
EOF
cat > fstack/listmonk/data/listmonk/config.toml <<EOF
[app]
address = "0.0.0.0:9000"
admin_username = "admin"
admin_password = "$ADMINPASS"
# Database.
[db]
host = "postgresql.$DOMAIN"
port = 5432
user = "listmonk"
password = "$ADMINPASS"
database = "listmonk"
ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"
EOF
kill -9 $SPINPID &> /dev/null
echo -ne "done."
}
start_listmonk() {
# Start fstack/listmonk with output to /dev/null
echo -ne "\n* Starting fstack/listmonk service.."
spin &
SPINPID=$!
if [ $DEBUG ]; then
# Start fstack/listmonk with output to console for debug
docker-compose -f fstack/listmonk/docker-compose.yml -p listmonk up --build
[ $? -eq 0 ] && echo -ne "done.\n" || fail "There was a problem starting service fstack/listmonk"
else
docker-compose -f fstack/listmonk/docker-compose.yml -p listmonk up --build -d &> /dev/null
# Keep trying listmonk port 9000 to make sure it's up
# before we proceed
RETRY="30"
while [ $RETRY -gt 0 ]; do
nc -z 172.99.0.39 9000 &> /dev/null
if [ $? -eq 0 ]; then
break
else
if [ "$RETRY" == 1 ]; then
docker-compose -f fstack/listmonk/docker-compose.yml -p listmonk down &> /dev/null
kill -9 $SPINPID &> /dev/null
fail "There was a problem starting service fstack/listmonk\nCheck the output of 'docker logs listmonk' or turn on\ndebug with -d"
fi
((RETRY--))
sleep 7
fi
done
fi
kill -9 $SPINPID &> /dev/null
echo -ne "done."
}