这是我第一次将 bash 脚本制作成服务,并且遇到服务失败的错误,因为它无法打开用于 java 参数的文本文件 (user_jvm_args.txt)。我认为存在某种权限问题,但我不知所措。当我努力变得更好和学习时,任何事情都有帮助。谢谢!
这是服务文件:
[Service]
ExecStart=/home/ethan/ATM9-Server/run.sh
这是 run.sh bash 脚本:
#!/usr/bin/env sh
java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.20.1-47.1.3/unix_args.txt "$@"
以下是与 run.sh 脚本位于同一文件夹中的 user_jvm_args.txt 文件:
# Xmx and Xms set the maximum and minimum RAM usage, respectively.
# They can take any number, followed by an M or a G.
# M means Megabyte, G means Gigabyte.
# For example, to set the maximum to 3GB: -Xmx3G
# To set the minimum to 2.5GB: -Xms2500M
# A good default for a modded server is 4GB.
-Xms1G
-Xmx10G
-XX:+UseG1GC
-XX:+ParallelRefProcEnabled
-XX:MaxGCPauseMillis=200
-XX:+UnlockExperimentalVMOptions
-XX:+DisableExplicitGC
-XX:+AlwaysPreTouch
-XX:G1NewSizePercent=30
-XX:G1MaxNewSizePercent=40
-XX:G1HeapRegionSize=8M
-XX:G1ReservePercent=20
-XX:G1HeapWastePercent=5
-XX:G1MixedGCCountTarget=4
-XX:InitiatingHeapOccupancyPercent=15
-XX:G1MixedGCLiveThresholdPercent=90
-XX:G1RSetUpdatingPauseTimePercent=5
-XX:SurvivorRatio=32
-XX:+PerfDisableSharedMem
-XX:MaxTenuringThreshold=1
其中大部分都是默认值,我唯一更改的是 -Xms 和 -Xmx。
这是日志中显示的发生的错误:
Nov 03 15:44:43 ATM9-Server-Temp systemd[1]: Started run.service.
Nov 03 15:44:43 ATM9-Server-Temp run.sh[12480]: Error: could not open `user_jvm_args.txt'
Nov 03 15:44:43 ATM9-Server-Temp systemd[1]: run.service: Main process exited, code=exited, status=1/FAILURE
Nov 03 15:44:43 ATM9-Server-Temp systemd[1]: run.service: Failed with result 'exit-code'.
答案1
事实证明,通过添加用户、组和工作目录,我可以毫无问题地启动它!