Files
proxmox-lxc-shell-commands/proxmox-lxc-listmonk.sh
DevOps 200be91ec1 feat: 6개 LXC 설치 스크립트 추가 (배치 4)
- proxmox-lxc-plausible.sh: 웹 분석 (ClickHouse + PostgreSQL)
- proxmox-lxc-listmonk.sh: 이메일 마케팅 (PostgreSQL)
- proxmox-lxc-linkwarden.sh: 북마크 관리 (PostgreSQL)
- proxmox-lxc-stirling-pdf.sh: PDF 도구
- proxmox-lxc-uptime-kuma.sh: 서비스 모니터링
- proxmox-lxc-paperless-ngx.sh: 문서 관리 (PostgreSQL + Redis + OCR)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-06 00:22:21 +09:00

251 lines
8.3 KiB
Bash

#!/usr/bin/env bash
# Listmonk LXC Installation Script
# Description: Self-hosted newsletter and mailing list manager
# OS: Debian 12 (Bookworm)
# Ports: Web UI: 9000
# Repository: https://github.com/knadh/listmonk
# Last Updated: 2026-01-06
set -euo pipefail
CT_ID=${CT_ID:-29002}
CT_HOSTNAME=${CT_HOSTNAME:-"listmonk"}
CT_CORES=${CT_CORES:-1}
CT_MEMORY=${CT_MEMORY:-1024}
CT_SWAP=${CT_SWAP:-512}
CT_DISK_SIZE=${CT_DISK_SIZE:-10}
CT_IP=${CT_IP:-"dhcp"}
CT_GATEWAY=${CT_GATEWAY:-""}
CT_BRIDGE=${CT_BRIDGE:-"vmbr0"}
CT_NAMESERVER=${CT_NAMESERVER:-"8.8.8.8"}
CT_STORAGE=${CT_STORAGE:-"local-lvm"}
TEMPLATE_STORAGE=${TEMPLATE_STORAGE:-"local"}
DEBIAN_VERSION="12"
TEMPLATE_NAME=""
LISTMONK_PORT=${LISTMONK_PORT:-9000}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-"$(openssl rand -base64 24 | tr -dc 'a-zA-Z0-9' | head -c 20)"}
ADMIN_USER=${ADMIN_USER:-"admin"}
ADMIN_PASSWORD=${ADMIN_PASSWORD:-"$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 12)"}
CT_ONBOOT=${CT_ONBOOT:-1}
CT_UNPRIVILEGED=${CT_UNPRIVILEGED:-0}
CT_FEATURES=${CT_FEATURES:-"keyctl=1,nesting=1"}
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; }
check_root() { [[ $EUID -ne 0 ]] && error "Run as root" && exit 1; }
check_proxmox() { command -v pct &>/dev/null || { error "Run on Proxmox VE host"; exit 1; }; }
check_container_exists() { pct status "$CT_ID" &>/dev/null && { error "Container $CT_ID exists"; exit 1; }; }
detect_and_download_template() {
info "Updating template database..."
pveam update 2>&1 || true
local available_template
available_template=$(pveam available --section system 2>/dev/null | grep "debian-${DEBIAN_VERSION}" | grep "standard" | tail -1 | awk '{print $2}')
[[ -z "$available_template" ]] && error "No Debian ${DEBIAN_VERSION} template found" && exit 1
TEMPLATE_NAME="$available_template"
info "Found template: $TEMPLATE_NAME"
pveam list "$TEMPLATE_STORAGE" 2>/dev/null | grep -q "$TEMPLATE_NAME" || pveam download "$TEMPLATE_STORAGE" "$TEMPLATE_NAME" 2>&1
success "Template ready"
}
create_container() {
info "Creating LXC container $CT_ID ($CT_HOSTNAME)..."
local net_config="name=eth0,bridge=${CT_BRIDGE},ip=${CT_IP}"
[[ "$CT_IP" != "dhcp" ]] && [[ -n "$CT_GATEWAY" ]] && net_config="${net_config},gw=${CT_GATEWAY}"
pct create "$CT_ID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE_NAME}" \
--hostname "$CT_HOSTNAME" --cores "$CT_CORES" --memory "$CT_MEMORY" --swap "$CT_SWAP" \
--rootfs "${CT_STORAGE}:${CT_DISK_SIZE}" --net0 "$net_config" --nameserver "$CT_NAMESERVER" \
--onboot "$CT_ONBOOT" --unprivileged "$CT_UNPRIVILEGED" --features "$CT_FEATURES" --ostype debian || exit 1
success "Container created"
}
start_container() {
info "Starting container..."
pct start "$CT_ID" && sleep 5
success "Container started"
}
install_docker() {
info "Installing Docker..."
pct exec "$CT_ID" -- bash -c "apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq ca-certificates curl gnupg"
pct exec "$CT_ID" -- bash -c "install -m 0755 -d /etc/apt/keyrings && curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && chmod a+r /etc/apt/keyrings/docker.asc"
pct exec "$CT_ID" -- bash -c 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null'
pct exec "$CT_ID" -- bash -c "apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
pct exec "$CT_ID" -- bash -c "systemctl enable docker && systemctl start docker"
sleep 3
success "Docker installed"
}
install_listmonk() {
info "Installing Listmonk..."
pct exec "$CT_ID" -- bash -c "mkdir -p /opt/listmonk/{postgres,uploads}"
pct exec "$CT_ID" -- bash -c "cat > /opt/listmonk/docker-compose.yml << 'EOF'
services:
listmonk:
image: listmonk/listmonk:latest
container_name: listmonk
restart: always
ports:
- \"\${LISTMONK_PORT:-9000}:9000\"
environment:
- TZ=Asia/Seoul
volumes:
- ./config.toml:/listmonk/config.toml
- ./uploads:/listmonk/uploads
depends_on:
postgres:
condition: service_healthy
networks:
- listmonk-network
postgres:
image: postgres:15-alpine
container_name: listmonk-postgres
restart: always
environment:
POSTGRES_USER: listmonk
POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}
POSTGRES_DB: listmonk
volumes:
- ./postgres:/var/lib/postgresql/data
healthcheck:
test: [\"CMD-SHELL\", \"pg_isready -U listmonk -d listmonk\"]
interval: 10s
timeout: 5s
retries: 5
networks:
- listmonk-network
networks:
listmonk-network:
driver: bridge
EOF"
pct exec "$CT_ID" -- bash -c "cat > /opt/listmonk/.env << 'EOF'
LISTMONK_PORT=${LISTMONK_PORT}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
EOF"
pct exec "$CT_ID" -- bash -c "cat > /opt/listmonk/config.toml << 'EOF'
[app]
address = \"0.0.0.0:9000\"
admin_username = \"${ADMIN_USER}\"
admin_password = \"${ADMIN_PASSWORD}\"
[db]
host = \"postgres\"
port = 5432
user = \"listmonk\"
password = \"${POSTGRES_PASSWORD}\"
database = \"listmonk\"
ssl_mode = \"disable\"
max_open = 25
max_idle = 25
max_lifetime = \"300s\"
EOF"
info "Starting Listmonk containers..."
pct exec "$CT_ID" -- bash -c "cd /opt/listmonk && docker compose up -d postgres" 2>&1
sleep 10
info "Initializing database..."
pct exec "$CT_ID" -- bash -c "cd /opt/listmonk && docker compose run --rm listmonk ./listmonk --install --yes" 2>&1 || true
pct exec "$CT_ID" -- bash -c "cd /opt/listmonk && docker compose up -d" 2>&1
info "Waiting for Listmonk to start..."
local max_attempts=30
local attempt=1
while [[ $attempt -le $max_attempts ]]; do
if pct exec "$CT_ID" -- bash -c "curl -s -o /dev/null -w '%{http_code}' http://localhost:${LISTMONK_PORT}/" | grep -q "200\|302"; then
success "Listmonk is running!"
break
fi
echo -n "."
sleep 3
((attempt++))
done
echo ""
success "Listmonk installed"
}
create_service() {
pct exec "$CT_ID" -- bash -c 'cat > /etc/systemd/system/listmonk.service << EOF
[Unit]
Description=Listmonk Newsletter Manager
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/listmonk
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
TimeoutStartSec=180
[Install]
WantedBy=multi-user.target
EOF'
pct exec "$CT_ID" -- bash -c "systemctl daemon-reload && systemctl enable listmonk"
success "Listmonk service created"
}
verify_installation() {
local container_ip
container_ip=$(pct exec "$CT_ID" -- bash -c "hostname -I | awk '{print \$1}'" 2>/dev/null || echo "unknown")
echo ""
echo "================================================================"
echo -e "${GREEN}Listmonk Installation Complete!${NC}"
echo "================================================================"
echo "Container ID: $CT_ID | Hostname: $CT_HOSTNAME | IP: $container_ip"
echo ""
echo "Web UI: http://${container_ip}:${LISTMONK_PORT}"
echo ""
echo "Admin Credentials:"
echo " Username: ${ADMIN_USER}"
echo " Password: ${ADMIN_PASSWORD}"
echo ""
echo "Next steps:"
echo " 1. Configure SMTP settings for sending emails"
echo " 2. Create your first mailing list"
echo " 3. Import subscribers or create a signup form"
echo ""
echo "Data location: /opt/listmonk"
echo "================================================================"
}
main() {
echo "================================================================"
echo "Listmonk LXC Installation Script"
echo "================================================================"
check_root
check_proxmox
check_container_exists
detect_and_download_template
create_container
start_container
install_docker
install_listmonk
create_service
verify_installation
}
main "$@"