[解决了]
我的问题很简单
我创建了一个 mcboot.service 来自动启动我的所有 Mod 8 MC 服务器,我 sysctl 启用了它,并做了 daemon-reload,我现在的问题是,我可以使用名为“agent”的用户手动执行 run.sh,但在自动启动时我在 sysctl 状态上得到了这个:
agent@ubntsrv1: /var/ATM8$ systemctl daemon-reload
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon === Authentication is required to reload the systemd state.
Authenticating as: user (agent)
Password:
==== AUTHENTICATION COMPLETE ===
agent@ubntsrv1: /var/ATM8$ systemctl status mcboot.service
mcboot.service Minecraft boot script
Loaded: loaded (/etc/systemd/system/mcboot.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2023-02-02 11:14:20 UTC; 52min ago
Main PID: 718 (code=exited, status=0/SUCCESS)
CPU: 350ms
Feb 02 11:14:18 ubntsrv1 systemd[1]: Started Minecraft boot script.
Feb 02 11:14:18 ubntsrv1 run.sh [718]: /var/ATM8
Feb 02 11:14:19 ubntsrv1 run.sh [723]: Error: Could not find or load main class .var.ATM8.user_jvm_args.txt Feb 02 11:14:19 ubntsrv1 run.sh [723]: Caused by: java.lang.ClassNotFoundException: /var/ATM8/user_jvm_args/txt Feb 02 11:14:20 ubntsrv1 run.sh [718]: /var/ATM8
Feb 02 11:14:20 ubntsrv1 systemd[1]: mcboot.service: Deactivated successfully.
agent@ubntsry1:/var/ATM8$
这是我的 run.sh 的内容:
#!/bin/env sh
# Forge requires a configured set of both JVM and program arguments.
# Add custom JVM arguments to the user_jvm_args.txt
# Add custom program arguments (such as noguil to this file in the next line before the "$@" or
# pass them to this script directly
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.19.2-43.2.3/unix_args.txt BASEDIR=$(dirname "$0")
echo "$BASEDIR"
这是我的 mcboot.service :
[Unit]
Description=Minecraft boot script
[Service]
ExecStart=/var/ATM8/run.sh start
[Install]
WantedBy=multi-user.target
我想做正确的事情,我不想使用 crontab。
谢谢
[编辑已解决]
当您从不同的目录手动运行脚本时,您的脚本是否有效,例如 cd /tmp; /var/ATM8/run.sh 启动吗? (我想不是。)在 java 之前尝试 cd "$BASEDIR" ...
这实际上解决了我的问题!我可以从任何地方手动运行我的脚本,但实际上添加了cd $BASEDIR使该服务成功运行,现在每次我的 R820 重新启动时它都会运行!谢谢