我已经设置了运行 ubuntu 20.04 服务器的树莓派,因此它可以使用 box86 运行 teampeak。
为此,我ls /srv/chroot/focal-armhf/
使用 debootstrap 设置了一个 chroot。在那个目录中,我编译了 box86。然后我下载并安装了 ts3server for x86 on linux。我已经为 schroot 设置了自定义配置。
/etc/schroot/chroot.d/focal-armhf.conf
:
[focal-armhf]
description=Ubuntu focal armhf chroot
type=directory
directory=/srv/chroot/focal-armhf
profile=ts3server
personality=linux
# preserve-environment=true
root-users=ubuntu
users=ubuntu
当我在主机上的 bash 中运行以下命令时,一切正常。
# beginn session, name it ts3server
sudo /usr/bin/schroot -n ts3server -b -c chroot:focal-armhf
# run start script. it's the same as the default start script, however I added /usr/local/bin/box86 in front of the starting of the actual server binary.
sudo /usr/bin/schroot --run-session --chroot ts3server -d /opt/ts3server/teamspeak3-server_linux_x86/ './ts3custom.sh' start
# at this point the server is running and i can connect to it.
# ...
# when I want to shut down:
# stopping server
/usr/bin/schroot --run-session --chroot ts3server -d /opt/ts3server/teamspeak3-server_linux_x86/ './ts3custom.sh' stop
# ending schroot session
/usr/bin/schroot -e --chroot ts3server
我现在想用 systemd 自动执行此操作。所以我创建了这个单元配置
[Unit]
Description=Teamspeak3 Server in chroot
After=network.target
After=syslog.target
[Service]
ExecStartPre=/usr/bin/schroot -n ts3server -b -c chroot:focal-armhf
ExecStart=/usr/bin/schroot --run-session --chroot ts3server -d /opt/ts3server/teamspeak3-server_linux_x86/ './ts3custom.sh' start
ExecStop=/usr/bin/schroot --run-session --chroot ts3server -d /opt/ts3server/teamspeak3-server_linux_x86/ './ts3custom.sh' stop
ExecStopPost=/usr/bin/schroot -e --chroot ts3server
Restart=no
Type=simple
[Install]
WantedBy=multi-user.target
当我运行它时,它会立即关闭。teampeak 服务器日志运行是
2021-05-06 17:58:49.429511|INFO |ServerLibPriv | |TeamSpeak 3 Server 3.13.3 (2020-12-16 14:17:05)
2021-05-06 17:58:49.456286|INFO |ServerLibPriv | |SystemInformation: Linux 5.4.0-1034-raspi #37-Ubuntu SMP PREEMPT Mon Apr 12 23:14:49 UTC 2021 i686 Binary: 32bit
2021-05-06 17:58:49.456975|WARNING |ServerLibPriv | |The system locale is set to "C" this can cause unexpected behavior. We advice you to repair your locale!
2021-05-06 17:58:49.508403|INFO |DatabaseQuery | |dbPlugin name: SQLite3 plugin, Version 3, (c)TeamSpeak Systems GmbH
2021-05-06 17:58:49.509804|INFO |DatabaseQuery | |dbPlugin version: 3.11.1
2021-05-06 17:58:49.553828|INFO |DatabaseQuery | |checking database integrity (may take a while)
如果我总是设置重启,它会一遍又一遍地生成相同的日志。
似乎服务器已启动,然后分叉到后台,然后由 systemd 调用 ExecStop。
我试过设置Type=forking
andType=exec
和Type=simple
,结果都一样。
基本上一切正常,直到我尝试使用 systemd 来管理它。
我怎样才能让它工作?
我特别想要:
- 随系统自动启动
- 管理它
service ts3server start|stop|restart
为了完整起见,我的自定义脚本来管理 teampeak 服务器:
#!/bin/sh
# Copyright (c) 2019 TeamSpeak Systems GmbH
# All rights reserved
BINARYNAME="./ts3server"
COMMANDLINE_PARAMETERS="" #add any command line parameters you want to pass here
PID_FILE=ts3server.pid
do_start() {
if [ -e $PID_FILE ]; then
PID=$(cat "$PID_FILE")
if (ps -p "$PID" >/dev/null 2>&1); then
echo "The server is already running, try restart or stop"
return 1
else
echo "$PID_FILE found, but no server running. Possibly your previously started server crashed"
echo "Please view the logfile for details."
rm $PID_FILE
fi
fi
if [ $(id -u) -eq 0 ]; then
echo "WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT"
c=1
while [ "$c" -le 10 ]; do
echo -n "!"
sleep 1
c=$(($c + 1))
done
echo "!"
fi
echo "Starting the TeamSpeak 3 server"
if [ ! -e "$BINARYNAME" ]; then
echo "Could not find binary, aborting"
return 5
fi
if [ ! -x "$BINARYNAME" ]; then
echo "${BINARYNAME} is not executable, trying to set it"
chmod u+x "${BINARYNAME}"
fi
if [ ! -x "$BINARYNAME" ]; then
echo "${BINARNAME} is not exectuable, cannot start TeamSpeak 3 server"
return 3
fi
/usr/local/bin/box86 "./${BINARYNAME}" "${@}" "daemon=1" "pid_file=$PID_FILE"
if [ $? -eq 0 ]; then
echo "TeamSpeak 3 server started, for details please view the log file"
else
echo "TeamSpeak 3 server could not start"
return 4
fi
}
do_stop() {
if [ ! -e $PID_FILE ]; then
echo "No server running ($PID_FILE is missing)"
return 0
fi
PID=$(cat "$PID_FILE")
if (! ps -p "$PID" >/dev/null 2>&1); then
echo "No server running"
return 0
fi
echo -n "Stopping the TeamSpeak 3 server "
kill -TERM "$PID" || exit $?
rm -f $PID_FILE
c=300
while [ "$c" -gt 0 ]; do
if (kill -0 "$PID" 2>/dev/null); then
echo -n "."
sleep 1
else
break
fi
c=$(($c - 1))
done
echo
if [ $c -eq 0 ]; then
echo "Server is not shutting down cleanly - killing"
kill -KILL "$PID"
return $?
else
echo "done"
fi
return 0
}
do_status() {
if [ ! -e $PID_FILE ]; then
echo "No server running ($PID_FILE is missing)"
return 1
fi
PID=$(cat "$PID_FILE")
if (! ps -p "$PID" >/dev/null 2>&1); then
echo "Server seems to have died"
return 1
fi
echo "Server is running"
return 0
}
# change directory to the scripts location
cd $(dirname $([ -x "$(command -v realpath)" ] && realpath "$0" || readlink -f "$0"))
case "$1" in
start)
shift
do_start "$@" "$COMMANDLINE_PARAMETERS"
exit $?
;;
stop)
do_stop
exit $?
;;
restart)
shift
do_stop && (do_start "$@" "$COMMANDLINE_PARAMETERS")
exit $?
;;
status)
do_status
exit $?
;;
*)
echo "Usage: ${0} {start|stop|restart|status}"
exit 2
;;
esac
我在 tmux 上遇到过类似的问题,并像这样解决了它:
自其父(服务)停止以来,服务似乎已结束。RemainAfterExit 和 KillMode 帮助...