self host NTFY

Installing Self Host NTFY On Linux Using Docker Container

The NTFY generally stands for “Notify”, a 100% free or opensource and created by Phillipp Heckel. REST-API-based publish-subscribe notification service (using simple HTTP PUT or POST requests) ; a utility that lets you send push notifications to your mobile phone or desktop via scripts from any computer.

It supports shell integration with popular Linux shells such as bash and zsh; It also offers features for process, emjoi, XMPP, Telegram, Instapush and Slack notification support.

Lets assumed that you have already installed and running Docker service in your system.

Install NTFY

Host network
Executing the command line below will create a container for ntfy that uses host network:

docker run -d --name=ntfy --restart=always --network=host \
-v /opt/ntfy/cache:/var/cache/ntfy \
binwiederhier/ntfy serve --cache-file /var/cache/ntfy/cache.db

User-defined bridge network
User-defined bridge network can be used for listening on different port using -p option

docker network create app-net
docker run -d --name=ntfy --restart=always --network=app-net \
-p 8089:80 \
-v /opt/ntfy/cache:/var/cache/ntfy \
binwiederhier/ntfy serve --cache-file /var/cache/ntfy/cache.db

Using docker-compose with non-root user and healthchecks enabled:

version: "2.3"
services:
ntfy:
image: binwiederhier/ntfy
container_name: ntfy
command:
- serve
environment:
- TZ=UTC # optional: set desired timezone
user: UID:GID # optional: replace with your own user/group or uid/gid
volumes:
- /var/cache/ntfy:/var/cache/ntfy
- /etc/ntfy:/etc/ntfy
ports:
- 8089:80
healthcheck: # optional: remember to adapt the host:port to your environment
test: ["CMD-SHELL", "wget -q --tries=1 http://localhost:80/v1/health -O - | grep -Eo '\"healthy\"\\s*:\\s*true' || exit 1"]
interval: 60s
timeout: 10s
retries: 3
start_period: 40s
restart: unless-stopped

If using a non-root user when running the docker version, be sure to chown the server.yml, user.db, and cache.db files and attachments directory to the same uid/gid.

Alternatively, you may wish to build a customized Docker image that can be run with fewer command-line arguments and without delivering the configuration file separately.

FROM binwiederhier/ntfy
COPY server.yml /etc/ntfy/server.yml
ENTRYPOINT ["ntfy", "serve"]


Accessing And Testing NTFY

To access web UI, open a web browser and go to http://<HOST_IP_ADDRESS>:<PORT>

access-ntfy
access ntfy
config-ntfy
config ntfy
access-subscribed
access subscribed

Once you have accessed the url and done the basic configuration based on the sample screenshot above, you may now publish topic or test message notification using sample scripts below (curl and php).

Example1: Command line (curl)

curl \
-d "HELLOWORLD PINOYLINUX.ORG" \
https://localhost:8089/RockITPinoyNotifications

Example2: PHP

file_get_contents('https://localhost:8089/RockITPinoyNotifications', false, stream_context_create([
'http' => [
'method' => 'POST', // PUT also works
'header' =>
'Content-Type: text/plain\r\n' .
'content' => 'HELLOWORLD PINOYLINUX.ORG'
]
]));

Example3: RSYNC

rsync -rvapl --numeric-ids --progress ad***@pi********.org/home/admin/* . \
&& zfs snapshot ... \
&& curl -H prio:low -d "Server backup succeeded" ntfy.sh/adminfolderbackups \
|| curl -H tags:warning -H prio:high -d "Server backup failed" ntfy.sh/adminfolderbackups

 

Uninstall NTFY
To completely remove ntfy, remove its container:

docker rm --force ntfy

Remove ntfy image:

docker rmi binwiederhier/ntfy

You can also remove ntfy data:

sudo rm -rf /opt/ntfy

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Reference:

https://ntfy.sh/
https://www.docker.com/

rockitpinoy
rockitpinoy
Articles: 10

Leave a Reply

Your email address will not be published. Required fields are marked *

Protected by CleanTalk Anti-Spam