Skip to content

Instantly share code, notes, and snippets.

@esamson
Last active April 28, 2019 14:56
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save esamson/97d183e3225a2965d979 to your computer and use it in GitHub Desktop.
Save esamson/97d183e3225a2965d979 to your computer and use it in GitHub Desktop.
systemd service file for sonatype nexus. Put this in `$HOME/.config/systemd/user/nexus.service`. Launch with `systemctl --user start nexus`.
default.target.wants/
nexus
[Unit]
Description=Sonatype Nexus
[Service]
Type=forking
PIDFile=%h/.local/opt/nexus/bin/jsw/linux-x86-64/nexus.pid
ExecStart=%h/.local/opt/nexus/bin/nexus start
ExecReload=%h/.local/opt/nexus/bin/nexus restart
ExecStop=%h/.local/opt/nexus/bin/nexus stop
[Install]
Alias=nexus
WantedBy=default.target
@stephenfuqua
Copy link

Great script. I left out the PIDFile originally and suffered for it. Without it, systemd does not realize that the service is actually starting and it immediately kills the service.

@farahfa
Copy link

farahfa commented Nov 30, 2016

In 2.14.0-01 there's no nexus.pid there's only wrapper.. Should I use that instead?

@tearsakura
Copy link

on nexus 3.2

[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target

@lbruun
Copy link

lbruun commented Nov 11, 2017

Nexus 3.6 on CentOS 7

Note that I needed to set the INSTALL4J_JAVA_HOME env var, as I do not have a globally defined java in the path. Also I needed to increase the number of file descriptors, i.e. the LimitNOFILE property.

[Unit]
Description=Sonatype Nexus Repository Manager
After=network.target

[Service]
Type=forking
ExecStart=/apps/nexus/current/bin/nexus start
ExecStop=/apps/nexus/current/bin/nexus stop
User=nexus
Restart=on-abort
Environment=INSTALL4J_JAVA_HOME=/foo/bar/jre8
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

@dtonhofer
Copy link

@Ibruun's solution is the one currently used by Sonatype at

https://help.sonatype.com/repomanager3/installation/run-as-a-service#RunasaService-systemd

But the fact that systemd still starts an (really complex) init script /apps/nexus/current/bin/nexus is jarring; that's not how it is supposed to be done....

@glynnforrest
Copy link

@dtonhofer instead of ./bin/nexus start, do you think ./bin/nexus run would work with Type=simple?

@dtonhofer
Copy link

@glynnforrest I don't know, you will have to try. But there is no good reason to change from the forking modus, is there?

@glynnforrest
Copy link

@dtonhofer I did run it but wasn't sure if it would break nexus in some subtle way. nexus run spits the logs out to stdout so they appear in the systemd journal, which is quite handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment