Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 1 | Name: onos |
| 2 | Version: @ONOS_RPM_VERSION |
| 3 | Release: 1 |
| 4 | Summary: Open Networking Operating System (ONOS) |
| 5 | Vendor: ONOS Project |
| 6 | Packager: ONOS Project |
| 7 | |
| 8 | Group: Applications/Engineering |
| 9 | License: Apache 2.0 |
| 10 | Requires: jre >= 1:8 |
| 11 | URL: http://www.onosproject.org |
| 12 | Source0: %{name}-@ONOS_RPM_VERSION.tar.gz |
| 13 | |
| 14 | BuildArch: noarch |
| 15 | BuildRoot: %{_tmppath}/%{name}-buildroot |
| 16 | |
| 17 | %description |
| 18 | Open Network Operating System (ONOS) is an open source SDN controller. |
| 19 | |
| 20 | %prep |
| 21 | %setup -q |
| 22 | |
| 23 | %install |
| 24 | mkdir -p %{buildroot} |
| 25 | cp -R * %{buildroot} |
| 26 | |
| 27 | %clean |
| 28 | rm -rf %{buildroot} |
| 29 | |
| 30 | %files |
| 31 | %defattr(-,root,root,-) |
| 32 | /etc/init/onos.conf |
| 33 | /opt/onos/ |
| 34 | |
| 35 | %post |
| 36 | ONOS_USER=sdn |
| 37 | |
| 38 | # Check to see if user exists, and if not, create a service account |
| 39 | getent passwd $ONOS_USER >/dev/null 2&>1 || ( useradd -M $ONOS_USER && usermod -L $ONOS_USER ) |
| 40 | |
| 41 | # Create ONOS options file |
| 42 | [ ! -f /opt/onos/options ] && cat << EOF > /opt/onos/options |
| 43 | export ONOS_OPTS=server |
| 44 | export ONOS_USER="$ONOS_USER" |
| 45 | EOF |
| 46 | |
| 47 | # Change permissions for onos directory |
| 48 | [ -d /opt/onos ] && chown -R $ONOS_USER.$ONOS_USER /opt/onos |
| 49 | |
| 50 | echo ONOS successfully installed at /opt/onos |
| 51 | |
| 52 | %preun |
| 53 | # Check if onos is running; if it is, stop onos |
| 54 | [ -z "$(status onos 2>/dev/null | grep start)" ] && echo "onos is not running." || ( |
| 55 | stop onos |
| 56 | |
| 57 | # Wait for onos to stop up to 5 seconds |
| 58 | for i in $(seq 1 5); do |
| 59 | [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && break |
| 60 | sleep 1 |
| 61 | done |
| 62 | [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && echo 'Stopped onos service' || echo 'Failed to stop onos' |
| 63 | ) |
| 64 | |
| 65 | %postun |
| 66 | #TODO this should be less brute-force |
| 67 | rm -rf /opt/onos |
| 68 | |
| 69 | %changelog |
| 70 | # TODO |
| 71 | |