Repository Management with Nexus
3.7. Configuring Nexus as a Service

3.7. Configuring Nexus as a Service

When installing Nexus for production usage you should configure Nexus as a service, so it starts back up after server reboots. It is good practice to run that service or daemon as a specific user that has only the required access righs. The following sections provide instructions for configuring Nexus as a service or daemon on various operating systems.

3.7.1. Running as a Service on Linux

You can configure Nexus to start automatically, by copying the nexus script to the /etc/init.d directory. On a Linux system perform the following operations as the root user:

  1. Copy either $NEXUS_HOME/bin/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:

    1. Change NEXUS_HOME to the absolute folder location e.g. NEXUS_HOME="/usr/local/nexus"
    2. Optionally change PIDDIR to /var/run
    3. If Java is not on the default path for the user running Nexus, add a JAVA_HOME variable which points to your local Java installation and 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:

    1. Create a nexus user
    2. 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

Add Nexus as a Service on Red Hat, 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 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

Add Nexus as a Service on Ubuntu and Debian

The process for setting Nexus up as a service on Ubuntu differs slightly from the process used on a Red Hat variant. Instead of running chkconfig, you should run the following sequence of commands once you’ve configured the start-up 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

3.7.2. Running as a Service on Mac OS X

The standard way to run a service on Mac OS X is by using launchd, which uses plist files for configuration. An example plist file for Nexus in shown A sample com.sonatype.nexus.plist file.

A sample com.sonatype.nexus.plist file. 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.sonatype.nexus</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/nexus/bin/nexus</string>
        <string>console</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

After saving the file as "com.sonatype.nexus.plist" in /Library/LaunchDaemons/ you have to change the ownership and access rights.

sudo chown root:wheel /Library/LaunchDaemons/com.sonatype.nexus.plist
sudo chmod 644 /Library/LaunchDaemons/com.sonatype.nexus.plist

Tip

Consider setting up a different user to run Nexus and adapt permissions and the RUN_AS_USER setting in the nexus startup script.

With this setup Nexus will start as a service at boot time. To manually start it after the configuration you can use

sudo launchctl load /Library/LaunchDaemons/com.sonatype.nexus.plist

3.7.3. Running as a Service on Windows

The start-up script for Nexus on Windows platforms is bin/nexus.bat. Besides the standard commands for starting and stopping the service it has the additional commands install and uninstall. Running these commands with elevated privileges will set up the service for you or remove it as desired. Once installed as a service with the install command the batch file can be used to start and stop the service. In addition the service will be available in the usual Windows service management console with the nexus.

Sonatype Promotion Subscribe via RSS