Systemd 无法执行启动命令,并出现错误:没有这样的文件或目录,但路径正确并且权限也正确

Systemd 无法执行启动命令,并出现错误:没有这样的文件或目录,但路径正确并且权限也正确

所以我有这个修改过的《我的世界》服务器,它有一个非常简单的启动脚本,我想使用 systemd 来控制服务器。这是启动脚本:

#!/bin/sh

# Server Launch Script
#
# Thrown together by Neeve in under five minutes, Public Domain
# https://github.com/Neeve01
#
# Fixed and added java version check by t0suj4, Public Domain
# https://github.com/t0suj4

# DO NOT EDIT UNLESS YOU KNOW WHAT YOU'RE DOING
FORGEJAR='forge-1.12.2-14.23.5.2860.jar'
JAVA_PARAMETERS=''

# these you can edit
MIN_RAM='2048M'
MAX_RAM='12000M'

# DO NOT EDIT ANYTHING PAST THIS LINE
LAUNCHPARAMS="-server -Xms$MIN_RAM -Xmx$MAX_RAM $JAVA_PARAMETERS -Dlog4j.configurationFile=log4j2_112-116.xml -jar $FORGEJAR nogui"

echo "Checking java version..."
echo
java -version
echo
echo "The expected java version is 1.8. Not higher, not lower."
echo

echo "Launching the server..."
echo
echo "> java $LAUNCHPARAMS"

java $LAUNCHPARAMS

echo
echo "- The server has stopped. If it's a crash, please read the output above."
echo
read -p "- Press Return to exit..." _

这是一个ls-la工作环目录:

drwxrwxrwx 15 nomifactory nomifactory     4096 Dec 24 13:14 .
drwxrwxr-x  7 mux         mux             4096 Dec 24 01:18 ..
-rwxrwxrwx  1 nomifactory nomifactory        2 Dec 24 01:25 banned-ips.json
-rwxrwxrwx  1 nomifactory nomifactory        2 Dec 24 01:25 banned-players.json
drwxrwxrwx  3 nomifactory nomifactory     4096 Nov  9 22:43 bansoukou
-rwxrwxrwx  1 nomifactory nomifactory     1053 Nov  9 22:43 CHANGELOG.md
drwxrwxrwx 32 nomifactory nomifactory     4096 Dec 24 01:19 config
drwxrwxrwx  4 nomifactory nomifactory     4096 Nov  9 22:43 config-overrides
-rwxrwxrwx  1 nomifactory nomifactory     9375 Dec 24 12:38 crafttweaker.log
-rwxrwxrwx  1 nomifactory nomifactory      180 Dec 24 01:20 eula.txt
-rwxrwxrwx  1 nomifactory nomifactory  4466148 Nov  9 22:42 forge-1.12.2-14.23.5.2860.jar
drwxrwxrwx  3 nomifactory nomifactory     4096 Dec 24 01:25 journeymap
-rwxrwxrwx  1 nomifactory nomifactory      916 Nov  9 22:43 launch.bat
-rwxrwxrwx  1 nomifactory nomifactory      897 Dec 24 01:30 launch.sh
drwxrwxrwx  7 nomifactory nomifactory     4096 Nov  9 22:42 libraries
-rwxrwxrwx  1 nomifactory nomifactory     7817 Nov  9 22:43 LICENSE.md
drwxrwxrwx  4 nomifactory nomifactory     4096 Dec 24 01:20 local
-rwxrwxrwx  1 nomifactory nomifactory     1159 Nov  9 22:43 log4j2_112-116.xml
drwxrwxrwx  2 nomifactory nomifactory     4096 Dec 24 02:38 logs
-rwxrwxrwx  1 nomifactory nomifactory 30222121 Feb 11  2022 minecraft_server.1.12.2.jar
drwxrwxrwx  3 nomifactory nomifactory     4096 Dec 24 01:19 .mixin.out
drwxrwxrwx  4 nomifactory nomifactory    12288 Dec 24 01:19 mods
-rwxrwxrwx  1 nomifactory nomifactory        2 Dec 24 01:25 ops.json
-rwxrwxrwx  1 nomifactory nomifactory       15 Dec 24 01:20 options.txt
drwxrwxrwx  2 nomifactory nomifactory     4096 Dec 24 01:20 patchouli_books
-rwxrwxrwx  1 nomifactory nomifactory      702 Nov  9 22:42 README.md
drwxrwxrwx  3 nomifactory nomifactory     4096 Nov  9 22:43 scripts
-rwxrwxrwx  1 nomifactory nomifactory      752 Dec 24 01:25 server.properties
drwxrwxrwx  2 nomifactory nomifactory     4096 Dec 24 01:21 TombManyGraves
-rwxrwxrwx  1 nomifactory nomifactory        2 Dec 24 01:25 usercache.json
-rwxrwxrwx  1 nomifactory nomifactory        2 Dec 24 01:25 whitelist.json
drwxrwxrwx 13 nomifactory nomifactory     4096 Dec 24 01:27 world

我为其编写了以下单元文件:

[Unit]
Description=Nomifactory Server
After=network.target
[Service]
Type=simple
User=nomifactory
Group=nomifactory
Nice=1
KillSignal=SIGTERM
WorkingDirectory=/home/mux/mcs/nomifactory
ExecStart="/usr/bin/java -server -Xms2048M -Xmx12000M -Dlog4j.configurationFile=log4j2_112-116.xml -jar forge-1.12.2-14.23.5.2860.jar nogui"
#ExecStart=/usr/local/bin/nomifactory
[Install]
WantedBy=multi-user.target

当我尝试启动服务时,它失败并出现此错误(摘自journalctl):

Dec 24 12:56:02 johann-serve systemd[1]: Started Nomifactory Server.
-- Subject: A start job for unit nomifactory.service has finished successfully
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit nomifactory.service has finished successfully.
--
-- The job identifier is 232408.
Dec 24 12:56:02 johann-serve systemd[2579244]: nomifactory.service: Failed to execute command: No such file or directory
Dec 24 12:56:02 johann-serve systemd[2579244]: nomifactory.service: Failed at step EXEC spawning /usr/bin/java -server -Xms2048M -Xmx12000M -Dlog4j.configurationFile=log4j2_112-116.xml -jar forge-1.12.2-14.23.5.2860.jar nogui: No such file or directory
-- Subject: Process /usr/bin/java -server -Xms2048M -Xmx12000M -Dlog4j.configurationFile=log4j2_112-116.xml -jar forge-1.12.2-14.23.5.2860.jar nogui could not be executed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The process /usr/bin/java -server -Xms2048M -Xmx12000M -Dlog4j.configurationFile=log4j2_112-116.xml -jar forge-1.12.2-14.23.5.2860.jar nogui could not be executed and failed.
--
-- The error number returned by this process is ERRNO.
Dec 24 12:56:02 johann-serve systemd[1]: nomifactory.service: Main process exited, code=exited, status=203/EXEC
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit nomifactory.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 203.
Dec 24 12:56:02 johann-serve systemd[1]: nomifactory.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit nomifactory.service has entered the 'failed' state with result 'exit-code'.

一些常见问题解答来总结一下:

  • 我尝试过了进入nomifactory用户执行指定的命令执行启动在指定的同一目录中工作目录并正常启动。仅当使用 systemd 启动时才会出现该错误。
  • 所有必需的文件和目录(除了 java 可执行文件)都位于工作目录内。
  • 工作目录的所有者和组是指定工厂(无论如何,他们现在有 777 许可 xd)。
  • 路径中的所有目录都是可读且可执行的指定工厂

我希望有人能帮助我完成这个看似微不足道的任务,我可能是个白痴,但我就是看不到。

答案1

@ilkkachu 的评论为我解决了这个问题,如果有人有类似的问题,请检查ExecStart指令中的双引号!

相关内容