Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it more flexible to use latest version. Make nexus user own the process. #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ This repository holds files and scripts to build a Sonatype Nexus .rpm
package.

# Ingredients
- Nexus OSS 1.9.2.3: from http://nexus.sonatype.com
- Nexus OSS Latest: from http://nexus.sonatype.com

# Licenses
- Nexus OSS: AGPL, Sonatype
- Scripts and Spec: AGPL, Jens Braeuer <braeuer.jens@googlemail.com>
- Scripts and Spec: AGPL, Jens Braeuer <braeuer.jens@googlemail.com>, Ilja Bobkevic <ilja.bobkevic@gmail.com>

# How to build
- fetch Nexus OSS tar.gz: ./fetch-nexus-oos
Expand All @@ -18,17 +18,14 @@ Nexus configuration has been customized, so Nexus behaves more like a
"real" daemon.

- Logfiles: /var/log/nexus
- Pidfile: /var/run/
- Pidfile: /var/run
- Conf: /etc/nexus
- Init file: /etc/init.d/nexus

# Current state

This has been tested on Scientific Linux 6.1. It should work on CentOS
and RHEL too. Currently Nexus is configured to run as root
user. While this not perfect, it is better than the manual
unzip/install steps .
This has been tested on Scientific Linux 6.1 and CentOS 6.4.
It should work on RHEL too.

Have fun!
Jens

35 changes: 35 additions & 0 deletions SOURCES/nexus_initd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--- nexus-2.5.1-01/bin/nexus.orig 2013-06-28 19:26:12.000000000 +0000
+++ nexus-2.5.1-01/bin/nexus 2013-07-08 13:48:29.951546295 +0000
@@ -1,4 +1,21 @@
#! /bin/sh
+#
+# nexu Startup script for Nexus OSS
+#
+# chkconfig: 2345 98 02
+# description: Nexus OSS daemon
+
+### BEGIN INIT INFO
+# Provides: nexus
+# Required-Start: $local_fs $network $remote_fs
+# Required-Stop: $local_fs $network $remote_fs
+# Should-Start: $named $time
+# Should-Stop: $named $time
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Startup script for the Nexus OSS
+# Description: Nexus OSS daemon
+### END INIT INFO

#
# Copyright (c) 1999, 2006 Tanuki Software Inc.
@@ -289,7 +306,9 @@

# Still want to change users, recurse. This means that the user will only be
# prompted for a password once. Variables shifted by 1
- su - $RUN_AS_USER -c "\"$REALPATH\" $2"
+ touch $PIDFILE
+ chown $RUN_AS_USER:$RUN_AS_GROUP $PIDFILE
+ sudo -u $RUN_AS_USER $REALPATH $2

# Now that we are the original user again, we may need to clean up the lock file.
if [ "X$LOCKPROP" != "X" ]
45 changes: 31 additions & 14 deletions SPECS/nexus-oss.spec
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
Summary: Nexus manages software “artifacts” required for development, deployment, and provisioning.
Name: nexus-oss
Version: 1.9.2.3
Release: 1
Name: nexus
Version: %{version}
Release: %{release}
License: AGPL
Group: unknown
URL: http://nexus.sonatype.org/
Source0: %{name}-webapp-%{version}-bundle.tar.gz
Source0: %{name}-%{version}-%{release}-bundle.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires: jdk
BuildArch: noarch
AutoReqProv: no
Patch0: nexus_initd.patch

%define __os_install_post %{nil}

%description
A package repository

%prep
%setup -q -n %{name}-webapp-%{version}
%setup -q -n %{name}-%{version}-%{release}
%patch0 -p1

%build

Expand All @@ -25,23 +27,20 @@ rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/share/%{name}
mv * $RPM_BUILD_ROOT/usr/share/%{name}

arch=$(echo "%{_arch}" | sed -e 's/_/-/')
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d/
cd $RPM_BUILD_ROOT/etc/rc.d/init.d/
ln -sf /usr/share/%{name}/bin/jsw/linux-$arch/nexus $RPM_BUILD_ROOT/etc/rc.d/init.d/
ln -sf /usr/share/%{name}/bin/nexus $RPM_BUILD_ROOT/etc/rc.d/init.d/

mkdir -p $RPM_BUILD_ROOT/etc/
ln -sf /usr/share/%{name}/conf $RPM_BUILD_ROOT/etc/nexus

# patch work dir
sed -i -e 's#nexus-work=.*#nexus-work=/var/lib/nexus/#g' $RPM_BUILD_ROOT/usr/share/%{name}/conf/plexus.properties
sed -i -e 's#nexus-work=.*#nexus-work=/var/lib/nexus/#g' $RPM_BUILD_ROOT/usr/share/%{name}/conf/nexus.properties
mkdir -p $RPM_BUILD_ROOT/var/lib/nexus

# patch tcp port
sed -i -e 's#application-port=.*#application-port=80#g' $RPM_BUILD_ROOT/usr/share/%{name}/conf/plexus.properties

# patch pid dir
sed -i -e 's#PIDDIR=.*#PIDDIR=/var/run/#' $RPM_BUILD_ROOT/usr/share/%{name}/bin/jsw/linux-$arch/nexus
sed -i -e 's#PIDDIR=.*#PIDDIR=/var/run#' $RPM_BUILD_ROOT/usr/share/%{name}/bin/nexus
sed -i -e 's/#RUN_AS_USER=.*/RUN_AS_USER=nexus/' $RPM_BUILD_ROOT/usr/share/%{name}/bin/nexus

# patch logfile
mkdir -p $RPM_BUILD_ROOT/var/log/nexus
Expand All @@ -51,15 +50,33 @@ sed -i -e 's#wrapper.logfile=.*#wrapper.logfile=/var/log/nexus/nexus.log#' $RPM_
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%defattr(-,nexus,nexus,-)
%doc
/usr/share/%{name}
/etc/rc.d/init.d/nexus
/etc/nexus
/var/lib/nexus
/var/log/nexus

%pre
getent group nexus >/dev/null || groupadd -r nexus
getent passwd nexus >/dev/null || \
useradd -r -g nexus -d /usr/share/%{name} -s /sbin/nologin \
-c "Nexus OSS" nexus

%post
service nexus start

%preun
service nexus stop

%changelog
* Mon Jul 8 2013 Ilja Bobkevic <ilja.bobkevic@gmail.com>
- Addopt spec for external verison and release definition
- Use nexus credentials for the daemon
- Patch init.d script with proper headers and to use sudo instead su
* Thu Jul 13 2012 Mike Champion <mike.champion@gmail.com> - 2.0.6
- Upgrade to 2.0.6
* Thu Dec 22 2011 Jens Braeuer <braeuer.jens@googlemail.com> - 1.9.2.3-1
- Initial packaging.
- For now nexus will run as root and listen to port 80
Expand Down
6 changes: 3 additions & 3 deletions fetch-nexus-oss
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /bin/bash

readonly BASEDIR="$(dirname $(readlink -f "$0"))"
readonly BASEURL="http://nexus.sonatype.org/downloads"
readonly BINARY="nexus-oss-webapp-1.9.2.3-bundle.tar.gz"
readonly BASEURL="http://www.sonatype.org/downloads"
readonly BINARY="nexus-latest-bundle.tar.gz"

set -e
mkdir -p "${BASEDIR}/SOURCES/"
cd "${BASEDIR}/SOURCES/"
wget "${BASEURL}/${BINARY}"

9 changes: 9 additions & 0 deletions rpm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ fi
readonly SPEC="$(readlink -f "$1")"
readonly BASEDIR="$(dirname $(readlink -f "$0"))"

# Get downloaded file name
stringZ=`ls ${BASEDIR}/SOURCES/nexus-*-bundle.tar.gz`
# Parse version code
verrel=`expr match "$stringZ" '.*nexus-\(.*\)-bundle\.tar\.gz'`
# Sepearate version from release digits
IFS='-' read -a verarr <<< "$verrel"

mkdir -p ${BASEDIR}/{BUILD,BUILDROOT,RPMS}
rpmbuild --verbose \
--define "_topdir ${BASEDIR}" \
--define "_rpmdir ${BASEDIR}/RPMS" \
--define "version ${verarr[0]}" \
--define "release ${verarr[1]}" \
-bb "${SPEC}"