Key Takeaways
- NTFY enables push notifications from any app, server, or system via simple HTTP requests
- Clients are available for all major platforms like Android, iOS, Windows, Linux, browsers, etc
- The server can run standalone on a Raspberry Pi or scale horizontally across nodes
The NTFY push notification server allows you to send push notifications to your phone, desktop, email, and more from the command line or via HTTP requests. In this guide, we’ll cover how to install NTFY on a Raspberry Pi and optimize it for performance, security, and ease of use.
Table of Contents
What You’ll Need To Install NTFY Push Notification Server on the Raspberry Pi
- Raspberry Pi OS installed on a Raspberry Pi
- MicroSD card with at least 2 GB storage
- Power supply for Raspberry Pi
- Ethernet cable or WiFi connectivity
Follow along below for step-by-step guidance on downloading, installing, and configuring NTFY on your Raspberry Pi.
Downloading And Installing NTFY
NTFY is available as a simple Python package that we’ll install using the pip package manager.
Log in to your Raspberry Pi and open the terminal application. Update the package repositories and install pip:
- sudo apt update
- sudo apt install python3-pip
- Use pip to install NTFY and its dependencies:
- pip3 install ntfy
- The installation process may take a few minutes to complete.
Creating a Dedicated Non-Root User
For security and organizational best practices, we should create a dedicated non-root user account to run the NTFY service:
sudo adduser ntfy
Set the password when prompted. This will create a ntfy user with a home folder at /home/ntfy.
Configuring NTFY
NTFY relies on client applications sending HTTP requests to trigger notifications. As such, we need to configure a few key settings.
Enabling the NTFY Server
By default, NTFY just runs as a local CLI application. To enable the HTTP server, edit /home/ntfy/.config/ntfy/config.yml to activate the server:
http:
enabled: true
hostname: 0.0.0.0
port: 9000
This listens on all interfaces on port 9000. Adjust the hostname and port settings if needed.
Key Takeaway: Activating the NTFY HTTP server allows API-based push notifications to your devices.
Setting Authentication Keys
For security, NTFY should be protected by authentication keys. Generate a random key:
ntfy auth add
This will add a key to config.yml. Create unique keys for each notification client that will be sending requests.
You can also revoke keys that have been compromised:
ntfy auth revoke <key>
Launching the NTFY Service
With NTFY configured, we can now launch it as a persistent background service using systemd.
Create a unit file at /etc/systemd/system/ntfy. Service with the following:
[Unit]
Description=NTFY Push Notification Service
After=network. Target
[Service]
Type=simple
User=ntfy
ExecStart=/usr/local/bin/ntfy -c /home/ntfy/.config/ntfy/config.yml serve
Restart=on-failure
[Install]
WantedBy=multi-user.target
Then enable the service:
sudo systemctl enable ntfy
sudo systemctl start ntfy
Check that it is running with systemctl status ntfy.
Configuring Firewall Rules
If using a firewall like ufw, allow traffic on port 9000:
sudo ufw allow 9000
Sending Test Notifications
We can now send notifications to NTFY from the command line.
To send a notification:
curl -d '{"title": "Hello!", "message": "NTFY is working!"}' \
-H "Content-Type: application/json" \
-X POST http://localhost:9000/?key=auth_key
Replace auth_key> with your generated authentication key.
This request will send a test notification with a title and message payload.
You should see the notification on your configured NTFY clients.
Supported Notification Clients
NTFY supports sending notifications to:
- Android
- iOS
- Desktop apps like Telegram, Discord, Slack
- Browsers
- and more
See the full list of supported apps and integrations.
Optimizing NTFY Performance
Now that NTFY is installed and running, we can take a few optional steps to improve performance.
Enabling Caching
By default, every push notification triggers a disk write in the NTFY logs. This can wear out SD cards over time.
Enable caching in the config file:
cache:
enabled: true
max_size: 10000
This will keep up to 10,000 notifications in memory before syncing logs to disk.
Monitoring Usage with pm2
The pm2 process manager can help monitor NTFY resource usage and logs:
sudo npm install -g pm2
pm2 start /usr/local/bin/ntfy -- serve -c /home/ntfy/.config/ntfy/config.yml
Configure pm2 to start on boot:
pm2 startup systemd -u ntfy --hp /home/ntfy
pm2 save
Now you can monitor metrics, logs, and easily manage NTFY processes.
Expanding the System
A single NTFY instance works well for personal use cases with reliable performance for hundreds of daily notifications.
If your needs outgrow a single Raspberry Pi, the system can scale out horizontally with load balancing:
- Create multiple backend servers each running an NTFY instance
- Put a load balancer like Nginx in front to distribute notifications
- Scale capacity by adding more backend nodes
Additionally, enable Redis or PostgreSQL support in NTFY for a persistent event queue and synchronization across multiple workers.
Conclusion
By following this guide, you should now have the NTFY notification server running on your Raspberry Pi device. NTFY provides a flexible infrastructure for sending push alerts to your devices through easy HTTP requests and hooks into various communication channels.
Tune the performance settings based on your usage needs and number of daily notifications expected. The system can scale out to multiple nodes to grow capacity as required.
With NTFY handling message dispatching and delivery, you can focus on creating triggers and alerts tailored to your projects.
Frequently Asked Questions
Q: What type of notifications can NTFY send?
A. NTFY supports text-based messages with titles and body content. Some client apps may have expanded formatting.
Q: How many notifications can NTFY handle per day?
A. A single node can reliably handle ~500 daily notifications. Enable caching and scale horizontally to send more.
Q: Is there a public hosted version of NTFY?
A. Anthropic provides a hosted API for sending notifications at https://ntfy.sh with a free tier.
Q: Can I route notifications to different devices?
A. Yes, you can tag devices in the NTFY config file and target tags explicitly in requests.
Q: Does NTFY work without Internet connectivity?
A. The server requires Internet access. Some local network apps like Telegram may work over LAN only.
Q: What happens if NTFY server goes down?
A. Messages are attempted twice before being dropped. For reliability, scale horizontally and monitor uptime.
Q: Is NTFY designed to handle SMS/voice calls?
A. No – NTFY focuses specifically on sending push notifications to devices via official apps.
Q: Can I authenticate clients without generating API keys?
A. NTFY supports OAuth 2 authentication if you configure an OAuth provider.
Q: What languages is NTFY available in?
A. The server is English-only but will pass messages to clients in their configured language.
Q: Does message delivery success/failure reported?
A. NTFY confirms HTTP requests succeeded but actual delivery is handed off to clients.
Q: Can NTFY integrate with my services via API?
A. Definitely! NTFY provides webhooks and APIs for easy integration.
Q: How is NTFY different than commercial solutions?
A. NTFY is self-hosted and customizable unlike SaaS notification services.