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.
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:
-
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/nexusto/etc/init.d/nexus. -
Make the
/etc/init.d/nexusscript executable - chmod 755 /etc/init.d/nexus -
Edit this script changing the following variables:
-
Change
APP_NAMEto "nexus" -
Change
APP_LONG_NAMEto "Sonatype Nexus" -
Add a variable
NEXUS_HOMEwhich points to your Nexus installation directory -
Add a variable
PLATFORMwhich contains eitherlinux-x86-32,linux-x86-64, orlinux-ppc-64 -
Change
WRAPPER_CMDto${NEXUS_HOME}/bin/jsw/${PLATFORM}/wrapper -
Change
WRAPPER_CONFto${NEXUS_HOME}/bin/jsw/conf/wrapper.conf -
Change
PIDDIRto/var/run. -
Add a
JAVA_HOMEvariable which points to your local Java installation -
Add a
${JAVA_HOME}/binto thePATH
-
-
(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
-
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
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.
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.
