You are not logged in.
Hi guys,
As the title says, I want to create my own systemd .service file. It should start/stop my minecraft server automatically on boot/shutdown. I have had the bash script (http://pastebin.com/ntJJh3Ru) before, it uses some other scripts, but it works. If you exec ./mcserv start, it starts the minecraft server, if you do ./mcserv stop, it stops it. Then I wanted to make it automatically start on bootup. Here's my .service file: http://pastebin.com/Ty5RSRWv, but here's the output of sudo systemctl start minecraftserver-mcserv.service and then sudo systemctl status minecraftserver-mcserv.service:
[mr@server ~]$ sudo systemctl start minecraftserver-mcserv
[mr@server ~]$ sudo systemctl status minecraftserver-mcserv
minecraftserver-mcserv.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraftserver-mcserv.service; disabled)
Active: failed (Result: exit-code) since Fr 2014-03-14 13:12:25 CET; 1s ago
Process: 599 ExecStop=/home/mr/minecraft-server/mcserv stop (code=exited, status=2)
Process: 570 ExecStart=/home/mr/minecraft-server/mcserv start (code=exited, status=2)
Main PID: 570 (code=exited, status=2)
Mär 14 13:12:25 server mcserv[599]: tput: No value for $TERM and no -T specified
Mär 14 13:12:25 server mcserv[599]: ] Licensed under the GNU GPL.
Mär 14 13:12:25 server mcserv[599]: /home/mr/minecraft-server/mcserv: Zeile 85: screenonline: Kommand...nden.
Mär 14 13:12:25 server mcserv[599]: tput: No value for $TERM and no -T specified
Mär 14 13:12:25 server mcserv[599]: tput: No value for $TERM and no -T specified
Mär 14 13:12:25 server mcserv[599]: [tput: No value for $TERM and no -T specified
Mär 14 13:12:25 server mcserv[599]: FAILEDtput: No value for $TERM and no -T specified
Mär 14 13:12:25 server mcserv[599]: tput: No value for $TERM and no -T specified
Mär 14 13:12:25 server mcserv[599]: ] Server not running, aborting...
Mär 14 13:12:25 server mcserv[599]: tput: No value for $TERM and no -T specified
Mär 14 13:12:25 server systemd[1]: minecraftserver-mcserv.service: control process exited, code=exite...tus=2
Mär 14 13:12:25 server systemd[1]: Unit minecraftserver-mcserv.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.If you want to test it you need:
GNU screen
My script REQUIRE (http://www.marco-rebhan.de/mirror/linux-script/REQUIRE), it must be in ~/bin folder and that folder must be in your PATH.
Minecraft test server (https://s3.amazonaws.com/Minecraft.Down … .1.7.5.jar), must be in the same folder as mcserv script and named minecraft-server.jar
Then run:
./mcserv startto start it and
./mcserv stopto stop, you can also run
./mcservto get all the arguments etc etc.
Why doesn't my .service work when mcserv works perfect?
Please help! I want to make this fully automated ![]()
Last edited by HyperLink (2014-03-14 12:36:56)
Offline
Look at the errors in the journal. There's a lot of noise because your scripts assume they're running in a terminal and use tput everywhere.
There's also a message about screenonline. It's incomplete (see the hint at the bottom of the systemctl status output; you may also want to use LANG=C temporarily to avoid posting German messages here), but I think it says "Kommando nicht gefunden" and that makes sense, because while you say that ~/bin has to be in your PATH to run the script, you're not setting the PATH in the service file and ~/bin shouldn't be in the default PATH. Also, unless I'm mistaken, the shell that executes the script is neither a login shell nor an interactive shell, so any PATH exports in .bash_profile/.bashrc won't affect it.
Offline
With a 'Type=simple' .service, systemd is expecting the 'ExecStart' command to not exit whilst the service is active.
The other Exec* commands are used to manipulate the active service.
Your 'mcserv start' doesn't do that, as it spawns and then exits. This is an unexpected exit, so systemd calls the ExecStop (if defined, which it is in your case) to cleanup the unexpected exit.
So your service is doing a start immediately followed by a stop.
In this scenario, the solution is to use the 'RemainAfterExit' option. See systemd.service man page. This will tell systemd to consider your service still active, even though the process has exited.
Edit: looks like I took too long to write my reply.
Last edited by ukhippo (2014-03-14 13:32:46)
Offline
Hm, okay. I'll have a look at the man page for systemd.service, maybe I can find out more...
You say the PATH must include ~/bin...
So the lines are like this?
[Unit]
Description=Minecraft Server
[Service]
RemainAfterExit=yes
User=mr
ExecStart=PATH=/home/mr/bin:$PATH /home/mr/minecraft-server/mcserv start
ExecReload=/home/mr/bin:$PATH /home/mr/minecraft-server/mcserv restart
ExecStop=/home/mr/bin:$PATH /home/mr/minecraft-server/mcserv stop
[Install]
WantedBy=multi-user.targetI will test this, if it works, Thank you!
EDIT: Nope, it doesn't like PATH=...
Continue testing xD
Last edited by HyperLink (2014-03-16 07:29:03)
Offline
Okay. The output is now this:
[mr@server ~]$ sudo systemctl start minecraftserver-mcserv
[mr@server ~]$ sudo systemctl status minecraftserver-mcserv
minecraftserver-mcserv.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraftserver-mcserv.service; disabled)
Active: active (exited) (Result: exit-code) since So 2014-03-16 08:34:28 CET; 6s ago
Process: 1073 ExecStart=/home/mr/setpath; /home/mr/minecraft-server/mcserv start (code=exited, status=203/EXEC)
Main PID: 1073 (code=exited, status=203/EXEC)
Mär 16 08:34:28 server systemd[1]: Started Minecraft Server.
Mär 16 08:34:28 server systemd[1]: minecraftserver-mcserv.service: main process exited, code=exited, status=203/EXEC
[mr@server ~]$ sudo systemctl stop minecraftserver-mcserv
[mr@server ~]$ sudo systemctl status minecraftserver-mcserv
minecraftserver-mcserv.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraftserver-mcserv.service; disabled)
Active: failed (Result: exit-code) since So 2014-03-16 08:34:53 CET; 1s ago
Process: 1080 ExecStop=/home/mr/setpath; /home/mr/minecraft-server/mcserv stop (code=exited, status=203/EXEC)
Process: 1073 ExecStart=/home/mr/setpath; /home/mr/minecraft-server/mcserv start (code=exited, status=203/EXEC)
Main PID: 1073 (code=exited, status=203/EXEC)
Mär 16 08:34:28 server systemd[1]: Started Minecraft Server.
Mär 16 08:34:28 server systemd[1]: minecraftserver-mcserv.service: main process exited, code=exited, status=203/EXEC
Mär 16 08:34:53 server systemd[1]: Stopping Minecraft Server...
Mär 16 08:34:53 server systemd[1]: minecraftserver-mcserv.service: control process exited, code=exited status=203
Mär 16 08:34:53 server systemd[1]: Stopped Minecraft Server.
Mär 16 08:34:53 server systemd[1]: Unit minecraftserver-mcserv.service entered failed state.and the file contains this:
[Unit]
Description=Minecraft Server
[Service]
RemainAfterExit=yes
User=mr
ExecStart=/home/mr/setpath; /home/mr/minecraft-server/mcserv start
ExecReload=/home/mr/setpath; /home/mr/minecraft-server/mcserv restart
ExecStop=/home/mr/setpath; /home/mr/minecraft-server/mcserv stop
[Install]
WantedBy=multi-user.targetWhat am I doing wrong?
What's wierd is, that it doesnt show those tput messages anymore, and when I execute
systemctl start minecraftserver-mcserv,
~/minecraft-server/mcserv statusstill says the server is offline...
Offline
The main issue is that for running under systemd your mcserv script is not fit for purpose.
Start afresh. Create the following sd-mcserv script:
#!/bin/bash
. ~/.bashrc
nohup java -jar minecraft-server.jar &
echo $! > /run/sd-mcserv.pidAnd the service file:
[Unit]
Description=Minecraft Server
[Service]
Type=forking
User=mr
PIDFile=/run/sd-mcserv.pid
ExecStart=/path/to/sd-mcserv
[Install]
WantedBy=multi-user.targetGet that working first, then build on that.
Offline
Hm, I'd really like to have that minecraft server as a GNU screen... Otherwise it's not really controllable
The problem is, I have to first attach the screen session once before I can do "screen -X stuff ...."
Last edited by HyperLink (2014-03-16 12:49:12)
Offline
In that case make the script use screen, and go back to a Type=simple service. Again, this is just the bare-bones so it should be easier to see what errors occur. You can implement a stop behaviour if kill is too drastic, once you know the service will startup OK.
Updated sd-mcserv script:
#!/bin/bash
. ~/.bashrc
screen -d -m -S mcserv java -jar minecraft-server.jarThe updated service file:
[Unit]
Description=Minecraft Server
[Service]
User=mr
RemainAfterExit=true
ExecStart=/path/to/sd-mcserv
[Install]
WantedBy=multi-user.targetOffline
Ok, that works, but how to stop it? kill always locks up my whole command blocks, and for screen -X stuff the screen must be visiited atleast once... ![]()
systemctl stop mcserv just sets the status to inactive(dead)...
Offline
Can you not use -X quit to kill it? If so you could use that as the ExecStop command in the service file.
However, if that doesn't cut it extend the sd-mcserv script to support $1 being start/stop and implement stop. Perhaps using a cut-down version of the stop from your original mcserv script.
Offline
Yes, but as I said, kill or anything like that locks up my command block redstone circiut and -X stuff requires the screen to tlease be opened once ![]()
Is there any way to open the screen quickly and detach it then again? That would solve my problem with -X stuff.
Offline
Have you tried using tmux instead of screen (just for minecraft server)?
Offline
Hm, never used tmux too much
I'll read the manpage for that first ![]()
Offline
The wiki page is quite helpful; it has an example .service for auto-starting a tmux session.
You could tweak the ExecStart line (and ExecStop if you change the session name) to run the minecraft server. You may also want to add "-c $HOME" to the ExecStart line so that it starts up in your home directory instead of '/'.
To replace stuff, look at send-keys.
Offline