Розгортка проектів з SystemD (чернетка)

Юніт файли для юзера (щоб запускати без рута) лежать в ~/.config/systemd/user/. Назва по типу my-app.service

Приклад юніт файлу

[Unit]
Description=My app
After=default.target

[Service]
WorkingDirectory=%h/my-app
ExecStart=/home/adam/.bun/bin/bun run start

KillSignal=SIGINT
TimeoutStopSec=10

Environment=NODE_ENV=production
EnvironmentFile=%h/my-app/.env

Type=simple
Restart=always
RestartSec=5
StartLimitInterval=10
StartLimitBurst=3

NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full

[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user start my-app
systemctl --user enable my-app

systemctl --user list-units --type=service
systemctl --user list-unit-files --type=service

journalctl --user -fn 100 -u my-app

Приклад myapp.git/hooks/post-receive

#!/usr/bin/env bash

set -euo pipefail

TARGET=~/my-app
BARE=~/git/my-app.git
BRANCH=main

unset GIT_DIR GIT_WORK_TREE

git -C "$TARGET" remote set-url origin "file://$BARE" 2>/dev/null || \
git -C "$TARGET" remote add origin "file://$BARE"

while read -r oldrev newrev ref; do
  [[ "$ref" == "refs/heads/$BRANCH" ]] || continue
  git -C "$TARGET" fetch --prune origin
  git -C "$TARGET" checkout -f "$BRANCH"
  git -C "$TARGET" reset --hard "$newrev"
  systemctl --user restart my-app.service
done