umorpha-boxes/modules/service-avatard.sh

61 lines
1.5 KiB
Bash

#!/hint/bash -euE
# Copyright (C) 2024 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
load_module "$(dirname -- "${BASH_SOURCE[0]}")/base-nginx.sh"
post_install+=(20:avatard:post_install)
avatard:post_install() {
local arg_mountpoint=$1
install -Dm644 /dev/stdin "$arg_mountpoint/etc/nginx/sites/avatars.conf" <<-'EOF'
# -*- mode: nginx; nginx-indent-level: 4; intent-tabs-mode: nil -*-
server {
server_name avatars.mothstuff.lol;
include /etc/nginx/snippets/listen.conf;
location / {
proxy_pass http://unix:/run/avatard.socket;
}
}
EOF
install -Dm644 /dev/stdin "$arg_mountpoint/etc/sysusers.d/avatard.conf" <<-'EOF'
u avatard avatard "avatard user"
EOF
install -Dm644 /dev/stdin "$arg_mountpoint/etc/systemd/system/avatard.socket" <<-'EOF'
# Copyright (C) 2024 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
[Unit]
Description=Umorpha profile-pic server socket
[Socket]
ListenStream=/run/avatard.socket
SocketUser=http
SocketGroup=http
SocketMode=0600
[Install]
WantedBy=sockets.target
EOF
install -Dm644 /dev/stdin "$arg_mountpoint/etc/systemd/system/avatard.service" <<-'EOF'
# Copyright (C) 2024 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
[Unit]
Description=Umorpha profile-pic server process
[Service]
User=avatard
Group=avatard
Type=simple
ExecStart=/usr/bin/avatard --apikey-file=/etc/umorpha-secrets/avatard-apikey.txt --socket=fd:systemd
Restart=always
EOF
systemctl --root="$arg_mountpoint" enable avatard.socket
}