add listmonk app

This commit is contained in:
2026-02-06 18:36:15 +01:00
parent 3d6793a843
commit 905cc8b43d
12 changed files with 351 additions and 2 deletions

View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -euo pipefail
source /opt/environment/.env
TIMESTAMP=$(date +'%Y-%m-%d_%H%M%S')
systemctl stop listmonk
sudo -u $USERNAME pg_dump -Fc -U $DB_USER $DB_NAME > $SERVICE_BACKUPS_DIR/$SERVICE_BACKUPS_PREFIX-$TIMESTAMP.$SERVICE_BACKUPS_EXTENSION
systemctl start listmonk
ls -1dt $SERVICE_BACKUPS_DIR/$SERVICE_BACKUPS_PREFIX-*.$SERVICE_BACKUPS_EXTENSION | tail -n +5 | xargs -r rm -f

View File

@@ -0,0 +1,53 @@
#!/bin/bash
#LISTMONK_BINARY=/usr/local/bin/listmonk
#LISTMONK_VERSION=6.0.0
#LISTMONK_CONFIG=/home/listmonk/config.toml
#DB_USER
#DB_PASS
#DB_NAME
set -euo pipefail
source /opt/environment/.env
# Listmonk binary
if [ ! -f $LISTMONK_BINARY ]; then
wget -O /tmp/listmonk.tar.gz "https://github.com/knadh/listmonk/releases/download/v${LISTMONK_VERSION}/listmonk_${LISTMONK_VERSION}_linux_amd64.tar.gz"
mkdir /tmp/listmonk
tar -xzf /tmp/listmonk.tar.gz -C /tmp/listmonk
mv /tmp/listmonk/listmonk $LISTMONK_BINARY
chmod +x $LISTMONK_BINARY
fi
# Listmonk config
cat > $LISTMONK_CONFIG <<EOF
[app]
address = "0.0.0.0:9000"
[db]
host = "localhost"
port = 5432
user = "$DB_USER"
password = "$DB_PASS"
database = "$DB_NAME"
ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"
EOF
# Listmonk pgsql init db
sudo -u postgres psql <<EOF
CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';
CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
EOF
$LISTMONK_BINARY --install --config $LISTMONK_CONFIG --yes
systemctl start restore-backup.service
systemctl daemon-reload
systemctl enable listmonk
systemctl start listmonk

View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -euo pipefail
source /opt/environment/.env
LATEST_BACKUP=$(ls -1 $SERVICE_BACKUPS_DIR/$SERVICE_BACKUPS_PREFIX-*.$SERVICE_BACKUPS_EXTENSION 2>/dev/null | sort | tail -n1)
if [ -n "$LATEST_BACKUP" ] && [ -f "$LATEST_BACKUP" ]; then
systemctl stop listmonk
sudo -u $USERNAME pg_restore --clean --if-exists -U "$DB_USER" -d "$DB_NAME" $LATEST_BACKUP
systemctl start listmonk
fi

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Backup Service
Wants=network.target
After=network.target postgresql.service
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/backup.sh

View File

@@ -0,0 +1,15 @@
[Unit]
Description=listmonk mailing list and newsletter manager (%I)
ConditionPathExists=/home/listmonk/config.toml
Wants=network.target
After=postgresql.service
[Service]
Type=simple
ExecStartPre=/usr/local/bin/listmonk --config /home/listmonk/config.toml --upgrade --yes
ExecStart=/usr/local/bin/listmonk --config /home/listmonk/config.toml
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Restore latest backup
After=network.target postgresql.service
Requires=postgresql.service
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/restore-backup.sh