vladionescu / keybase-gitea-bot

Based on Keybase's Gitlab bot. Notifications in Keybase Teams for Gitea, using webhooks.
MIT License
3 stars 3 forks source link

Add systemd service support #3

Open vladionescu opened 3 years ago

vladionescu commented 3 years ago

I'm running this in an instance as a systemd service. It works out of the box as a simple service (https://wiki.archlinux.org/index.php/systemd#Service_types) so it would be nice to include a ready to use service file in this repo.

I'm not pushing my file right now because it has my username and home directory hardcoded. Ideally the bot would drop privs and run anywhere.

vladionescu commented 3 years ago

These need to be cleaned up and packaged nicely:

keybase-gitea-bot.service

[Unit]
Description=Keybase Gitea bot
After=network.target
StartLimitIntervalSec=60

[Service]
Type=simple
User=vlad
Group=vlad
Restart=on-failure
RestartSec=10
WorkingDirectory=/home/vlad
ExecStart=/home/vlad/run_bot.sh
SyslogIdentifier=keybase-gitea-bot

[Install]
WantedBy=multi-user.target

run_bot.sh

#!/bin/bash
set -e

HOSTNAME=http://$(curl http://169.254.169.254/0.1/meta-data/hostname)
DBUSER=giteabot
DBPASS=
DBHOST=
DB=giteabot
GITEA_URL=http://git.example.com

WEBHOOKSECRET=
CONVID=
KEYBASE_USER=giteabot

if [[ $(keybase whoami) == $KEYBASE_USER ]]; then
        ~/go/bin/keybase-gitea-bot --http-prefix "$HOSTNAME:80
80" \
        --gitea-url "$GITEA_URL" \
        --dsn "$DBUSER:$DBPASS@tcp($DBHOST:3306)/$DB" \
        --secret $WEBHOOKSECRET \
        --announcement "$CONVID" --err-report-conv "$CONVID"
else
        echo "Keybase user $(keybase whoami) is logged in, expecting $KEYBASE_USER. Failed to start bot."
fi