Discord Notifications from Systemd

Add the following lines in your service definition file (/etc/systemd/system/service_xyz.service) in the [Service] section:

1
2
ExecStartPost=/home/service_xyz/hooks.sh start
ExecStopPost=/home/service_xyz/hooks.sh stop

In /home/service_xyz/hooks.sh, put

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

hook_url=https://discord.com/api/webhooks/xxxxxxxxxxxx/yyyyyyyyyy

case "$1" in
 start)
  curl -H "Content-type: application/json" \
  -X POST -d \
  '{
    "content":"Hook: <NAME>; Action Start"
  }' $hook_url
   ;;
 stop)
  curl -H "Content-type: application/json" \
  -X POST -d \
  '{
    "content":"Hook: <NAME>; Action Stop"
  }' $hook_url
   ;;
esac

exit 0   

Read Next

I’m running an experiment for better content recommendations. These are the 3 posts that are most likely to be interesting for you:

  • The secret life of .well-known
    Exploring the .well-known directory’s vast applications can be a game-changer for you, especially if you’re keen on optimizing web server functionalities, much like how you’ve learned to enhance service notifications with systemd for Discord.

  • Start a container in a particular docker network
    If you’re jazzed about streamlining your service notifications with Discord, this next piece on effortlessly spinning up Docker containers could be your next tech hack to master!

  • Fix WSL time drift
    Keep your development environment in perfect sync; after setting up Discord notifications for service status, ensure your WSL2 VM clock doesn’t fall behind with a simple fix, avoiding potential timestamp and SSL headaches.

All content is licensed under CC BY-NC-SA 4.0. Copying is an act of love - please copy!
More cool websites: Prev | Hotline Webring | Next
Built with Hugo
Theme Stack designed by Jimmy