launch-service.sh 文件应该由 phantombot.service 文件执行。我查看了 systemctl service phantombot 中该服务是否确实启动。该服务启动后约 11 秒关闭。(见下文)
launch-service.sh
:
#!/bin/bash
#
# PhantomBot Launcher - Linux and macOS
#
# Please run the following to launch the bot, the chmod is required only once.
# % chmod +x launch-service.sh
# % ./launch-service.sh
#
unset DISPLAY
if [[ $(uname) -eq "Darwin" ]]; then
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
cd "$DIR"
else
cd $(dirname $(readlink -f $0))
fi
if type -p java 1>/dev/null 2>/dev/null; then
_java=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
_java="$JAVA_HOME/bin/java"
else
echo "You don't have Java installed! Download it from https://www.java.com/en/download/"
fi
java -Dfile.encoding=UTF-8 -jar PhantomBot.jar
/etc/systemd/system/phantombot.service
:
[Unit]
Description=PhantomBot
After=network.target remote-fs.target nss-lookup.target
[Service]
User=botuser
Group=botuser
Restart=on-failure
RestartSec=30
ExecStart=/home/botuser/phantombot/launch-service.sh
KillSignal=SIGTERM
[Install]
WantedBy=multi-user.target
这显示了我启动服务之后的 systemctl 状态:
$ systemctl status phantombot
● phantombot.service - PhantomBot
Loaded: loaded (/etc/systemd/system/phantombot.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2017-09-09 16:08:14 CEST; 21min ago
Process: 13145 ExecStart=/home/botuser/phantombot/launch-service.sh (code=exited, status=0/SUCCESS) Main PID: 13145 (code=exited, status=0/SUCCESS)
botuser@Ubuntu-1704-zesty-64-minimal:~/phantombot$ sudo /bin/systemctl start phantombot
$ systemctl status phantombot
● phantombot.service - PhantomBot
Loaded: loaded (/etc/systemd/system/phantombot.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-09-09 16:30:18 CEST; 1s ago
Main PID: 13295 (launch-service.)
Tasks: 23 (limit: 4915)
CGroup: /system.slice/phantombot.service
├─13295 /bin/bash /home/botuser/phantombot/launch-service.sh
└─13300 java -Dfile.encoding=UTF-8 -jar PhantomBot.jar
$ systemctl status phantombot
● phantombot.service - PhantomBot
Loaded: loaded (/etc/systemd/system/phantombot.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-09-09 16:30:18 CEST; 3s ago
Main PID: 13295 (launch-service.)
Tasks: 28 (limit: 4915)
CGroup: /system.slice/phantombot.service
├─13295 /bin/bash /home/botuser/phantombot/launch-service.sh
└─13300 java -Dfile.encoding=UTF-8 -jar PhantomBot.jar
$ systemctl status phantombot
● phantombot.service - PhantomBot
Loaded: loaded (/etc/systemd/system/phantombot.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-09-09 16:30:18 CEST; 5s ago
Main PID: 13295 (launch-service.)
Tasks: 28 (limit: 4915)
CGroup: /system.slice/phantombot.service
├─13295 /bin/bash /home/botuser/phantombot/launch-service.sh
└─13300 java -Dfile.encoding=UTF-8 -jar PhantomBot.jar
$ systemctl status phantombot
● phantombot.service - PhantomBot
Loaded: loaded (/etc/systemd/system/phantombot.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-09-09 16:30:18 CEST; 9s ago
Main PID: 13295 (launch-service.)
Tasks: 23 (limit: 4915)
CGroup: /system.slice/phantombot.service
├─13295 /bin/bash /home/botuser/phantombot/launch-service.sh
└─13300 java -Dfile.encoding=UTF-8 -jar PhantomBot.jar
$ systemctl status phantombot
● phantombot.service - PhantomBot
Loaded: loaded (/etc/systemd/system/phantombot.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-09-09 16:30:18 CEST; 11s ago
Main PID: 13295 (launch-service.)
Tasks: 23 (limit: 4915)
CGroup: /system.slice/phantombot.service
├─13295 /bin/bash /home/botuser/phantombot/launch-service.sh
└─13300 java -Dfile.encoding=UTF-8 -jar PhantomBot.jar
$ systemctl status phantombot
● phantombot.service - PhantomBot
Loaded: loaded (/etc/systemd/system/phantombot.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2017-09-09 16:30:31 CEST; 703ms ago
Process: 13295 ExecStart=/home/botuser/phantombot/launch-service.sh (code=exited, status=0/SUCCESS) Main PID: 13295 (code=exited, status=0/SUCCESS)
您会看到服务实际上启动了大约 11 秒才关闭。如果我/launch-service.sh
直接通过命令行执行 . 文件,它不会关闭。
我跟着本指南一步步。
感谢您提供的任何帮助。:)
有什么建议这里出了什么问题吗?
这是权限问题吗?我可以在某种详细模式下执行它来查看关闭守护进程的错误吗?
答案1
我发现了错误。这是一个权限错误。javascript 文件想要访问的一些日志文件由 root 拥有。这导致 init.js 文件抛出权限被拒绝错误,我通过命令在 journalctl 中发现了该错误sudo journalctl -u phantombot -b
。
我真的很想知道程序第一次启动时是如何没有任何错误的。
但无论如何,感谢您的帮助。