Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Minecraft Server as systemd service
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gamers & Players
View previous topic :: View next topic  
Author Message
tatterdemalian
n00b
n00b


Joined: 21 Jul 2011
Posts: 46

PostPosted: Thu Jan 25, 2018 7:18 am    Post subject: Minecraft Server as systemd service Reply with quote

Trying to run a minecraft server as a systemd service, to automatically start/stop on system boot. Apparently something is screwed up in the environment for the sandboxed user ("minecraft"), because attempting to start the service results in failure, and the following messages in journalctl:

Jan 25 00:31:34 TatterTown systemd[1]: Started Minecraft Server.
Jan 25 00:31:35 TatterTown java[3632]: * Home for VM 'icedtea-bin-8' does not exist: /usr/lib/jvm//icedtea-bin-8
Jan 25 00:31:35 TatterTown java[3632]: * Invalid System VM: icedtea-bin-8

The server runs fine when I run it using the exact same command line as the "minecraft" user, though, no errors. Anyone know why running as a systemd service seems to screw up the JAVA_HOME environment variable? I really don't want to set it manually, as I'd prefer not to do something that might make eselect panic.

/etc/systemd/system/minecraft.service:

Code:

[Unit]
Description=Minecraft Server
Documentation=

# A network server likes to have the network available.

Wants=network.target
After=network.target

[Service]
User=minecraft
Group=minecraft

# Nice it up a little, so Mom can still play her card games, but don't go
# overboard.

Nice=1

# Actually, don't specify this, system services use private as default and if
# that changes it's probably for a good (read: structurally critical) reason.

#KeyringMode=private

# Use default KillMode until I can get an RCON script written. Change to
# "none" and set ExecStop to run it once it's ready.

KillMode=control-group

# Make sure systemd reports a clean shutdown, no matter what the jre says.

SuccessExitStatus=0 1

# Protect /home and everyone's files from the online menace.

ProtectHome=true

# Not using strict, too strict for the jre. Bar access to sensitive
# directories with InaccessiblePaths, instead.

ProtectSystem=full

# Don't let the server play with USB.

PrivateDevices=true

# Don't let the server play with privilege.

NoNewPrivileges=true

# Don't let the server play with /tmp.

PrivateTmp=true

# Don't let the server even see these, that's just asking for trouble.

InaccessiblePaths=/root /sys /srv -/opt /media -/lost+found

# Let the server play in this sandbox.

ReadWritePaths=/var/minecraft/server
WorkingDirectory=/var/minecraft/server

# Run the server when the service starts.

ExecStart=/usr/bin/java -Xmx1G -Xms1G -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark -jar spigot.jar --noconsole

# No ExecStop until the RCON script is ready. Until then, stop the server
# with an op command before stopping the service.

#ExecStop=

[Install]
WantedBy=multi-user.target
Back to top
View user's profile Send private message
tatterdemalian
n00b
n00b


Joined: 21 Jul 2011
Posts: 46

PostPosted: Sun Jan 28, 2018 2:11 am    Post subject: Reply with quote

Well, tried everything I could, even adding

Code:

Environment="JAVA_HOME=/usr/lib/jvm/icedtea-bin-8/"


to minecraft.service. No matter what, same error:

Jan 27 20:04:05 TatterTown systemd[1]: Started Minecraft Server.
Jan 27 20:04:06 TatterTown java[15599]: * Home for VM 'icedtea-bin-8' does not exist: /usr/lib/jvm//icedtea-bin-8
Jan 27 20:04:06 TatterTown java[15599]: * Invalid User VM: icedtea-bin-8

Apparently systemd overrides the JAVA_HOME environment variable with whatever it wants, and what it wants is a directory that doesn't exist.

Anyone know any way to make it use the correct home while running as a sandboxed service?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21431

PostPosted: Sun Jan 28, 2018 5:20 am    Post subject: Reply with quote

tatterdemalian wrote:
Code:
Environment="JAVA_HOME=/usr/lib/jvm/icedtea-bin-8/"
Jan 27 20:04:06 TatterTown java[15599]: * Home for VM 'icedtea-bin-8' does not exist: /usr/lib/jvm//icedtea-bin-8

Apparently systemd overrides the JAVA_HOME environment variable with whatever it wants, and what it wants is a directory that doesn't exist.
Your output seems to indicate that it respected JAVA_HOME and did not override it. Why do you think systemd is overriding this variable? To me, it looks like systemd preserved the variable, but confined the service to a chroot where $JAVA_HOME does not exist.
Back to top
View user's profile Send private message
tatterdemalian
n00b
n00b


Joined: 21 Jul 2011
Posts: 46

PostPosted: Mon Jan 29, 2018 1:06 am    Post subject: Reply with quote

Hu wrote:
tatterdemalian wrote:
Code:
Environment="JAVA_HOME=/usr/lib/jvm/icedtea-bin-8/"
Jan 27 20:04:06 TatterTown java[15599]: * Home for VM 'icedtea-bin-8' does not exist: /usr/lib/jvm//icedtea-bin-8

Apparently systemd overrides the JAVA_HOME environment variable with whatever it wants, and what it wants is a directory that doesn't exist.
Your output seems to indicate that it respected JAVA_HOME and did not override it. Why do you think systemd is overriding this variable? To me, it looks like systemd preserved the variable, but confined the service to a chroot where $JAVA_HOME does not exist.


Because it's using a double slash between directories instead of a single slash. The value I'm trying to set $JAVA_HOME to is "/usr/lib/jvm/icedtea-bin-8/" but the one java seems to be attempting to use is "/usr/lib/jvm//icedtea-bin-8"

Maybe it's not even using $JAVA_HOME, but instead some other environment variable when java is run as a systemd service?
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Jan 30, 2018 12:24 am    Post subject: Reply with quote

FWIW, minecraft runs no problem with a blank env (under runit), so try wrapping it in env -i.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gamers & Players All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum