# Mosaic Discord connector, one instance per binding: mosaic-discord@<binding>.
# Rendered by scripts/discord-service.sh from packages/discord/systemd/;
# /mnt/storage/src/mosaic-stack-rocko-114 and /usr/local/bin:/usr/bin:/bin are filled in at install time. Edit the template and
# reinstall; do not edit the installed copy.
[Unit]
Description=Mosaic Discord connector (%i)
Documentation=file:///mnt/storage/src/mosaic-stack-rocko-114/packages/discord/README.md
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=600
StartLimitBurst=5

[Service]
Type=simple
WorkingDirectory=/mnt/storage/src/mosaic-stack-rocko-114
Environment=PATH=/usr/local/bin:/usr/bin:/bin
# A supervised run first clears a lock left by a crash or a reboot, and
# refuses with exit 3 while STOP is present or the binding is held. Exit 3
# is never retried: the brake belongs to the operator. This happens inside
# the main process on purpose: systemd honours RestartPreventExitStatus only
# for the main process, so a refusing ExecStartPre would loop.
ExecStart=/mnt/storage/src/mosaic-stack-rocko-114/scripts/discord.sh run %i --supervised
# `systemctl --user reload` re-reads the binding in place (channels, users,
# limits); the connector refuses and keeps the old binding when the file is
# invalid or a fixed key changed. See reloads.jsonl under the journal.
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=15
RestartPreventExitStatus=3
# `systemctl --user stop` sends SIGTERM; the connector finishes the turn in
# flight, then exits 0. The stop timeout covers the largest turn timeout a
# binding may set (3600 s) plus margin; a normal stop takes seconds.
KillSignal=SIGTERM
KillMode=mixed
TimeoutStopSec=3700
NoNewPrivileges=yes

[Install]
WantedBy=default.target
