简体   繁体   English

start.sh in.bash 同一个服务或者启动服务内的.sh文件

[英]start .sh in .bash with a service or start the .sh file within the service

im currently setting up a minecraft server on my root but struggle with the startup on boot.我目前正在我的 root 上设置一个 minecraft 服务器,但在启动时遇到困难。

Before having this in startup i was starting the server with a.sh file which i had to start manually.在启动之前,我使用必须手动启动的 a.sh 文件启动服务器。 the.sh file also created a screen where i was able to check the console the.sh 文件还创建了一个屏幕,我可以在其中检查控制台

.sh file: .sh 文件:

screen -AmdS minecraft java -Xms4096M -Xmx4096M -jar /home/minecraft/server/server.jar nogui

But then i tried to have the server in startup of the root server so it starts automaticly但后来我试图让服务器启动根服务器,以便它自动启动

i created a service with a.bash file which starts the server with no problem on startup but without the screen option for the console我用 a.bash 文件创建了一个服务,该文件启动服务器时没有问题,但没有控制台的屏幕选项

Service:服务:

[Unit]
Description=Start Minecraft
After=network.target

[Service]
Type=simple
ExecStart=/root/start_minecraft_server.bash
TimeoutStartSec=0

[Install]
WantedBy=default.target

Bash: Bash:

#!/bin/bash

#Standard Minecraft
cd /home/minecraft/server/
exec java -Xmx4096M -Xms1024M -jar server.jar nogui

now i want to ask if you know any easy option for adding the screen option to the service or bash file?现在我想问你是否知道将屏幕选项添加到服务或 bash 文件的任何简单选项?

Try this and make sure your screen is actually in /usr/bin/ by which screen试试这个并确保你的screen实际上在/usr/bin/which screen

[Unit]
Description=Start Minecraft
After=network.target

    [Service]
    user=minecraft
    Type=simple
    ExecStart=/usr/bin/screen -S Minecraft_Server -d -m sh /root/start_minecraft_server.bash
    TimeoutStartSec=0
    
[Install]
WantedBy=default.target

But you should also alter your startcript itself:但是你也应该改变你的 startcript 本身:

#!/bin/bash

#Standard Minecraft
cd /home/minecraft/server/
while true; do
exec java -Xmx4096M -Xms1024M -jar server.jar nogui
done;

And just for security reasons, you should never run your mc server as root - create another user for it with limited permissions and add something like user=minecraft below the SERVICE tag in the init startscript出于安全原因,你永远不应该以 root 身份运行你的 mc 服务器——为它创建另一个具有有限权限的用户,并在 init startscript 的 SERVICE 标签下添加类似user=minecraft的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM