| 1 |
#!/sbin/openrc-run |
| 2 |
|
| 3 |
# OpenRC service configuration for ntfy Server. |
| 4 |
# Should be placed in /etc/init.d/ as "ntfy" or "ntfy-server" (no extension), owned by root:root and with permissions 755. |
| 5 |
# Assumes an ntfy system user and group have been created, for example using this command: |
| 6 |
# useradd --system --home-dir /var/lib/ntfy --shell /bin/false --comment "User for the simple HTTP-based pub-sub notification service" ntfy |
| 7 |
|
| 8 |
name=$RC_SVCNAME |
| 9 |
description="ntfy server" |
| 10 |
|
| 11 |
command="/usr/local/bin/ntfy" |
| 12 |
command_background=true |
| 13 |
command_args="serve" |
| 14 |
command_user="ntfy:ntfy" |
| 15 |
extra_started_commands="reload" |
| 16 |
|
| 17 |
pidfile="/run/${RC_SVCNAME}/${RC_SVCNAME}.pid" |
| 18 |
|
| 19 |
# Changes the hard number of open files (nofile) limit to 2048 for the service. |
| 20 |
rc_ulimit="-n 2048" |
| 21 |
|
| 22 |
# Allows the service to bind to privileged ports (<1024). |
| 23 |
capabilities="^cap_net_bind_service" |
| 24 |
|
| 25 |
error_log="/var/log/ntfy.log" |
| 26 |
|
| 27 |
# Service dependencies |
| 28 |
depend() { |
| 29 |
use net |
| 30 |
after firewall |
| 31 |
} |
| 32 |
|
| 33 |
# Check for - and if necessary - create required files and folders. Might require some adjustment dependings on the content of the server.yml file. |
| 34 |
start_pre() { |
| 35 |
checkpath -f --owner "$command_user" --mode 0644 \ |
| 36 |
/var/log/ntfy.log |
| 37 |
checkpath -d --owner "$command_user" --mode 0750 \ |
| 38 |
/run/ntfy/ |
| 39 |
checkpath -d --owner "$command_user" --mode 0755 \ |
| 40 |
/var/lib/ntfy/ |
| 41 |
checkpath -d --owner "$command_user" --mode 0750 \ |
| 42 |
/var/cache/ntfy/ |
| 43 |
} |
| 44 |
|
| 45 |
reload() { |
| 46 |
ebegin "Reloading $RC_SVCNAME's configuration" |
| 47 |
start-stop-daemon --signal SIGHUP --pidfile "${pidfile}" |
| 48 |
eend $? "Failed to reload $RC_SVCNAME's configuration" |
| 49 |
} |