Permalink
Browse files

rpm-rg: support renaming the service to ptpd2

  • Loading branch information...
1 parent c2cd4f0 commit c467e3be62ae7f975f9a5483696d8ad0ed1146b3 @stdweird stdweird committed Jun 20, 2016
Showing with 52 additions and 22 deletions.
  1. +2 −2 packagebuild/rpm-rh/ptpd.init
  2. +1 −1 packagebuild/rpm-rh/ptpd.service
  3. +18 −14 packagebuild/rpm-rh/ptpd.spec
  4. +31 −5 packagebuild/rpm-rh/rpmbuild.sh
@@ -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"
@@ -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} \
@@ -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.
@@ -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
@@ -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
}
@@ -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"
@@ -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/*
@@ -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`
@@ -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 \;
}

0 comments on commit c467e3b

Please sign in to comment.