Repository Management with Nexus
3.6. Configuring Nexus as a Service

3.6. Configuring Nexus as a Service

When installing Nexus, you will often want to configure Nexus as a service. If you are on Windows, the Nexus distribution includes binaries that can work with the Windows Services subsystem and if you are on another platform such as GNU/Linux[1], Nexus also includes scripts that can be configured to start Nexus as a service. The following sections provide instructions for configuring Nexus as a service.

3.6.1. Startup Scripts for GNU/Linux

You can configure Nexus to start automatically, by copying the nexus script to the /etc/init.d directory. On a GNU/Linux system (tested with Redhat, Fedora, Ubuntu, or CentOS) perform the following operations as the root user:

  1. Copy either ${NEXUS_HOME}/bin/jsw/linux-ppc-64/nexus, ${NEXUS_HOME}/bin/jsw/linux-x86-32/nexus, or ${NEXUS_HOME}/bin/jsw/linux-x86-64/nexus to /etc/init.d/nexus.

  2. Make the /etc/init.d/nexus script executable - chmod 755 /etc/init.d/nexus

  3. Edit this script changing the following variables:

    • Change APP_NAME to "nexus"

    • Change APP_LONG_NAME to "Sonatype Nexus"

    • Add a variable NEXUS_HOME which points to your Nexus installation directory

    • Add a variable PLATFORM which contains either linux-x86-32, linux-x86-64, or linux-ppc-64

    • Change WRAPPER_CMD to ${NEXUS_HOME}/bin/jsw/${PLATFORM}/wrapper

    • Change WRAPPER_CONF to ${NEXUS_HOME}/bin/jsw/conf/wrapper.conf

    • Change PIDDIR to /var/run.

    • Add a JAVA_HOME variable which points to your local Java installation

    • Add a ${JAVA_HOME}/bin to the PATH

  4. (Optional) Set the RUN_AS_USER to "nexus". If you do this, you will need to:

    • Create a nexus user

    • Change the Owner and Group of your nexus install directory to nexus

    Note

    If you set the "RUN_AS_USER" variable, you'll have to change the "pid" directory to point to a directory where this user has read/write permissions. In most Linux distributions, /var/run is only writable by root. The properties that would need to be added to customize the PID file location is "wrapper.pid". For more information about this property and how it would be configured in wrapper.conf, see: http://wrapper.tanukisoftware.com/doc/english/properties.html

Script Directory for 32-bit GNU/Linux in ${NEXUS_HOME}/bin/jsw

Figure 3.5. Script Directory for 32-bit GNU/Linux in ${NEXUS_HOME}/bin/jsw


At the end of this you should have a file in /etc/init.d/nexus which starts with a series of configuration properties which look something like this (assuming that you've installed Nexus in /usr/local/nexus and that you have Java installed in /usr/java/latest):

JAVA_HOME=/usr/java/latest
PATH=${PATH}:${JAVA_HOME}/bin
APP_NAME="nexus"
APP_LONG_NAME="Sonatype Nexus"
NEXUS_HOME=/usr/local/nexus
PLATFORM=linux-x86-64
WRAPPER_CMD="${NEXUS_HOME}/bin/jsw/${PLATFORM}/wrapper"
WRAPPER_CONF="${NEXUS_HOME}/bin/jsw/conf/wrapper.conf"
PRIORITY=
PIDDIR="/var/run"
#RUN_AS_USER=nexus

3.6.1.1. Add Nexus as a Service on Redhat, Fedora, and CentOS

This script has the appropriate chkconfig directives, so all you need to do to add Nexus as a service is run the following commands:

$ cd /etc/init.d
$ chkconfig --add nexus
$ chkconfig --levels 345 nexus on
$ service nexus start
Starting Sonatype Nexus...
$ tail -f /usr/local/nexus/logs/wrapper.log

The second command adds nexus as a service to be started and stopped with the service command and managed by the chkconfig command. chkconfig manages the symbolic links in /etc/rc[0-6].d which control the services to be started and stopped when the operating system restarts or transitions between run-levels. The third command adds nexus to run-levels 3, 4, and 5. The service command starts Nexus, and the last command tails the wrapper.log to verify that Nexus has been started successfully. If Nexus has started successfully, you should see a message notifying you that Nexus is listening for HTTP connections on a port.

3.6.1.2. Add Nexus as a Service on Ubuntu

The process for setting Nexus up as a service on Ubuntu differs slightly from the process used on a Redhat variant. Instead of running chkconfig, you should run the following sequence of commands once you've configured the startup script in /etc/init.d:

$ cd /etc/init.d
$ update-rc.d nexus defaults
$ service nexus start
Starting Sonatype Nexus...
$ tail -f /usr/local/nexus/logs/wrapper.log


[1] While many refer to GNU/Linux as Linux, we've decided to use GNU/Linux. For more information about GNU/Linux vs. Linux, see http://en.wikipedia.org/wiki/GNU/Linux_naming_controversy.

Sonatype Promotion Subscribe via RSS