[Question] - FreeBSD Port
Hello,
Straight to the point: are there any plans to port ntfy.sh to FreeBSD?
It would be great to have this tool available there. I will try to build and run it from the sources to see what happens.
Best regards,
Ross
So,
here's what I did:
I started by reading this:
https://docs.ntfy.sh/develop/
Then I cloned the sources into the following repository:
https://github.com/rmszc81/ntfy/tree/freebsd14
I made changes in the following files:
Makefile, .goreleaser.yml
To be able to build in FreeBSD 14.
I installed the following packages in the OS:
pkg install git go goreleaser node20 npm-node20 py311-mkdocs py311-pip py311-pylint-venv
Then I ran:
make cli-freebsd-amd64, apparently it builds the application correctly, and the binary is generated at ntfy_freebsd_amd64_freebsd_amd64_v1
When I run ./dist/ntfy_freebsd_amd64_freebsd_amd64_v1/ntfy, I get the following output:
root@ntfy:/app/ntfy # ./dist/ntfy_freebsd_amd64_freebsd_amd64_v1/ntfy
NAME:
ntfy - Simple pub-sub notification service
USAGE:
ntfy [OPTION..]
COMMANDS:
help, h Shows a list of commands or help for one command
Client commands:
publish, pub, send, trigger Send message via a ntfy server
subscribe, sub Subscribe to one or more topics on a ntfy server
Server commands:
access Grant/revoke access to a topic, or show access
serve Run the ntfy server
tier Manage/show tiers
token Create, list or delete user tokens
user Manage/show users
webpush Generate keys, in the future manage web push subscriptions
GLOBAL OPTIONS:
--debug, -d
enable debug logging (default: false) [$NTFY_DEBUG]
--trace
enable tracing (very verbose, be careful) (default: false) [$NTFY_TRACE]
--no-log-dates, --no_log_dates
disable the date/time prefix (default: false) [$NTFY_NO_LOG_DATES]
--log-level value, --log_level value
set log level (default: "INFO") [$NTFY_LOG_LEVEL]
--log-level-overrides value, --log_level_overrides value [ --log-level-overrides value, --log_level_overrides value ] set log level overrides [$NTFY_LOG_LEVEL_OVERRIDES]
--log-format value, --log_format value
set log format (default: "text") [$NTFY_LOG_FORMAT]
--log-file value, --log_file value
set log file, default is STDOUT [$NTFY_LOG_FILE]
--help, -h
show help
Try 'ntfy COMMAND --help' or https://ntfy.sh/docs/ for more information.
To report a bug, open an issue on GitHub: https://github.com/binwiederhier/ntfy/issues.
If you want to chat, simply join the Discord server (https://discord.gg/cT7ECsZj9w), or
the Matrix room (https://matrix.to/#/#ntfy:matrix.org).
ntfy v2.11.0-next (f0dc666), runtime go1.21.10, built at 2024-06-12T02:42:16Z
Copyright (C) 2022 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2
So it seems that the binary is working as intended.
make install-freebsd-amd64 shows the following error:
rm -f /usr/local/bin/ntfy
cp -a dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy /usr/local/bin/ntfy
cp: dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy: No such file or directory
*** Error code 1
Stop.
make: stopped in /app/ntfy
I know the error above is related to the target path being different. I just don't know why in FreeBSD _v1 is being concatenated to the end of the path when the binary is generated.
make web executes correctly and the UI works fine.
make docs stops at this point:
Successfully installed certifi-2024.6.2 charset-normalizer-3.3.2 colorama-0.4.6 csscompressor-0.9.5 htmlmin2-0.1.13 idna-3.7 jsmin-3.0.1 markdown-3.6 mkdocs-material-9.5.26 mkdocs-material-extensions-1.3.1 mkdocs-minify-plugin-0.8.0 paginate-0.5.6 pygments-2.18.0 pymdown-extensions-10.8.1 regex-2024.5.15 requests-2.32.3 urllib3-2.2.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behavior with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
(. venv/bin/activate && python3.11 -m mkdocs build)
/app/ntfy/venv/bin/python3.11: No module named mkdocs
*** Error code 1
Stop.
make: stopped in /app/ntfy
make docs-deps runs without any errors.
make docs-build returns the following:
root@ntfy:/app/ntfy # make docs-build
python3.11 -m venv ./venv
(. venv/bin/activate && python3.11 -m mkdocs build)
/app/ntfy/venv/bin/python3.11: No module named mkdocs
*** Error code 1
Stop.
make: stopped in /app/ntfy
I didn't have enough time to go deeper into this but still, I'd like to have some insights from you guys on how I could solve it.
Best! @rmszc81
Hi, Thank you for doing most of the work
pkg install git go goreleaser node20 npm-node20 py311-mkdocs py311-pip py311-pylint-venv
No need to install py311-mkdocs as it will be installed by pip in the venv
make install-freebsd-amd64shows the following error:rm -f /usr/local/bin/ntfy cp -a dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy /usr/local/bin/ntfy cp: dist/ntfy_freebsd_amd64_freebsd_amd64/ntfy: No such file or directory *** Error code 1 Stop. make: stopped in /app/ntfyI know the error above is related to the target path being different. I just don't know why in FreeBSD
_v1is being concatenated to the end of the path when the binary is generated.
Look at install-linux-amd64 _v1 is also append to the directory name so I guess that it is an expected behavior when building for amd64.
root@ntfy:/app/ntfy # make docs-build python3.11 -m venv ./venv (. venv/bin/activate && python3.11 -m mkdocs build) /app/ntfy/venv/bin/python3.11: No module named mkdocs *** Error code 1 Stop. make: stopped in /app/ntfy
You set pip-3.11 as the pip command but it is only available at /usr/local/bin/pip-3.11 and not in the venv. So when running docs-dep it installed the requirements on the system, not in the venv.
pip commands available in the venv are pip, pip3 and pip3.11
ok, I'll try to come back to this in this week. is there any other tips for me to continue from here beyond the ones that you already shaerd?
best! @rmszc81
No, nothing else. I did not test the binary yet
Looking forward for having ntfy.sh available for FreeBSD @positiveEV! Thank you for the great work!
I was just looking into FreeBSD support when I found this. I did the same as rmszc81 and now have ntfy running on my server. I tested the android app against it and it all seems to work just fine. My diffs:
diff --git a/Makefile b/Makefile
index 4355423e..124b46cb 100644
--- a/Makefile
+++ b/Makefile
@@ -163,6 +163,9 @@ web-lint:
cli: cli-deps
goreleaser build --snapshot --clean
+cli-freebsd-amd64: cli-deps-static-sites
+ goreleaser build --snapshot --clean --id ntfy_freebsd_amd64
+
cli-linux-amd64: cli-deps-static-sites
goreleaser build --snapshot --clean --id ntfy_linux_amd64
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 062cce1f..65572787 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -3,6 +3,16 @@ before:
- go mod download
- go mod tidy
builds:
+ -
+ id: ntfy_freebsd_amd64
+ binary: ntfy
+ env:
+ - CGO_ENABLED=1
+ tags: [sqlite_omit_load_extension,osusergo,netgo]
+ ldflags:
+ - "-linkmode=external -extldflags=-static -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
+ goos: [freebsd]
+ goarch: [amd64]
-
id: ntfy_linux_amd64
binary: ntfy
Then I create a server.yml and started the daemon with /dist/ntfy_freebsd_amd64_freebsd_amd64_v1/ntfy serve --config /path/to/ntfy.yml. So if anyone else seeks out to try this, it seems (I only tested briefly) to work fine with these minor changes.
This is on FreeBSD 14.1, by the way.
ntfy works flawlessly in FreeBSD with gihub clone.
Once compiled you can start the server with the standard command and config file without any issues.
Messages coming through in android all good.
I use Caddy and the only thing I couldn't get it work is the web app. Only a blank page.
Will try again as time permits.
ntfy works flawlessly in FreeBSD with gihub clone.
Once compiled you can start the server with the standard command and config file without any issues.
Messages coming through in android all good.
I use Caddy and the only thing I couldn't get it work is the web app. Only a blank page.
Will try again as time permits.
Hey @escix. Did you just run make build? I'm not seeing anything related to FreeBSD in the Makefile to run a make against, so curious the steps you took to get it built, as well as what packages might have been needed as well.
git clone https://github.com/binwiederhier/ntfy.git
cd ntfy/
make cli-deps-static-sites
export CGO_ENABLED=1
go build
^ this is what I got in the command history. I will do a detailed installation guide time permits.
I recently also did a make web-build and it compiled without any issues.
cat /usr/local/etc/rc.d/ntfy
#!/bin/sh
# $FreeBSD$
# PROVIDE: ntfy
# REQUIRE: DAEMON LOGIN
# KEYWORD: shutdown
#set -x
. /etc/rc.subr
name="ntfy"
rcvar="${name}_enable"
desc="ntfy push notification server"
load_rc_config ${name}
ntfy_enable=${ntfy_enable:="NO"}
# Define default values for user and log locations
: ${ntfy_user:=ntfy}
: ${ntfy_group:=ntfy}
: ${ntfy_home:=$(getent passwd ${ntfy_user} | awk -F: '{print $6}')}
: ${ntfy_chdir:="/opt/ntfy/ntfy"}
: ${ntfy_config:="/opt/ntfy/server.yml"}
: ${ntfy_log:="/opt/ntfy/ntfy.log"}
pidfile="/var/run/${name}/${name}.pid"
procname="ntfy"
command="/usr/sbin/daemon"
command_args="-o ${ntfy_log} -t ${name} su -l ${ntfy_user} -c '${ntfy_chdir}/ntfy.sh'"
start_precmd="start_precmd"
start_postcmd="start_postcmd"
stop_cmd="stop_cmd"
# Ensure the PID directory exists before starting the service
start_precmd()
{
if [ ! -e "/var/run/${name}" ]; then
install -d -o ${ntfy_user} -g ${ntfy_group} /var/run/${name}
fi
}
# After starting the service, write the PID to the PID file
start_postcmd()
{
# Give it some time for the process to start
sleep 5
pid=$(/bin/pgrep -u ${ntfy_user} ntfy)
if [ -n "$pid" ]; then
# Ensure $pidfile is expanded properly
su -l ${ntfy_user} -c "touch $pidfile && echo $pid > $pidfile"
else
echo "Error: Could not find process ID for ${name}"
fi
}
# Stop the service by killing the process using the PID
stop_cmd()
{
if [ -f "$pidfile" ]; then
pid=$(cat $pidfile)
if [ -n "$pid" ]; then
kill "$pid"
rm -f "$pidfile"
echo "${name} service stopped."
else
echo "Error: No PID found in $pidfile."
fi
else
echo "Error: No PID file found for ${name}."
fi
}
run_rc_command "$1"
cat /opt/ntfy/ntfy/ntfy.sh
cd /opt/ntfy/ntfy/ && /opt/ntfy/ntfy/ntfy serve -c /opt/ntfy/server.yml
Thanks @escix -- got it working!
Updated to include the web-app too.
git clone https://github.com/binwiederhier/ntfy.git
cd ntfy/
make cli-deps-static-sites
export CGO_ENABLED=1
#do these before the go build so the web-app get build into the binary. May not need all three of them I did run these anyway
make web
make web-deps
make web-build
go build
Hi, I'm preparing a port. Until it will be approved you can use this file https://github.com/msviba/freebsd-ports/blob/main/ports-www-ntfy-server.diff
fetch https://raw.githubusercontent.com/msviba/freebsd-ports/refs/heads/main/ports-www-ntfy-server.diff -o /tmp
cd /usr/ports
patch -B '' -p1 < /tmp/ports-www-ntfy-server.diff
cd www/ntfy-server/
make install
If I can build it in GitHub CI I'd be happy to make it an official thing. Though you'd have to do all the PRs
I've submit a new port and it was rejected, because it already exists
https://www.freshports.org/sysutils/go-ntfy/
IMHO is possible to close this issue.
solution is:
pkg install go-ntfy