Skip to content

Commit

Permalink
rpm-rg: support renaming the service to ptpd2
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Jun 20, 2016
1 parent c2cd4f0 commit c467e3b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packagebuild/rpm-rh/ptpd.init
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ DAEMON_DESC="IEEE 1588 Precision Time Protocol (v2) daemon"

. /etc/init.d/functions

if test -e /etc/sysconfig/ptpd ; then
if test -e /etc/sysconfig/__SERVICENAME__ ; then

. /etc/sysconfig/ptpd
. /etc/sysconfig/__SERVICENAME__

PTPD_OPTIONS="--global:lock_file=$PTPD_PID_FILE --global:status_file=$PTPD_STATUS_FILE -c $PTPD_CONFIG_FILE $PTPD_EXTRA_OPTIONS"

Expand Down
2 changes: 1 addition & 1 deletion packagebuild/rpm-rh/ptpd.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ After=syslog.target ntpdate.service sntp.service ntp.service chronyd.service net

[Service]
Type=forking
EnvironmentFile=-/etc/sysconfig/ptpd
EnvironmentFile=-/etc/sysconfig/__SERVICENAME__
ExecStart=/usr/sbin/ptpd2 \
--global:lock_file=${PTPD_PID_FILE} \
--global:status_file=${PTPD_STATUS_FILE} \
Expand Down
32 changes: 18 additions & 14 deletions packagebuild/rpm-rh/ptpd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
%define distver %(/usr/lib/rpm/redhat/dist.sh --dist)
%endif

%define servicename ptpd%{?servicesuffix}

%if %{slaveonly_build} == 1
Name: ptpd-slaveonly
Summary: Synchronises system time using the Precision Time Protocol (PTP) implementing the IEEE 1588-2008 (PTP v 2) standard. Slave-only version.
Expand Down Expand Up @@ -66,7 +68,7 @@ coordination of LAN connected computers.
Install the ptpd package if you need tools for keeping your system's
time synchronised via the PTP protocol or serving PTP time.

%prep
%prep

%setup -n ptpd-2.3.2

Expand Down Expand Up @@ -104,14 +106,16 @@ install -m 644 src/templates.conf $RPM_BUILD_ROOT%{_datadir}/ptpd/templates.conf

%if %{?_unitdir:1}%{!?_unitdir:0}
mkdir -p .%{_unitdir}
install -m644 $RPM_SOURCE_DIR/ptpd.service .%{_unitdir}/ptpd.service
install -m644 $RPM_SOURCE_DIR/ptpd.service .%{_unitdir}/%{servicename}.service
sed -i 's#/etc/sysconfig/__SERVICENAME__#/etc/sysconfig/%{servicename}#' .%{_unitdir}/%{servicename}.service
%else
mkdir -p .%{_initrddir}
install -m755 $RPM_SOURCE_DIR/ptpd.init .%{_initrddir}/ptpd
install -m755 $RPM_SOURCE_DIR/ptpd.init .%{_initrddir}/%{servicename}
sed -i 's#/etc/sysconfig/__SERVICENAME__#/etc/sysconfig/%{servicename}#' .%{_initrddir}/%{servicename}
%endif

mkdir -p .%{_sysconfdir}/sysconfig
install -m644 %{SOURCE2} .%{_sysconfdir}/sysconfig/ptpd
install -m644 %{SOURCE2} .%{_sysconfdir}/sysconfig/%{servicename}
install -m644 %{SOURCE3} .%{_sysconfdir}/ptpd2.conf

}
Expand All @@ -125,9 +129,9 @@ rm -rf $RPM_BUILD_ROOT
%post

%if %{?_unitdir:1}%{!?_unitdir:0}
/usr/bin/systemctl enable ptpd >/dev/null 2>&1
/usr/bin/systemctl enable %{servicename} >/dev/null 2>&1
%else
/sbin/chkconfig --add ptpd
/sbin/chkconfig --add %{servicename}
%endif
echo
echo -e "**** PTPd - Running post-install checks...\n"
Expand Down Expand Up @@ -185,30 +189,30 @@ done
%preun
if [ $1 = 0 ]; then
%if %{?_unitdir:1}%{!?_unitdir:0}
systemctl stop ptpd > /dev/null 2>&1
systemctl disable ptpd >/dev/null 2>&1
systemctl stop %{servicename} > /dev/null 2>&1
systemctl disable %{servicename} >/dev/null 2>&1
%else
service ptpd stop > /dev/null 2>&1
/sbin/chkconfig --del ptpd
service %{servicename} stop > /dev/null 2>&1
/sbin/chkconfig --del %{servicename}
%endif
fi
:

%postun
if [ "$1" -ge "1" ]; then
service ptpd condrestart > /dev/null 2>&1
service %{servicename} condrestart > /dev/null 2>&1
fi
:

%files
%defattr(-,root,root)
%{_sbindir}/ptpd2
%if %{?_unitdir:1}%{!?_unitdir:0}
%{_unitdir}/ptpd.service
%{_unitdir}/%{servicename}.service
%else
%config %{_initrddir}/ptpd
%config %{_initrddir}/%{servicename}
%endif
%config(noreplace) %{_sysconfdir}/sysconfig/ptpd
%config(noreplace) %{_sysconfdir}/sysconfig/%{servicename}
%config(noreplace) %{_sysconfdir}/ptpd2.conf
%config(noreplace) %{_datadir}/ptpd/templates.conf
%{_mandir}/man8/*
Expand Down
36 changes: 31 additions & 5 deletions packagebuild/rpm-rh/rpmbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@ fi
# ptpd RPM building script
# (c) 2013-2015: Wojciech Owczarek, PTPd project

# First argument: 1/0 to add a git tag (timestamp.lastgitcommit)
ADD_TAG=${1:-0}
while [[ $# -gt 0 ]]; do
opt="$1";
shift; #expose next argument
case "$opt" in
"--tag" )
# Add git-based tag
ADD_TAG=1;;
"--service2" )
# Create ptpd2 service
SERVICESUFFIX='2';;
*) cat >&2 <<EOF
Invalid option: $opt (remainder $@)
Supported options:
--tag: add a git-based tag to the rpm release
--service2: generate the service as ptpd2 (instead of default ptpd)
EOF
exit 1;;
esac
done


SPEC=ptpd.spec
PWD=`pwd`
Expand Down Expand Up @@ -58,13 +76,21 @@ for slaveonly in 0 1; do
RPMFILE=$BUILDDIR/RPMS/`uname -m`/$ARCHIVE.`uname -m`.rpm
SRPMFILE=$BUILDDIR/SRPMS/$ARCHIVE.src.rpm

TAG_ARG=''
if [ $ADD_TAG -ne 0 ]; then
if [ -z "$ADD_TAG" ]; then
TAG_ARG='__gittag notag' # cannot be empty
else
tag=`git log --format=.%ct.%h -1` # based on last commit, timestamp for increasing versions
TAG_ARG="gittag $tag"
fi

rpmbuild --define "$TAG_ARG" --define "build_slaveonly $slaveonly" --define "_topdir $BUILDDIR" -ba $BUILDDIR/SPECS/$SPEC && {
if [ -z "$SERVICESUFFIX" ]; then
SERVICESUFFIX_ARG='__servicesuffix nosuffix' # cannot be empty
else
SERVICESUFFIX_ARG="servicesuffix $SERVICESUFFIX"
fi


rpmbuild --define "$TAG_ARG" --define "$SERVICESUFFIX_ARG" --define "build_slaveonly $slaveonly" --define "_topdir $BUILDDIR" -ba $BUILDDIR/SPECS/$SPEC && {
find $BUILDDIR -name "*.rpm" -exec mv {} $PWD \;
}

Expand Down

0 comments on commit c467e3b

Please sign in to comment.