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   
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