Add systemd service with webhook notify on start/stop
This commit is contained in:
parent
36d04e6cf2
commit
83751f37ca
3 changed files with 50 additions and 12 deletions
40
README.md
40
README.md
|
@ -22,33 +22,49 @@ Copy `.env.example` to `.env`:
|
|||
- Settings > Advanced > Developer Mode: enabled
|
||||
- Right click the guild and select "Copy ID"
|
||||
|
||||
- `DISCORD_STATUS_WEBHOOK_URL` (optional) is used to monitor when the bot fails
|
||||
- Channel Settings > Integrations > New Webhook (don't forget to save changes)
|
||||
- Copy Webhook URL
|
||||
|
||||
- `DISCORD_BOT_ADMIN_ROLE_ID` for reloading cogs
|
||||
- `DISCORD_BOT_ADMIN_USER_ID` for reloading cogs
|
||||
- `DISCORD_VCJOIN_CHANNEL` for the VCJoin cog
|
||||
|
||||
## Setup
|
||||
|
||||
### ...with PDM
|
||||
### with systemd
|
||||
|
||||
```sh
|
||||
pdm install --prod
|
||||
pdm run python app.py
|
||||
```
|
||||
mkdir -p /srv/discord
|
||||
cd /srv/discord
|
||||
|
||||
### ...with requirements.txt and virtualenv
|
||||
sudo useradd --system -s /srv/discord discord
|
||||
sudo chown -R discord:discord /srv/discord
|
||||
|
||||
```sh
|
||||
virtualenv .venv
|
||||
source .venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
python app.py
|
||||
sudo -Hu discord git clone https://git.trwnh.com/a/umi.git
|
||||
|
||||
python -m venv .venv
|
||||
.venv/bin/pip install -r umi/requirements.txt
|
||||
|
||||
sudo cp umi/umi@.service /etc/systemd/system/umi@.service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl start umi@umi
|
||||
```
|
||||
|
||||
### ...with Docker Compose
|
||||
|
||||
```sh
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
mkdir -p /srv/discord
|
||||
cd /srv/discord
|
||||
|
||||
sudo useradd --system -s /srv/discord discord
|
||||
sudo chown -R discord:discord /srv/discord
|
||||
|
||||
sudo -Hu discord git clone https://git.trwnh.com/a/umi.git
|
||||
|
||||
cd umi
|
||||
sudo docker compose build
|
||||
sudo docker compose up -d
|
||||
```
|
||||
|
||||
## Log into YouTube
|
||||
|
|
7
contrib/notify.sh
Normal file
7
contrib/notify.sh
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
curl \
|
||||
-X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username": "system", "content": "'"$1"'"}' \
|
||||
$DISCORD_STATUS_WEBHOOK_URL
|
15
contrib/umi@.service
Normal file
15
contrib/umi@.service
Normal file
|
@ -0,0 +1,15 @@
|
|||
[Unit]
|
||||
Description=Discord bot for logging VC joins and playing music
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Restart=on-failure
|
||||
User=discord
|
||||
WorkingDirectory=/srv/discord/%I
|
||||
EnvironmentFile=/srv/discord/%I/.env
|
||||
ExecStart=/srv/discord/.venv/bin/python -u app.py
|
||||
ExecStopPost=/srv/discord/%I/notify.sh "umi instance stopped: `%i`"
|
||||
ExecStartPost=/srv/discord/%I/notify.sh "umi instance started: `%i`"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Add table
Reference in a new issue