Run as a Service
When installing Nexus Repository for production usage it has to be configured to run as a service, so it restarts after the server reboots. It is good practice to run that service or daemon as a specific user that has only the required access rights. Installation from the distribution archive does not include the configuration of a service. The following sections provide instructions for configuring the service manually. Independent of the operating system the steps are:
Create an operating system user with limited access rights dedicated to running the repository manager as a service
Ensure a suitable Java runtime environment is installed
Configure the service and ensure it starts as part of the operating system boot process
Linux
You can configure the repository manager to run as a service with init.d
or systemd
. Both are startup frameworks used in Linux-based systems such as Ubuntu and CentOS. They are, essentially, init scripts that load commands to manage the repository manager daemon. Before running the service configure an absolute path for your repository manager files. Then create a nexus
user with sufficient access rights to run the service. In bin/nexus.rc
assign the user between the quotes in the line below:
run_as_user="nexus"
Symlink $installdir/bin/nexus
to /etc/init.d/nexus
:
sudo ln -s /opt/nexus-3.15.2-01/bin/nexus /etc/init.d/nexus
Adjust the location (shown above as "/opt/nexus-3.15.2-01'") as needed for your installation location.
chkconfig
This example uses chkconfig
, a tool that targets the init scripts in init.d
to run the nexus
service. Run these commands to activate the service:
cd /etc/init.d sudo chkconfig --add nexus sudo chkconfig --levels 345 nexus on sudo service nexus start
The second command adds nexus as a service to be started and stopped with the 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. Then the service command starts the repository manager.
update-rc.d
This example usesupdate-rc.d
, a tool similar to the chkconfig
.
cd /etc/init.d sudo update-rc.d nexus defaults sudo service nexus start
In the second line, you will run a default priority to add the nexus
service before starting it.
systemd
This example is a script that uses systemd
to run the repository manager service. Create a file called nexus.service
. Add the following contents, then save the file in the /etc/systemd/system/
directory:
[Unit] Description=nexus service After=network.target [Service] Type=forking LimitNOFILE=65536 ExecStart=/etc/init.d/nexus start ExecStop=/etc/init.d/nexus stop User=nexus Restart=on-abort TimeoutSec=600 [Install] WantedBy=multi-user.target
Activate the service with the following commands:
sudo systemctl daemon-reload sudo systemctl enable nexus.service sudo systemctl start nexus.service
After starting the service for any Linux-based operating system, verify that the service started successfully.
tail -f /opt/sonatype-work/nexus3/log/nexus.log
The tail command verifies that the service has been started successfully. If successful, you should see a message notifying you that it is listening for HTTP.
Warning
Be sure to assign the appropriate permissions to the user running the nexus
service.
PID File
When started as a service on Linux, Nexus Repository will create a file that holds a process ID in the operating system /tmp directory. This file will have the name of the form:
prefix: "i4jdaemon_"
suffix: the absolute path to the nexus start script with path part separators replaced with underscores
Example: Temporary directory is /tmp and the path to start the script is at /opt/nexus/nexus-3.14.0-04/bin/nexus, then the file created will be at "/tmp/i4jdaemon__opt_nexus_nexus-3.14.0-04_bin_nexus".
If the service pid file cannot be written the service startup will silently fail, without any logging statements written to the nexus.log.
If the Nexus Repository process is already stopped, and the service is failing to start, first confirm there is no log output being added to the nexus.log file. If not, then check for a pre-existing pid file. If that file is present, delete it first before trying to start the service.
The directory this file is created in can optionally be changed by editing $install-dir/bin/nexus.vmoptions and adding a line like this:
|
The directory specified by the property must already exist for the property to work - the directory will not be created automatically.
Native Linux Installers from the community
There are community-provided native installers for Linux available here: nexus-repository-installer
These installers set up Nexus Repository Manager to run as a service. NOTE: These are provided by the community, and not officially supported.
Windows
The startup script that runs Nexus Repository on Windows platforms is bin/nexus.exe
. The script includes standard commands for starting and stopping the service. It also contains commands install
and uninstall
to create and delete the configuration for the service. You can create the service configuration with:
nexus.exe /install <optional-service-name>
The new service is named nexus
by default. It is available in the Windows console application to manage services such as Windows Services. You can start, stop, and restart the service there as well as configure it to start as part of an operating system startup. Alternatively, you can manage the service on the command line:
nexus.exe /start <optional-service-name> nexus.exe /stop <optional-service-name> nexus.exe /uninstall <optional-service-name>
The <optional-service-name>
parameter with a value of e.g. nexus3
can be used to create a service that does not collide with an existing service established for Nexus Repository Manager 2 running on the same server.
Mac OS
The standard way to run a service on Mac OS is to use launchd
, a program that starts, stops, and manages daemons and scripts in Apple OS X environments. To run the service you need to create an XML document called with the file extension .plist
to define its properties. An example plist file for the repository manager installed in /opt
is shown here:
A sample com.sonatype.nexus.plist file
<!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>/opt/nexus/bin/nexus</string> <string>start</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
Consider setting up a different user to run the repository manager and adapt permissions and the RUN_AS_USER
setting in the nexus startup script. With this setup, the repository manager starts 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