@@ -0,0 +1,34 @@
|
||||
[Unit]
|
||||
# Description is a human-readable name for the service.
|
||||
Description=Gardomatic API service
|
||||
|
||||
# Wait until PostgreSQL is running and the network is "up" before starting the service.
|
||||
After=postgresql.service
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
# Configure service start rate limiting. If the service is (re)started more than 5 times
|
||||
# in 600 seconds then don't permit it to start anymore.
|
||||
StartLimitIntervalSec=600
|
||||
StartLimitBurst=5
|
||||
|
||||
[Service]
|
||||
# Execute the API binary as the gardomatic user, loading its dedicated environment file
|
||||
# and using its writable state directory.
|
||||
Type=exec
|
||||
User=gardomatic
|
||||
Group=gardomatic
|
||||
EnvironmentFile=/etc/gardomatic/gardomatic.env
|
||||
WorkingDirectory=/var/lib/gardomatic
|
||||
ExecStart=/usr/local/bin/gardomatic-api
|
||||
|
||||
# Automatically restart the service after a 5-second wait if it exits with a non-zero
|
||||
# exit code. If it restarts more than 5 times in 600 seconds, then the rate limit we
|
||||
# configured above will be hit and it won't be restarted anymore.
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
# Start the service automatically at boot time (the 'multi-user.target' describes a boot
|
||||
# state when the system will accept logins).
|
||||
WantedBy=multi-user.target
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
# Installs artifacts uploaded by `make production/deploy`. Run as root or as an
|
||||
# administrator with passwordless sudo.
|
||||
if [[ $(id -u) -ne 0 ]]; then
|
||||
exec sudo -n "$0" "$@"
|
||||
fi
|
||||
|
||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
||||
APPLICATION_DIR=/opt/gardomatic
|
||||
STATE_DIR=/var/lib/gardomatic
|
||||
ENV_FILE=/etc/gardomatic/gardomatic.env
|
||||
|
||||
required_files=(
|
||||
api
|
||||
web
|
||||
cli
|
||||
api.service
|
||||
web.service
|
||||
create-admin.sh
|
||||
)
|
||||
for file in "${required_files[@]}"; do
|
||||
[[ -f "$SCRIPT_DIR/$file" ]] || {
|
||||
printf 'Missing deployment artifact: %s\n' "$file" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
[[ -d "$SCRIPT_DIR/migrations" ]] || {
|
||||
printf 'Missing deployment artifact: migrations\n' >&2
|
||||
exit 1
|
||||
}
|
||||
[[ -f "$ENV_FILE" ]] || {
|
||||
printf 'Missing runtime configuration: %s; run production/provision first.\n' "$ENV_FILE" >&2
|
||||
exit 1
|
||||
}
|
||||
id gardomatic >/dev/null 2>&1 || {
|
||||
printf 'Missing service user gardomatic; run production/provision first.\n' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
install -d -m 0755 -o root -g root "$APPLICATION_DIR"
|
||||
install -d -m 0750 -o gardomatic -g gardomatic "$STATE_DIR"
|
||||
install -m 0755 -o root -g root "$SCRIPT_DIR/api" /usr/local/bin/gardomatic-api
|
||||
install -m 0755 -o root -g root "$SCRIPT_DIR/web" /usr/local/bin/gardomatic-web
|
||||
install -m 0755 -o root -g root "$SCRIPT_DIR/cli" /usr/local/bin/gardomatic-cli
|
||||
install -d -m 0755 -o root -g root "$APPLICATION_DIR/migrations"
|
||||
rsync --archive --delete "$SCRIPT_DIR/migrations/" "$APPLICATION_DIR/migrations/"
|
||||
|
||||
install -m 0644 -o root -g root "$SCRIPT_DIR/api.service" /etc/systemd/system/api.service
|
||||
install -m 0644 -o root -g root "$SCRIPT_DIR/web.service" /etc/systemd/system/web.service
|
||||
install -m 0755 -o root -g root "$SCRIPT_DIR/create-admin.sh" /usr/local/sbin/gardomatic-create-admin
|
||||
|
||||
# provision-server.sh writes a file compatible with systemd and Bash. Loading it
|
||||
# here keeps the database DSN out of command-line arguments and process listings.
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source "$ENV_FILE"
|
||||
set +a
|
||||
migrate -path "$APPLICATION_DIR/migrations" -database "$GARDOMATIC_DB_DSN" up
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable api web
|
||||
systemctl restart api web
|
||||
|
||||
printf 'Gardomatic deployment complete.\n'
|
||||
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Gardomatic web service
|
||||
After=network-online.target api.service
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=gardomatic
|
||||
Group=gardomatic
|
||||
EnvironmentFile=/etc/gardomatic/gardomatic.env
|
||||
WorkingDirectory=/var/lib/gardomatic
|
||||
ExecStart=/usr/local/bin/gardomatic-web
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user