{"id":1603,"date":"2019-01-06T10:43:19","date_gmt":"2019-01-06T10:43:19","guid":{"rendered":"https:\/\/scunster.co.uk\/?p=1603"},"modified":"2019-01-06T10:45:36","modified_gmt":"2019-01-06T10:45:36","slug":"create-system-service-for-starting-stopping-a-linux-minecraft-server","status":"publish","type":"post","link":"https:\/\/scunster.co.uk\/?p=1603","title":{"rendered":"Create system service for starting &#038; stopping a linux minecraft server"},"content":{"rendered":"<p>Tested in Debian 9 and CentOS7<\/p>\n<p>It is assumed that you already have a user named minecraft and have the minecraft server setup and working in the users home directory.<\/p>\n<p>We need to create a service file for game service that we would like to control<br \/>\nOnce done you can control the service easily from the terminal, you can also set it up to allow specific users to control the services without any su or root intervention.<\/p>\n<p>Log in as root or issue the commands as su<\/p>\n<p>first lets create the minecraft services file.<\/p>\n<pre>vi \/etc\/systemd\/system\/minecraft.service<\/pre>\n<pre>[Unit]\r\nDescription=Minecraft Java Server\r\nDocumentation=\r\n\r\nWants=network.target\r\nAfter=network.target\r\n\r\n[Service]\r\nUser=minecraft\r\nNice=5\r\nKillMode=control-group\r\nSuccessExitStatus=0 1\r\n\r\nRestart=always\r\nRestartSec=10\r\nNoNewPrivileges=true\r\nPrivateTmp=true\r\nInaccessibleDirectories=\/root \/sys \/srv -\/opt \/media -\/lost+found\r\n\r\nWorkingDirectory=\/home\/minecraft\/minecraftserver\/\r\nExecStart=\/usr\/bin\/java -Xms2G -Xmx6G -jar minecraftserver.jar --noconsole nogui\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p>The only things you really need to change are the <strong>description<\/strong><br \/>\nThe <strong>user<\/strong> who will be running the server, in this case the user is &#8220;minecraft&#8221;<br \/>\nThe <strong>working directory<\/strong> for the minecraft jar file<br \/>\nThe <strong>java arguments<\/strong> that you use to start your minecraft server, this must also include the full <strong>path to your systems java<\/strong><\/p>\n<p>Save and exit vi :wq<\/p>\n<p>Now we need to reload the system services so that your service is registered.<\/p>\n<pre>systemctl daemon-reload<\/pre>\n<p>You can now control your minecraft server with the following commands<\/p>\n<pre>systemctl start minecraft<\/pre>\n<pre>systemctl stop minecraft<\/pre>\n<pre>systemctl restart minecraft<\/pre>\n<p>If you need to access your server to issue op commands from the terminal then don&#8217;t forget to stop the service, and load the server manually as you can&#8217;t interact with it from the terminal once the services is running.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tested in Debian 9 and CentOS7 It is assumed that you already have a user named minecraft and have the minecraft server setup and working in the users home directory. We need to create a service file for game service that we would like to control Once done you can control the service easily from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[38,415,402,447,446],"class_list":["post-1603","post","type-post","status-publish","format-standard","hentry","category-linux","tag-game","tag-minecraft","tag-server","tag-services","tag-systemctl"],"_links":{"self":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1603"}],"version-history":[{"count":3,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1603\/revisions"}],"predecessor-version":[{"id":1606,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1603\/revisions\/1606"}],"wp:attachment":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}