2.6. Startup Scripts for Linux

You can configure Nexus to start automatically, by copying the app script to the /etc/init.d directory. On a 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}/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

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}/conf/wrapper.conf"
PRIORITY=
PIDDIR="/var/run"
#RUN_AS_USER=nexus

2.6.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 chkconfig command. chkconfig manages the symbolic links in /etc/rc[0-6].d which control the services which are 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.

2.6.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