Notify on boot
Sometimes its handy to send a notification on boot,
for example to send the IP address that the server has.
This script uses discord to send a message.
-
Install dependencies
-
Install discord.sh
cd /usr/local/bin
sudo curl -L -O https://github.com/fieu/discord.sh/releases/download/v2.0.0/discord.sh
sudo chmod +x discord.sh
-
Create a boot-notify.sh script to send a message
/opt/boot-notify.shIP=$(hostname -I | awk '{print $1}')
WEBHOOK_URL=<https://discord.com/api/webhooks/<webhook-url>>
discord.sh \
--webhook-url="$WEBHOOK_URL" \
--username="server" \
--text="server booted with IP $IP"
sudo chmod u+x /opt/boot-notify.sh
-
Create a boot-notify systemd task that runs after networking has started
/etc/systemd/system/boot-notify.service[Unit]
Description=Sends a message over discord at startup
After=network-online.target
[Service]
Type=simple
ExecStart=/bin/bash /opt/boot-notify.sh
[Install]
WantedBy=multi-user.target
-
Test the systemd service
sudo systemctl daemon-reload
sudo systemctl start boot-notify
Then verify the message is received
-
Enable the systemd service
sudo systemctl enable boot-notify
Last update:
August 12, 2023
Created:
June 3, 2023