Skip to main content
added 15 characters in body
Source Link
Tiky
  • 146
  • 3

Add a new minecraft.socket file (assuming your service is named minecraft.service) to bind your server's input to:

[Unit]
BindsTo=minecraft.service
    
[Socket]
ListenFIFO=/run/minecraft.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=user
SocketGroup=user_group

Then modify your minecraft.service file to not send SIGTERM, bind standard input to the socket by modifying ExecStart with an exec wrapper. Then ExecStop will simply write to the new socket to send "/stop\n" to the input.

[Service]
...
KillSignal=SIGCONT
Sockets=testSockets=minecraft.socket
ExecStart=/bin/sh -c "exec /usr/local/bin/services/minecraft/run.sh </run/test.control"
ExecStop=/bin/sh -c "echo /stop >/run/testminecraft.control"

Bonus, you'll be able to send command to the server using echo "/command" > /run/minecraft.control anytime.

You don't have to take care of adding dependencies to the .service file, it is automatically added by the Sockets= option, the BindsTo= option will take care of stopping the socket and cleaning up the FIFO file when the service stops.


Here are some clarifications from suggestions of the original author.

Why do we have to use KillSignal=SIGCONT?

This prevent sending SIGTERM to the server process and cause a premature stopping of the process. It will still send SIGKILL after a certain time unless you add some more parameters (man systemd.kill).

Sockets=xxx contains the name of the Socket you created above, correct?

Yes

The socket-file (in this case testminecraft.socket?) has to be placed in the same directory as the service?

Yes, usually /etc/systemd/system/ if added by the sysadmin.

Add a new minecraft.socket file (assuming your service is named minecraft.service) to bind your server's input to:

[Unit]
BindsTo=minecraft.service
    
[Socket]
ListenFIFO=/run/minecraft.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=user
SocketGroup=user_group

Then modify your minecraft.service file to not send SIGTERM, bind standard input to the socket by modifying ExecStart with an exec wrapper. Then ExecStop will simply write to the new socket to send "/stop\n" to the input.

[Service]
...
KillSignal=SIGCONT
Sockets=test.socket
ExecStart=/bin/sh -c "exec /usr/local/bin/services/minecraft/run.sh </run/test.control"
ExecStop=/bin/sh -c "echo /stop >/run/test.control"

Bonus, you'll be able to send command to the server using echo "/command" > /run/minecraft.control anytime.

You don't have to take care of adding dependencies to the .service file, it is automatically added by the Sockets= option, the BindsTo= option will take care of stopping the socket and cleaning up the FIFO file when the service stops.


Here are some clarifications from suggestions of the original author.

Why do we have to use KillSignal=SIGCONT?

This prevent sending SIGTERM to the server process and cause a premature stopping of the process. It will still send SIGKILL after a certain time unless you add some more parameters (man systemd.kill).

Sockets=xxx contains the name of the Socket you created above, correct?

Yes

The socket-file (in this case test.socket?) has to be placed in the same directory as the service?

Yes, usually /etc/systemd/system/ if added by the sysadmin.

Add a new minecraft.socket file (assuming your service is named minecraft.service) to bind your server's input to:

[Unit]
BindsTo=minecraft.service
    
[Socket]
ListenFIFO=/run/minecraft.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=user
SocketGroup=user_group

Then modify your minecraft.service file to not send SIGTERM, bind standard input to the socket by modifying ExecStart with an exec wrapper. Then ExecStop will simply write to the new socket to send "/stop\n" to the input.

[Service]
...
KillSignal=SIGCONT
Sockets=minecraft.socket
ExecStart=/bin/sh -c "exec /usr/local/bin/services/minecraft/run.sh </run/test.control"
ExecStop=/bin/sh -c "echo /stop >/run/minecraft.control"

Bonus, you'll be able to send command to the server using echo "/command" > /run/minecraft.control anytime.

You don't have to take care of adding dependencies to the .service file, it is automatically added by the Sockets= option, the BindsTo= option will take care of stopping the socket and cleaning up the FIFO file when the service stops.


Here are some clarifications from suggestions of the original author.

Why do we have to use KillSignal=SIGCONT?

This prevent sending SIGTERM to the server process and cause a premature stopping of the process. It will still send SIGKILL after a certain time unless you add some more parameters (man systemd.kill).

Sockets=xxx contains the name of the Socket you created above, correct?

Yes

The socket-file (in this case minecraft.socket?) has to be placed in the same directory as the service?

Yes, usually /etc/systemd/system/ if added by the sysadmin.

added 584 characters in body
Source Link
Tiky
  • 146
  • 3

Add a new minecraft.socket file (assuming your service is named minecraft.service) to bind your server's input to:

[Unit]
BindsTo=minecraft.service
    
[Socket]
ListenFIFO=/run/minecraft.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=user
SocketGroup=user_group

Then modify your minecraft.service file to not send SIGTERM, bind standard input to the socket by modifying ExecStart with an exec wrapper. Then ExecStop will simply write to the new socket to send "/stop\n" to the input.

[Service]
...
KillSignal=SIGCONT
Sockets=test.socket
ExecStart=/bin/sh -c "exec /usr/local/bin/services/minecraft/run.sh </run/test.control"
ExecStop=/bin/sh -c "echo /stop >/run/test.control"

Bonus, you'll be able to send command to the server using echo "/command" > /run/minecraft.control anytime.

You don't have to take care of adding dependencies to the .service file, it is automatically added by the Sockets= option, the BindsTo= option will take care of stopping the socket and cleaning up the FIFO file when the service stops.


Here are some clarifications from suggestions of the original author.

Why do we have to use KillSignal=SIGCONT?

This prevent sending SIGTERM to the server process and cause a premature stopping of the process. It will still send SIGKILL after a certain time unless you add some more parameters (man systemd.kill).

Sockets=xxx contains the name of the Socket you created above, correct?

Yes

The socket-file (in this case test.socket?) has to be placed in the same directory as the service?

Yes, usually /etc/systemd/system/ if added by the sysadmin.

Add a new minecraft.socket file (assuming your service is named minecraft.service) to bind your server's input to:

[Unit]
BindsTo=minecraft.service
    
[Socket]
ListenFIFO=/run/minecraft.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=user
SocketGroup=user_group

Then modify your minecraft.service file to not send SIGTERM, bind standard input to the socket by modifying ExecStart with an exec wrapper. Then ExecStop will simply write to the new socket to send "/stop\n" to the input.

[Service]
...
KillSignal=SIGCONT
Sockets=test.socket
ExecStart=/bin/sh -c "exec /usr/local/bin/services/minecraft/run.sh </run/test.control"
ExecStop=/bin/sh -c "echo /stop >/run/test.control"

Bonus, you'll be able to send command to the server using echo "/command" > /run/minecraft.control anytime.

You don't have to take care of adding dependencies to the .service file, it is automatically added by the Sockets= option, the BindsTo= option will take care of stopping the socket and cleaning up the FIFO file when the service stops.

Add a new minecraft.socket file (assuming your service is named minecraft.service) to bind your server's input to:

[Unit]
BindsTo=minecraft.service
    
[Socket]
ListenFIFO=/run/minecraft.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=user
SocketGroup=user_group

Then modify your minecraft.service file to not send SIGTERM, bind standard input to the socket by modifying ExecStart with an exec wrapper. Then ExecStop will simply write to the new socket to send "/stop\n" to the input.

[Service]
...
KillSignal=SIGCONT
Sockets=test.socket
ExecStart=/bin/sh -c "exec /usr/local/bin/services/minecraft/run.sh </run/test.control"
ExecStop=/bin/sh -c "echo /stop >/run/test.control"

Bonus, you'll be able to send command to the server using echo "/command" > /run/minecraft.control anytime.

You don't have to take care of adding dependencies to the .service file, it is automatically added by the Sockets= option, the BindsTo= option will take care of stopping the socket and cleaning up the FIFO file when the service stops.


Here are some clarifications from suggestions of the original author.

Why do we have to use KillSignal=SIGCONT?

This prevent sending SIGTERM to the server process and cause a premature stopping of the process. It will still send SIGKILL after a certain time unless you add some more parameters (man systemd.kill).

Sockets=xxx contains the name of the Socket you created above, correct?

Yes

The socket-file (in this case test.socket?) has to be placed in the same directory as the service?

Yes, usually /etc/systemd/system/ if added by the sysadmin.

Source Link
Tiky
  • 146
  • 3

Add a new minecraft.socket file (assuming your service is named minecraft.service) to bind your server's input to:

[Unit]
BindsTo=minecraft.service
    
[Socket]
ListenFIFO=/run/minecraft.control
FileDescriptorName=control
RemoveOnStop=true
SocketMode=0660
SocketUser=user
SocketGroup=user_group

Then modify your minecraft.service file to not send SIGTERM, bind standard input to the socket by modifying ExecStart with an exec wrapper. Then ExecStop will simply write to the new socket to send "/stop\n" to the input.

[Service]
...
KillSignal=SIGCONT
Sockets=test.socket
ExecStart=/bin/sh -c "exec /usr/local/bin/services/minecraft/run.sh </run/test.control"
ExecStop=/bin/sh -c "echo /stop >/run/test.control"

Bonus, you'll be able to send command to the server using echo "/command" > /run/minecraft.control anytime.

You don't have to take care of adding dependencies to the .service file, it is automatically added by the Sockets= option, the BindsTo= option will take care of stopping the socket and cleaning up the FIFO file when the service stops.