drop SysV init script

This commit is contained in:
Miroslav Lichvar 2011-06-24 15:36:06 +02:00
parent 561c9824f7
commit 259c5c431c
7 changed files with 90 additions and 192 deletions

View File

@ -5,7 +5,7 @@ SERVERFILE=$SAVEDIR/chrony.servers.$interface
chrony_config() {
rm -f $SERVERFILE
if [ "$PEERNTP" != "no" ]; then
/etc/init.d/chronyd command "$(
/usr/libexec/chrony-helper command "$(
for server in $new_ntp_servers; do
echo "add server $server $NTPSERVERARGS"
echo "$server $NTPSERVERARGS" >> $SERVERFILE
@ -15,7 +15,7 @@ chrony_config() {
chrony_restore() {
if [ -f $SERVERFILE ]; then
/etc/init.d/chronyd command "$(
/usr/libexec/chrony-helper command "$(
while read server serverargs; do
echo "delete $server"
done < $SERVERFILE)" &> /dev/null

68
chrony.helper Normal file
View File

@ -0,0 +1,68 @@
#!/bin/bash
config=/etc/chrony.conf
keyfile=/etc/chrony.keys
chronyc=/usr/bin/chronyc
dhclient_servers=/var/lib/dhclient/chrony.servers.*
service_name=chronyd.service
get_key() {
awk '/^[ \t]*'$1'\>/ { print $2; exit }' < $keyfile
}
get_commandkeyid() {
awk '/^[ \t]*commandkey\>/ { keyid=$2 } END { print keyid }' < $config
}
chrony_command() {
commandkeyid=$(get_commandkeyid)
[ -z "$commandkeyid" ] && return 1
commandkey=$(get_key $commandkeyid)
[ -z "$commandkey" ] && return 2
$chronyc <<EOF
password $commandkey
$1
EOF
}
generate_commandkey() {
commandkeyid=$(get_commandkeyid)
[ -z "$commandkeyid" ] && return 1
commandkey=$(get_key $commandkeyid)
[ -z "$commandkey" ] || return 0
commandkey=$(tr -c -d '[\041-\176]' < /dev/urandom | head -c 8)
[ -n "$commandkey" ] && echo "$commandkeyid $commandkey" >> $keyfile
}
add_dhclient_servers() {
command=$(cat $dhclient_servers 2> /dev/null |
while read server serverargs; do
echo "add server $server $serverargs"
done)
if [ -n "$command" ]; then
chrony_command "$command" &> /dev/null
fi
}
is_running() {
systemctl status chronyd.service &> /dev/null
}
case "$1" in
generate-commandkey)
generate_commandkey
;;
add-dhclient-servers)
add_dhclient_servers
;;
command)
is_running && chrony_command "$2"
;;
*)
echo $"Usage: $0 {generate-commandkey|add-dhclient-servers|command}"
exit 2
esac
exit $?

View File

@ -3,6 +3,6 @@
nocreate
sharedscripts
postrotate
/sbin/service chronyd cyclelogs 2> /dev/null > /dev/null || true
/usr/libexec/chrony-helper command cyclelogs > /dev/null 2>&1 || true
endscript
}

View File

@ -4,12 +4,12 @@ export LC_ALL=C
if [ "$2" = "up" ]; then
/sbin/ip route list dev "$1" | grep -q '^default' &&
/etc/init.d/chronyd online
/usr/libexec/chrony-helper command online > /dev/null 2>&1
fi
if [ "$2" = "down" ]; then
/sbin/ip route list | grep -q '^default' ||
/etc/init.d/chronyd offline
/usr/libexec/chrony-helper command offline > /dev/null 2>&1
fi
exit 0

View File

@ -11,7 +11,7 @@ Source0: http://download.tuxfamily.org/chrony/chrony-%{version}%{?prerele
Source1: chrony.conf
Source2: chrony.keys
Source3: chronyd.service
Source4: chronyd.init
Source4: chrony.helper
Source5: chrony.logrotate
# wget -O timepps.h 'http://gitweb.enneenne.com/?p=linuxpps;a=blob_plain;f=Documentation/pps/timepps.h;hb=b895b1a28558b83907c691aad231c41a0d14df88'
Source6: timepps.h
@ -23,9 +23,9 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libcap-devel libedit-devel bison texinfo
Requires(pre): shadow-utils
Requires(post): chkconfig info
Requires(preun): chkconfig initscripts info
Requires(postun): initscripts
Requires(post): systemd-units info chkconfig
Requires(preun): systemd-units info
Requires(postun): systemd-units
%description
A client/server for the Network Time Protocol, this program keeps your
@ -65,16 +65,17 @@ make install install-docs DESTDIR=$RPM_BUILD_ROOT
rm -rf $RPM_BUILD_ROOT%{_docdir}
mkdir -p $RPM_BUILD_ROOT{%{_sysconfdir}/{sysconfig,logrotate.d},%{_initrddir}}
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{sysconfig,logrotate.d}
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/{lib,log}/chrony
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/NetworkManager/dispatcher.d
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/dhcp/dhclient.d
mkdir -p $RPM_BUILD_ROOT%{_libexecdir}
mkdir -p $RPM_BUILD_ROOT/lib/systemd/system
install -m 644 -p %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/chrony.conf
install -m 640 -p %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/chrony.keys
install -m 644 -p %{SOURCE3} $RPM_BUILD_ROOT/lib/systemd/system/chronyd.service
install -m 755 -p %{SOURCE4} $RPM_BUILD_ROOT%{_initrddir}/chronyd
install -m 755 -p %{SOURCE4} $RPM_BUILD_ROOT%{_libexecdir}/chrony-helper
install -m 644 -p %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/chrony
install -m 755 -p %{SOURCE7} \
$RPM_BUILD_ROOT%{_sysconfdir}/NetworkManager/dispatcher.d/20-chrony
@ -93,9 +94,9 @@ getent passwd chrony > /dev/null || /usr/sbin/useradd -r -g chrony \
:
%post
/sbin/chkconfig --add chronyd
/bin/systemctl daemon-reload &> /dev/null || :
/sbin/install-info %{_infodir}/chrony.info.gz %{_infodir}/dir &> /dev/null || :
/bin/systemctl daemon-reload &> /dev/null
/sbin/install-info %{_infodir}/chrony.info.gz %{_infodir}/dir &> /dev/null
:
%triggerun -- chrony < 1.25
if /sbin/chkconfig --level 3 chronyd; then
@ -105,17 +106,17 @@ fi
%preun
if [ "$1" -eq 0 ]; then
/sbin/service chronyd stop &> /dev/null
/sbin/chkconfig --del chronyd
/bin/systemctl disable chronyd.service &> /dev/null
/bin/systemctl --no-reload disable chronyd.service &> /dev/null
/bin/systemctl stop chronyd.service &> /dev/null
/sbin/install-info --delete %{_infodir}/chrony.info.gz \
%{_infodir}/dir &> /dev/null
fi
:
%postun
/bin/systemctl daemon-reload &> /dev/null
if [ "$1" -ge 1 ]; then
/sbin/service chronyd condrestart &> /dev/null
/bin/systemctl try-restart chronyd.service &> /dev/null
fi
:
@ -127,9 +128,9 @@ fi
%config(noreplace) %{_sysconfdir}/logrotate.d/chrony
%{_sysconfdir}/NetworkManager/dispatcher.d/20-chrony
%{_sysconfdir}/dhcp/dhclient.d/chrony.sh
%{_initrddir}/chronyd
%{_bindir}/chronyc
%{_sbindir}/chronyd
%{_libexecdir}/chrony-helper
%{_infodir}/chrony.info*
/lib/systemd/system/chronyd.service
%{_mandir}/man[158]/%{name}*.[158]*

View File

@ -1,171 +0,0 @@
#!/bin/bash
#
# chronyd <summary>
#
# chkconfig: - 58 74
# description: Client/server for the Network Time Protocol, \
# this program keeps your computer's clock accurate.
### BEGIN INIT INFO
# Provides: chronyd
# Required-Start: $network $local_fs $remote_fs
# Required-Stop:
# Should-Start: $syslog $named
# Should-Stop: $syslog
# Short-Description: NTP client/server
# Description: Client/server for the Network Time Protocol,
# this program keeps your computer's clock accurate.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
exec=/usr/sbin/chronyd
prog=chronyd
config=/etc/chrony.conf
keyfile=/etc/chrony.keys
chronyc=/usr/bin/chronyc
dhclient_servers=/var/lib/dhclient/chrony.servers.*
lockfile=/var/lock/subsys/$prog
OPTIONS="-u chrony"
get_key() {
awk '/^[ \t]*'$1'\>/ { print $2; exit }' < $keyfile
}
get_commandkeyid() {
awk '/^[ \t]*commandkey\>/ { keyid=$2 } END { print keyid }' < $config
}
chrony_command() {
commandkeyid=$(get_commandkeyid)
[ -z "$commandkeyid" ] && return 1
commandkey=$(get_key $commandkeyid)
[ -z "$commandkey" ] && return 2
$chronyc <<EOF | grep -v '200 OK'
password $commandkey
$1
EOF
}
generate_commandkey() {
commandkeyid=$(get_commandkeyid)
[ -z "$commandkeyid" ] && return 1
commandkey=$(get_key $commandkeyid)
[ -z "$commandkey" ] || return 0
echo -n $"Generating chrony command key: "
commandkey=$(tr -c -d '[\041-\176]' < /dev/urandom | head -c 8)
[ -n "$commandkey" ] && echo "$commandkeyid $commandkey" >> $keyfile &&
success || failure
echo
}
add_dhclient_servers() {
command=$(cat $dhclient_servers 2> /dev/null |
while read server serverargs; do
echo "add server $server $serverargs"
done)
if [ -n "$command" ]; then
echo -n $"Adding dhclient NTP servers to chrony: "
chrony_command "$command" &> /dev/null && success || failure
echo
fi
}
start() {
[ "$NETWORKING" = "no" ] && exit 1
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
generate_commandkey
echo -n $"Starting $prog: "
daemon $exec $OPTIONS
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
[ $retval -eq 0 ] && add_dhclient_servers
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
online|offline|cyclelogs)
rh_status_q || exit 7
chrony_command $1
;;
generate-commandkey)
generate_commandkey
;;
add-dhclient-servers)
add_dhclient_servers
;;
command)
rh_status_q || exit 7
chrony_command "$2"
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|cyclelogs|online|offline|command}"
exit 2
esac
exit $?

View File

@ -4,9 +4,9 @@ After=syslog.target ntpdate.service
Conflicts=ntpd.service
[Service]
ExecStartPre=/etc/init.d/chronyd generate-commandkey
ExecStartPre=/usr/libexec/chrony-helper generate-commandkey
ExecStart=/usr/sbin/chronyd -n -u chrony
ExecStartPost=/etc/init.d/chronyd add-dhclient-servers
ExecStartPost=/usr/libexec/chrony-helper add-dhclient-servers
[Install]
WantedBy=multi-user.target