+# Spec file only supports RHEL and Fedora now
+%if 0%{?rhel} || 0%{?fedora}
+
Name: opendaylight-controller
Version: 0.1.0
-Release: 0.2.0%{?dist}
+Release: 0.3.0%{?dist}
Summary: OpenDaylight SDN Controller
Group: Applications/Communications
License: EPL
BuildRequires: java-devel
BuildRequires: maven
+%if 0%{?fedora}
BuildRequires: systemd
+%else
+BuildRequires: sysvinit-tools
+%endif
Requires: java >= 1:1.7.0
Requires: %{name}-dependencies
+%if 0%{?fedora}
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
+%else
+# use sysV for rhel
+Requires(post): chkconfig
+Requires(preun): chkconfig
+
+# This is for /sbin/service
+Requires(preun): initscripts
+Requires(postun): initscripts
+%endif
# This is the directory where all the application resources (scripts,
# maven.compile.fork is used to reduce the build time.
#export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" && \
# mvn clean install -Dmaven.test.skip=true -DskipIT -Dmaven.compile.fork=true
-export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" && mvn clean install
+export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" && mvn clean install -Dmaven.test.skip=true
%install
ln -s %{resources_dir}/lib %{buildroot}%{data_dir}
ln -s %{resources_dir}/plugins %{buildroot}%{data_dir}
+%if 0%{?fedora}
install -m 644 -D %{name}.systemd %{buildroot}%{_unitdir}/%{name}.service
+%else
+install -m 644 -D %{name}.sysv %{buildroot}%{_initddir}/%{name}
+%endif
install -m 644 -D %{name}.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/%{name}
# Usually one wants to replace the .jar files of the dependencies by symlinks
find %{buildroot}%{data_dir} -type d -exec chmod 755 {} \;
find %{buildroot}%{data_dir} -type f -exec chmod 755 {} \;
chmod 755 %{buildroot}%{resources_dir}/run.sh
+%if 0%{?rhel}
+chmod 755 %{buildroot}%{_initddir}/%{name}
+%endif
# Remove the temporary directory:
rm -rf tmp
#%systemd_post %{name}.service
%preun
+%if 0%{?fedora}
%systemd_preun %{name}.service
+%else
+if [ $1 -eq 0 ] ; then
+ /sbin/service %{name} stop >/dev/null 2>&1
+ /sbin/chkconfig --del %{name}
+fi
+%endif
%postun
+%if 0%{?fedora}
%systemd_postun
+%else
+if [ "$1" -ge "1" ] ; then
+ /sbin/service %{name} condrestart >/dev/null 2>&1 || :
+fi
+%endif
%clean
%if "%{noclean}" == "1"
%files
%{resources_dir}
+%if 0%{?fedora}
%{_unitdir}/%{name}.service
+%else
+%{_initddir}/%{name}
+%endif
# Configuration files should marked as such, so that they aren't overwritten
# when updating the package:
%doc NOTICE
%doc README.OPENDAYLIGHT
+%endif
%changelog
+* Mon Dec 23 2013 Hsin-Yi Shen <hshen@redhat.com> - 0.1.0-0.3.0
+- Updates to support building rpm for both RHEL and fedora.
+
* Fri Nov 22 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.2.0
- Updates to support building rpm with jenkins.
--- /dev/null
+#!/bin/sh
+#
+# Opendaylight controller
+#
+# chkconfig: 2345 95 15
+# description: OpenDaylight Controller
+
+### BEGIN INIT INFO
+# Provides: opendaylight-controller
+# Required-Start: $network
+# Required-Stop: $network
+# Should-Start:
+# Should-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: start and stop opendaylight controller
+# Description: Opendaylight controller
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+exec="/usr/share/opendaylight-controller/run.sh"
+prog="opendaylight-controller"
+config="/etc/opendaylight-controller/config.ini"
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+lockfile=/var/lock/subsys/$prog
+
+start() {
+ [ -x $exec ] || exit 5
+ [ -f $config ] || exit 6
+ echo -n $"Starting $prog: "
+ # if not running, start it up here, usually something like "daemon $exec"
+ $exec -start
+ retval=$?
+ echo
+ # [ $retval -eq 0 ] && touch $lockfile
+ return $retval
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ # stop it here, often "killproc $prog"
+ $exec -stop
+ retval=$?
+ echo
+ # [ $retval -eq 0 ] && rm -f $lockfile
+ return $retval
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ restart
+}
+
+force_reload() {
+ restart
+}
+
+rh_status() {
+ # run checks to determine if the service is running or use generic status
+ #status $prog
+ $exec -status
+}
+
+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
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+ exit 2
+esac
+exit $?