TL:DR; to resolve, add an Environment
section to the system.d service file:
[Service]
Environment="INSTALL4J_JAVA_HOME=/home/nexus/.sdkman/candidates/java/current/"
Long-form answer:
As of this writing, the Sonatype documents say to use the following file as your /etc/systemd/system/nexus.service
file, which works great if you installed java to your service user via the system distribution (ensuring your distro's java home is managed by the system). That doesn't work to resolve my question:
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
TimeoutSec=600
[Install]
WantedBy=multi-user.target
To resolve, you must add the Environment variable to the system.d service file (with your_user
replaced by the user you are running nexus
as, and /opt/nexus
being replaced by your nexus install location):
[Unit]
Description=nexus service
After=network.target
[Service]
Environment="INSTALL4J_JAVA_HOME=/home/your_user/.sdkman/candidates/java/current/"
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=your_user
Restart=on-abort
TimeoutSec=600
[Install]
WantedBy=multi-user.target