To create a service using systemd
:
Create a file in /etc/systemd/system/
called minecraft-server.service
with the following content:
[Unit]
Description=Minecraft server
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=minecraft
Group=appmgr
ExecStart=java -Xmx4G -Xms4G -jar server.jar
[Install]
WantedBy=multi-user.target
Replace server.jar
with full path.
Now lets create the new group and user.
To create new group run the following command:
sudo groupadd appmgr
Now lets create the new user and it it to a group.
sudo useradd –G appmgr minecraft
Now your service is created, we need to enable it and run it for first time.
systemctl enable minecraft-server
systemctl start minecraft-server
Last step to write php script to restart the services:
<?php
exec("systemctl restart minecraft-server");
?>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…