summaryrefslogtreecommitdiff
path: root/net/chrony/files/chronyd.sh
blob: 578a5c5b98139f960774b7942652bcafd7383c1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: chronyd.sh,v 1.4 2002/09/23 07:04:39 grant Exp $
#
# PROVIDE: chronyd
# REQUIRE: DAEMON

. /etc/rc.subr

name="chronyd"
command="@PREFIX@/sbin/${name}"
pidfile="/var/run/${name}.pid"
required_files="@PKG_SYSCONFDIR@/chrony.conf"
extra_commands="online offline"
online_cmd="chronyd_online"
online_precmd="chronyd_precmd"
offline_cmd="chronyd_offline"
offline_precmd="chronyd_precmd"

chronyd_precmd()
{
	local id kfile
	id=`awk '$1 == "commandkey" { print $2 }' @PKG_SYSCONFDIR@/chrony.conf`
	if [ -z "$id" ]; then
		echo "ERROR: no commandkey in @PKG_SYSCONFDIR@/chrony.conf!"
		exit 1
	fi
	kfile=`awk '$1 == "keyfile" { print $2 }' @PKG_SYSCONFDIR@/chrony.conf`
	if [ -z "$kfile" ]; then
		echo "ERROR: no keyfile in @PKG_SYSCONFDIR@/chrony.conf!"
		exit 1
	fi
	chronyd_password=`awk '$1 == "'$id'" { print $2 }' $kfile`
	if [ -z "$chronyd_password" ]; then
		echo "ERROR: no key #$id in $kfile!"
		exit 1
	fi
}

chronyd_online()
{
	printf "password %s\nonline\n" $chronyd_password | @PREFIX@/bin/chronyc
}

chronyd_offline()
{
	printf "password %s\noffline\n" $chronyd_password | @PREFIX@/bin/chronyc
}

load_rc_config $name
run_rc_command "$1"