ports/net/ntpd-rs/files/ntp_daemon.in
Mikael Urankar 811c1b9162 net/ntpd-rs: Add new port
ntpd-rs is an NTP implementation written in Rust, with a focus on security and
stability. It includes client and server functionality and supports NTS.

WWW: https://tweedegolf.nl/en/pendulum

PR:		272774
2023-08-24 11:02:18 +02:00

56 lines
1.2 KiB
Bash

#!/bin/sh
# PROVIDE: ntp_daemon
# REQUIRE: DAEMON FILESYSTEMS devfs
# BEFORE: LOGIN
# KEYWORD: nojail resume shutdown
#
. /etc/rc.subr
name=ntp_daemon
rcvar=ntp_daemon_enable
load_rc_config $name
ntp_daemon_enable=${ntp_daemon_enable-"NO"}
ntp_daemon_config=${ntp_daemon_config-"%%ETCDIR%%/ntp.toml"}
ntp_daemon_socket=${ntp_daemon_socket-"/var/run/ntpd-rs"}
command="/usr/bin/true"
procname="/usr/sbin/daemon"
pidfile="/var/run/${name}.pid"
start_cmd="ntp_daemon_start"
stop_cmd="ntp_daemon_stop"
is_process_running()
{
[ -f ${pidfile} ] && procstat $(cat ${pidfile}) >/dev/null 2>&1
}
ntp_daemon_start()
{
[ -d "${ntp_daemon_socket}" ] || /bin/mkdir "${ntp_daemon_socket}"
/usr/sbin/chown _ntp:_ntp "${ntp_daemon_socket}"
/usr/sbin/daemon -P ${pidfile} -r -f -o /var/log/ntp_daemon.log -H %%PREFIX%%/bin/ntp-daemon --config "${ntp_daemon_config}"
if is_process_running; then
echo "Started ntp-daemon (pid=$(cat ${pidfile}))"
else
echo "Failed to start ntp-daemon"
fi
}
ntp_daemon_stop()
{
if is_process_running; then
/bin/rm -rf "${ntp_daemon_socket}"
local pid=$(cat ${pidfile})
echo "Stopping ntp-daemon (pid=${pid})"
kill -- -${pid}
else
echo "ntp-daemon isn't running"
fi
}
run_rc_command "$1"