Add systemd unit, example config, and deb packaging

This commit is contained in:
Andrey Kutin 2026-07-03 09:44:39 +03:00
parent 99e0c2387a
commit ca9912f8de
5 changed files with 91 additions and 1 deletions

View File

@ -55,6 +55,15 @@ set_target_properties(cards PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
) )
# ─── Install ──────────────────────────────────────────────────────────
install(TARGETS cards DESTINATION /usr/bin)
install(FILES deploy/systemd/cards.service DESTINATION /usr/lib/systemd/system)
install(FILES deploy/config/cards.json.example DESTINATION /etc/cards)
install(FILES LICENSE DESTINATION /usr/share/doc/cards)
# ─── Packaging (CPack) ──────────────────────────────────────────────── # ─── Packaging (CPack) ────────────────────────────────────────────────
set(CPACK_PACKAGE_NAME "cards") set(CPACK_PACKAGE_NAME "cards")
set(CPACK_PACKAGE_VERSION "1.0.0") set(CPACK_PACKAGE_VERSION "1.0.0")
@ -62,13 +71,20 @@ set(CPACK_PACKAGE_VENDOR "cards")
set(CPACK_PACKAGE_MAINTAINER "root") set(CPACK_PACKAGE_MAINTAINER "root")
set(CPACK_PACKAGE_CONTACT "root@localhost") set(CPACK_PACKAGE_CONTACT "root@localhost")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cards web server") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cards web server")
set(CPACK_PACKAGE_DESCRIPTION "A simple C++20 web server for cards") set(CPACK_PACKAGE_DESCRIPTION "A simple C++20 web server powered by Boost.Beast and PostgreSQL")
set(CPACK_PACKAGE_SECTION "web") set(CPACK_PACKAGE_SECTION "web")
set(CPACK_DEBIAN_PACKAGE_SECTION "web") set(CPACK_DEBIAN_PACKAGE_SECTION "web")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_DEPENDS set(CPACK_DEBIAN_PACKAGE_DEPENDS
"libpqxx-7.0 (>= 7.0), libpq5 (>= 13), libstdc++6 (>= 10), libgcc-s1" "libpqxx-7.0 (>= 7.0), libpq5 (>= 13), libstdc++6 (>= 10), libgcc-s1"
) )
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${CMAKE_SOURCE_DIR}/deploy/deb/postinst"
"${CMAKE_SOURCE_DIR}/deploy/deb/prerm"
)
set(CPACK_DEBIAN_FILE_NAME "cards-${CPACK_PACKAGE_VERSION}-Linux.deb") set(CPACK_DEBIAN_FILE_NAME "cards-${CPACK_PACKAGE_VERSION}-Linux.deb")
set(CPACK_GENERATOR "DEB") set(CPACK_GENERATOR "DEB")

View File

@ -0,0 +1,14 @@
{
"server": {
"address": "0.0.0.0",
"port": 8080,
"threads": 4
},
"database": {
"host": "localhost",
"port": 5432,
"dbname": "cards",
"user": "cards",
"password": ""
}
}

28
deploy/deb/postinst Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
set -e
case "$1" in
configure)
# Create cards user/group if they don't exist
if ! getent group cards >/dev/null 2>&1; then
addgroup --system cards
fi
if ! getent passwd cards >/dev/null 2>&1; then
adduser --system --ingroup cards --no-create-home --disabled-password cards
fi
# Copy default config if not present
if [ ! -f /etc/cards/config.json ]; then
cp /etc/cards/config.json.example /etc/cards/config.json
chown cards:cards /etc/cards/config.json
chmod 640 /etc/cards/config.json
fi
# Enable and restart service
if [ -d /run/systemd/system ]; then
systemctl daemon-reload >/dev/null 2>&1 || true
systemctl enable cards >/dev/null 2>&1 || true
systemctl restart cards >/dev/null 2>&1 || true
fi
;;
esac

11
deploy/deb/prerm Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
set -e
case "$1" in
remove|upgrade|deconfigure)
if [ -d /run/systemd/system ]; then
systemctl stop cards >/dev/null 2>&1 || true
systemctl disable cards >/dev/null 2>&1 || true
fi
;;
esac

View File

@ -0,0 +1,21 @@
[Unit]
Description=Cards web server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=cards
Group=cards
ExecStart=/usr/bin/cards /etc/cards/config.json
Restart=on-failure
RestartSec=5
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=yes
ProtectSystem=full
ProtectHome=yes
PrivateTmp=yes
MemoryDenyWriteExecute=yes
[Install]
WantedBy=multi-user.target