| [Unit] |
| Description=Minecraft server %I |
| After=network.target |
| |
| [Service] |
| Type=forking |
| |
| ProtectSystem=yes |
| ProtectControlGroups=yes |
| |
| ; Those environment are useless due to limitations of systemd |
| ;Environment=MINECRAFT_HOME=%h |
| ;MINECRAFT_START_COMMAND="exec sh run.sh" |
| ;EnvironmentFile=/etc/default/minecraft |
| |
| ; Hardcoded user name because systemd doesn't support using variables here |
| User=minecraft |
| |
| ; Cannot use 'WorkingDirectory=' due to '%h' will be expanded to empty string |
| ;WorkingDirectory=%h/%I |
| ;ExecStart=/usr/bin/tmux -L minecraft-%i new-session -d "exec sh run.sh" |
| |
| ; chdir(2) inside sh(1) instead |
| ExecStart=/usr/bin/tmux -L minecraft-%i new-session -d "cd ~/%i/ && exec sh run.sh" |
| |
| ExecStop=/usr/bin/tmux -L minecraft-%i send-keys -t 0 C-u stop ENTER |
| ExecReload=/usr/bin/tmux -L minecraft-%i send-keys -t 0 C-u reload ENTER |
| |
| ; SIGTERM will be sent immediately after 'ExecStop' command, change it to a harmless one |
| KillSignal=SIGCONT |
| |
| ; '%h' will be expanded to empty string |
| ; However I'm no longer consider this is main process anyway |
| ;PIDFile=%h/%I/server.pid |
| |
| ; Send SIGKILL only to tmux(1) after 'TimeoutStopSec' so the server software got more chance to stop gracefully |
| GuessMainPID=yes |
| KillMode=process |
| TimeoutStopSec=30s |
| |
| [Install] |
| WantedBy=multi-user.target |