Artemis 版本:2.19.1
JDK 1.8.0.271
尝试过使用不同权限用户,都无法使用 systemctl start 启动
使用 broker 中的 artemis-service start ,能够正常启动
service 文件如下
[Unit]
Description=Apache ActiveMQ Artemis
After=network.target
[Service]
Type=forking
User=activemq
Group=activemq
ExecStart=/var/lib/jms-broker/bin/artemis-service start
ExecStop=/var/lib/jms-broker/bin/artemis-service stop
[Install]
WantedBy=multi-user.target
journalctl -xe
中的 artemis-service 返回的信息很有限,除了 starting ,就只有Could not start ${service}
顺便贴一下 artemis-serive 启动脚本的内容,这个脚本是 artemis 自动生成的
service=`basename "$0"`
#
# Discover the ARTEMIS_INSTANCE from the location of this script.
#
if [ -z "$ARTEMIS_INSTANCE" ] ; then
## resolve links - $0 may be a link to ActiveMQ's home
PRG="$0"
saveddir=`pwd`
# need this for relative symlinks
dirname_prg=`dirname "$PRG"`
cd "$dirname_prg"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
ARTEMIS_INSTANCE=`dirname "$PRG"`
cd "$saveddir"
# make it fully qualified
ARTEMIS_INSTANCE=`cd "$ARTEMIS_INSTANCE/.." && pwd`
export ARTEMIS_INSTANCE
fi
PID_FILE="${ARTEMIS_INSTANCE}/data/artemis.pid"
if [ ! -d "${ARTEMIS_INSTANCE}/data/" ]; then
mkdir "${ARTEMIS_INSTANCE}/data/"
fi
status() {
if [ -f "${PID_FILE}" ] ; then
pid=`cat "${PID_FILE}"`
# check to see if it's gone...
ps -p ${pid} > /dev/null
if [ $? -eq 0 ] ; then
return 0
else
rm "${PID_FILE}"
return 3
fi
fi
return 3
}
stop() {
if [ -f "${PID_FILE}" ] ; then
pid=`cat "${PID_FILE}"`
kill $@ ${pid} > /dev/null
fi
for i in 1 2 3 4 5 ; do
status
if [ $? -ne 0 ] ; then
return 0
fi
sleep 1
done
echo "Could not stop process ${pid}"
return 1
}
start() {
status
if [ $? -eq 0 ] ; then
echo "Already running."
return 1
fi
if [ -z "$ARTEMIS_USER" -o `id -un` = "$ARTEMIS_USER" ] ; then
nohup "${ARTEMIS_INSTANCE}/bin/artemis" run > /dev/null 2> /dev/null &
else
sudo -n -u ${ARTEMIS_USER} nohup "${ARTEMIS_INSTANCE}/bin/artemis" run > /dev/null 2> /dev/null &
fi
echo $! > "${PID_FILE}"
# check to see if stays up...
sleep 1
status
if [ $? -ne 0 ] ; then
echo "Could not start ${service}"
return 1
fi
echo "${service} is now running (${pid})"
return 0
}
case $1 in
start)
echo "Starting ${service}"
start
exit $?
;;
force-stop)
echo "Forcibly Stopping ${service}"
stop -9
exit $?
;;
stop)
echo "Gracefully Stopping ${service}"
stop
exit $?
;;
restart)
echo "Restarting ${service}"
stop
start
exit $?
;;
status)
status
rc=$?
if [ $rc -eq 0 ] ; then
echo "${service} is running (${pid})"
else
echo "${service} is stopped"
fi
exit $rc
;;
*)
echo "Usage: $0 {start|stop|restart|force-stop|status}" >&2
exit 2
;;
esac
1
Kobayashi 2022-04-15 09:31:29 +08:00 via Android
不要使用启动脚本,systemd 直接管理 daemon. 把 start 脚本里除去 nohup 的部分提取出来。
|
2
oneisall8955 2022-04-15 09:57:22 +08:00 via Android
核心代码:
把 systemd 的 User 修改成和脚本的${ARTEMIS_USER}一致,然后 systemd 的 ExecStart 启动命令修改为 ${ARTEMIS_INSTANCE}/bin/artemis" run > /dev/null 2> /dev/null 一致 |
3
julyclyde 2022-04-15 10:52:35 +08:00
@oneisall8955 不要重定向 stdout 和 stderr 。systemd 会收集的
|
4
julyclyde 2022-04-15 10:53:30 +08:00
一般使用 init 脚本的服务,启动后进程都会转后台,所以这时候不应该用 forking 类型
建议 simple 类型+PIDFile 或者进行彻底的 systemd 化改造 |
5
oneisall8955 2022-04-15 11:14:16 +08:00
@julyclyde #3 谢谢大佬指教~
|
6
oneisall8955 2022-04-15 11:14:31 +08:00
|
7
pocketz OP @Kobayashi
@oneisall8955 @julyclyde 现在去掉了 forking ,加了 PIDFile=/var/lib/jms-broker/data/artemis.pid 改成 ExecStart=/var/lib/jms-broker/bin/artemis-service start 结果是返回了正常启动的信息,又马上自动关闭了 放弃了,直接 /var/lib/jms-broker/bin/artemis-service start 启动了。只是没实现开机启动,倒不影响使用 |
8
pocketz OP |
9
oneisall8955 2022-04-15 11:30:42 +08:00
@pocketz #8 撒花~
|
10
pocketz OP @oneisall8955
@julyclyde 看来我的记忆没出错,只绿了一小段时间,还是红了 提示 ``` artemis.service holdoff time over, scheduling restarting. start request repeated too quickly for artemis.service failed to start ``` |
11
pocketz OP 脚本本身的提示是,启动之后又调用了 stop 命令
|
12
pocketz OP @julyclyde
对了,请问 journalctl -xe 中提示的 Unregisted Authentication Agent for unix-process:5032:5410854 和启动失败有关系吗 |
14
julyclyde 2022-04-15 14:09:01 +08:00
@pocketz Unregisted Authentication Agent for unix-process 是 polkit 的日志。具体情况不了解
|
15
julyclyde 2022-04-15 14:14:03 +08:00 1
@oneisall8955
把 systemd 的 User 修改成和脚本的${ARTEMIS_USER}一致,在一些情况下会失败(不过你这个案例大概不会失败) systemd 的 User 是先降级用户权限,后执行 ExecStart init 脚本是刚开始 root 权限,由服务进程初始化之后自己去降级(脚本里 sudo 命令) 我建议你把脚本里面重定向去掉,用 systemd 运行看看日志 |
16
oneisall8955 2022-04-15 15:11:56 +08:00 1
服务器下了个 ActiveMQ Artemis ,运行起来了。没问题呀
服务器 debian9 ,java8 ,artemis 2.19.1 1 创建了 broker /opt/software/apache-artemis/bin/artemis create /opt/artemis_brokers/foo 2 测试直接运行能否正常启动 /opt/artemis_brokers/foo/bin/artemis run 3 编写 artemis.service ``` [Unit] Description=Artemis Server Service After=network.target [Service] Type=simple Restart=on-failure RestartSec=5s ExecStart=/opt/artemis_brokers/foo/bin/artemis run [Install] WantedBy=multi-user.target ``` 4 复制到 systemd 文件夹及更新 cp artemis.service /etc/systemd/system systemctl daemon-reload 5 启动及自启等 systemctl enable artemis.service systemctl start artemis.service |
17
pocketz OP |
18
oneisall8955 2022-04-15 15:56:57 +08:00
@pocketz #17 还需要环境变量,不然找不到 java 命令
- 创建 systemd service 配置文件夹 mkdir /etc/systemd/system/artemis.service.d - 创建环境变量文件 vim environment.conf ``` [Service] Environment=JAVA_HOME=/opt/software/jdk1.8.0_181 ``` - reload 配置 systemctl daemon-reload |
19
pocketz OP |
20
tramm 2022-04-15 21:08:32 +08:00
我记得这个都停止维护了吧? 还用这个的嘛
|