18.04 - how to create PID file in systemd unit?
up vote
0
down vote
favorite
I am trying to properly setup my minecraft server with systemd so that it correctly determines the main PID for the process. I have the following systemd service unit:
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
Group=minecraft
WorkingDirectory=/srv/minecraft
ProtectSystem=full
ProtectHome=true
Type=forking
ExecStartPre=/srv/minecraft/mc_server.sh setup
ExecStart=/srv/minecraft/mc_server.sh start
PIDFile=/srv/minecraft/mc.pid
ExecStop=/srv/minecraft/mc_server.sh stop
[Install]
WantedBy=multi-user.target
When I attempt to start the service, I get this error message (the main issue being the "failed to parse PID from file" part):
minecraft.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Wed 2018-11-28 12:57:03 PST; 6min ago
Process: 9611 ExecStart=/srv/minecraft/mc_server.sh start (code=exited, status=0/SUCCESS)
Process: 9591 ExecStartPre=/srv/minecraft/mc_server.sh setup (code=exited, status=0/SUCCESS)
Main PID: 5213 (code=exited, status=0/SUCCESS)
Nov 28 12:55:32 xxx mc_server.sh[9591]: No Session found. Creating and configuring.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9607 (tmux: server) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9608 (bash) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx mc_server.sh[9611]: Minecraft server successfully started
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Failed to parse PID from file /srv/minecraft/mc.pid: Invalid argument
Nov 28 12:57:02 xxx systemd[1]: minecraft.service: Start operation timed out. Terminating.
Nov 28 12:57:03 xxx systemd[1]: minecraft.service: Failed with result 'timeout'.
Nov 28 12:57:03 xxx systemd[1]: Failed to start Minecraft Server.
I'm not sure what this error means or how to resolve it. If I remove the PIDfile= option then it works, but lists the tmux process as the main PID and therefore doesn't record output from the java process in the logs. I also just noticed that it's not actually writing the PID to mc.pid. When running the script directly it does write the PID correctly.
Here is the contents of "mc_server.sh start", which is how I'm starting the server and creating the PID file (note that the tmux session is created during "mc_server.sh setup"):
/usr/bin/tmux send-keys -t minecraft '/usr/bin/java -server -Xmx2048M -Xms1024M -jar /srv/minecraft/minecraft_server.jar nogui' C-m &&
/usr/bin/pgrep -u minecraft -f minecraft_server.jar > /srv/minecraft/mc.pid
server java systemd minecraft tmux
add a comment |
up vote
0
down vote
favorite
I am trying to properly setup my minecraft server with systemd so that it correctly determines the main PID for the process. I have the following systemd service unit:
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
Group=minecraft
WorkingDirectory=/srv/minecraft
ProtectSystem=full
ProtectHome=true
Type=forking
ExecStartPre=/srv/minecraft/mc_server.sh setup
ExecStart=/srv/minecraft/mc_server.sh start
PIDFile=/srv/minecraft/mc.pid
ExecStop=/srv/minecraft/mc_server.sh stop
[Install]
WantedBy=multi-user.target
When I attempt to start the service, I get this error message (the main issue being the "failed to parse PID from file" part):
minecraft.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Wed 2018-11-28 12:57:03 PST; 6min ago
Process: 9611 ExecStart=/srv/minecraft/mc_server.sh start (code=exited, status=0/SUCCESS)
Process: 9591 ExecStartPre=/srv/minecraft/mc_server.sh setup (code=exited, status=0/SUCCESS)
Main PID: 5213 (code=exited, status=0/SUCCESS)
Nov 28 12:55:32 xxx mc_server.sh[9591]: No Session found. Creating and configuring.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9607 (tmux: server) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9608 (bash) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx mc_server.sh[9611]: Minecraft server successfully started
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Failed to parse PID from file /srv/minecraft/mc.pid: Invalid argument
Nov 28 12:57:02 xxx systemd[1]: minecraft.service: Start operation timed out. Terminating.
Nov 28 12:57:03 xxx systemd[1]: minecraft.service: Failed with result 'timeout'.
Nov 28 12:57:03 xxx systemd[1]: Failed to start Minecraft Server.
I'm not sure what this error means or how to resolve it. If I remove the PIDfile= option then it works, but lists the tmux process as the main PID and therefore doesn't record output from the java process in the logs. I also just noticed that it's not actually writing the PID to mc.pid. When running the script directly it does write the PID correctly.
Here is the contents of "mc_server.sh start", which is how I'm starting the server and creating the PID file (note that the tmux session is created during "mc_server.sh setup"):
/usr/bin/tmux send-keys -t minecraft '/usr/bin/java -server -Xmx2048M -Xms1024M -jar /srv/minecraft/minecraft_server.jar nogui' C-m &&
/usr/bin/pgrep -u minecraft -f minecraft_server.jar > /srv/minecraft/mc.pid
server java systemd minecraft tmux
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to properly setup my minecraft server with systemd so that it correctly determines the main PID for the process. I have the following systemd service unit:
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
Group=minecraft
WorkingDirectory=/srv/minecraft
ProtectSystem=full
ProtectHome=true
Type=forking
ExecStartPre=/srv/minecraft/mc_server.sh setup
ExecStart=/srv/minecraft/mc_server.sh start
PIDFile=/srv/minecraft/mc.pid
ExecStop=/srv/minecraft/mc_server.sh stop
[Install]
WantedBy=multi-user.target
When I attempt to start the service, I get this error message (the main issue being the "failed to parse PID from file" part):
minecraft.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Wed 2018-11-28 12:57:03 PST; 6min ago
Process: 9611 ExecStart=/srv/minecraft/mc_server.sh start (code=exited, status=0/SUCCESS)
Process: 9591 ExecStartPre=/srv/minecraft/mc_server.sh setup (code=exited, status=0/SUCCESS)
Main PID: 5213 (code=exited, status=0/SUCCESS)
Nov 28 12:55:32 xxx mc_server.sh[9591]: No Session found. Creating and configuring.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9607 (tmux: server) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9608 (bash) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx mc_server.sh[9611]: Minecraft server successfully started
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Failed to parse PID from file /srv/minecraft/mc.pid: Invalid argument
Nov 28 12:57:02 xxx systemd[1]: minecraft.service: Start operation timed out. Terminating.
Nov 28 12:57:03 xxx systemd[1]: minecraft.service: Failed with result 'timeout'.
Nov 28 12:57:03 xxx systemd[1]: Failed to start Minecraft Server.
I'm not sure what this error means or how to resolve it. If I remove the PIDfile= option then it works, but lists the tmux process as the main PID and therefore doesn't record output from the java process in the logs. I also just noticed that it's not actually writing the PID to mc.pid. When running the script directly it does write the PID correctly.
Here is the contents of "mc_server.sh start", which is how I'm starting the server and creating the PID file (note that the tmux session is created during "mc_server.sh setup"):
/usr/bin/tmux send-keys -t minecraft '/usr/bin/java -server -Xmx2048M -Xms1024M -jar /srv/minecraft/minecraft_server.jar nogui' C-m &&
/usr/bin/pgrep -u minecraft -f minecraft_server.jar > /srv/minecraft/mc.pid
server java systemd minecraft tmux
I am trying to properly setup my minecraft server with systemd so that it correctly determines the main PID for the process. I have the following systemd service unit:
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
Group=minecraft
WorkingDirectory=/srv/minecraft
ProtectSystem=full
ProtectHome=true
Type=forking
ExecStartPre=/srv/minecraft/mc_server.sh setup
ExecStart=/srv/minecraft/mc_server.sh start
PIDFile=/srv/minecraft/mc.pid
ExecStop=/srv/minecraft/mc_server.sh stop
[Install]
WantedBy=multi-user.target
When I attempt to start the service, I get this error message (the main issue being the "failed to parse PID from file" part):
minecraft.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Wed 2018-11-28 12:57:03 PST; 6min ago
Process: 9611 ExecStart=/srv/minecraft/mc_server.sh start (code=exited, status=0/SUCCESS)
Process: 9591 ExecStartPre=/srv/minecraft/mc_server.sh setup (code=exited, status=0/SUCCESS)
Main PID: 5213 (code=exited, status=0/SUCCESS)
Nov 28 12:55:32 xxx mc_server.sh[9591]: No Session found. Creating and configuring.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9607 (tmux: server) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Found left-over process 9608 (bash) in control group while starting unit. Ignoring.
Nov 28 12:55:32 xxx systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
Nov 28 12:55:32 xxx mc_server.sh[9611]: Minecraft server successfully started
Nov 28 12:55:32 xxx systemd[1]: minecraft.service: Failed to parse PID from file /srv/minecraft/mc.pid: Invalid argument
Nov 28 12:57:02 xxx systemd[1]: minecraft.service: Start operation timed out. Terminating.
Nov 28 12:57:03 xxx systemd[1]: minecraft.service: Failed with result 'timeout'.
Nov 28 12:57:03 xxx systemd[1]: Failed to start Minecraft Server.
I'm not sure what this error means or how to resolve it. If I remove the PIDfile= option then it works, but lists the tmux process as the main PID and therefore doesn't record output from the java process in the logs. I also just noticed that it's not actually writing the PID to mc.pid. When running the script directly it does write the PID correctly.
Here is the contents of "mc_server.sh start", which is how I'm starting the server and creating the PID file (note that the tmux session is created during "mc_server.sh setup"):
/usr/bin/tmux send-keys -t minecraft '/usr/bin/java -server -Xmx2048M -Xms1024M -jar /srv/minecraft/minecraft_server.jar nogui' C-m &&
/usr/bin/pgrep -u minecraft -f minecraft_server.jar > /srv/minecraft/mc.pid
server java systemd minecraft tmux
server java systemd minecraft tmux
edited 2 days ago
asked Nov 28 at 21:14
MysticEagle
184
184
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1096933%2f18-04-how-to-create-pid-file-in-systemd-unit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown