Making your wrist vibrate if your server goes down
If you read my earlier post, you'd know I was grappling with a bruteforce attack (which manifested as a DDOS) over the last couple of weeks. I'm not sure if I mentioned it in the post, but it was taking my server down a couple of times a day with it. As part of my debugging process I had set a log for the halt command that was triggered, recording a wealthy amount of data for everything that had happened in the moments leading up to the server being taken offline. Eventually this proved worthless as I couldn't figure out why init was giving the order to halt, but I did gain something else out of it: my wrist now vibrates if my server ever goes down.
I have a Xiaomi Mi Band, and one of the benefits is that you can set it to vibrate in the intensity you want and flash in a color of your choosing based on notifications from your phone. This is achieved using either one of the aftermarket companion apps, or a semi-official modified Mi Fit APK. I've personally set up a number of different notifcations, including independent notifications for my Gmail accounts, SMS, WhatsApp, Agent, and a couple of others. So I thought "hey, why not configure my server to send a notification to my phone, then pair that notification with the Mi Band, so that my wrist will vibrate if it ever goes down!" -- and so it began.
The process isn't too difficult:
- Sign up for an account at Airgram -- a free service for pushing notifications, download the APK for your phone and log in.
Open a terminal and, with root privileges, type the following into the terminal:
mv /sbin/halt /sbin/halt.orig
touch /sbin/halt
nano /sbin/halt
This will rename the original halt script into halt.orig, then create a new halt file which we will use to intercept the shutdown procedure, and then allow us to edit the new file using nano.
Inside the new /sbin/halt, add
#!/bin/bash
TODAY=$(date)
curl https://api.airgramapp.com/1/send_as_guest \
--data-urlencode [email protected] \
--data-urlencode msg='Server went down at $TODAY' \
./sbin/halt.orig
Where [email protected] is the email of your Airgram account.
- Configure your Mi Band vibrate/flash for any notifications from the Airgram app.
Of course you can skip over Airgram altogether and send yourself an email instead through a bash script, but unless you send that email to a separate account and then configure a separate email app to deal only with that account, you won't be able to get notifications exclusively for the server going down.