gpt4 book ai didi

java - 如何在 AIX 中将 jar 文件作为服务运行,以便在崩溃时自动重新启动?

转载 作者:行者123 更新时间:2023-12-02 03:44:40 24 4
gpt4 key购买 nike

我有几个 jar 文件,我想将它们作为服务在 AIX 上运行。如果服务崩溃/结束,则必须自动重新启动。我怎样才能实现这个目标?

我有一个像这样的 shell 脚本

(
until java -jar Test.jar; do
echo "Test Service crashed with exit code $?. Respawning... " >&2
sleep 5
done
)

这可行,但我想知道是否有更好的方法来做到这一点?如果机器由于某种原因重新启动,则必须手动运行该脚本。我不是 Linux 或 AIX 方面的专家。

最佳答案

您可以查看this page关于 AIX 中的自动启动/重新启动服务/守护进程

inittab entries

Let’s look at a entry for inittab that runs a script. Suppose, we want to run a script that sends an email to system administrators stating that the box is available when the system come up.

The entry for inittab is shown below:

mailout:2:once:/usr/local/bin/mailout > / dev/null 2>&1 #mail users

The above entry can be summarized as follows:

mailout: The unique identifier

2: Run this when the system reaches runlevel two (the default) once: Run the script and do not wait for its termination; init will carry on processing inittab. Iif the process fails, init will not attempt to rerun it. /usr/local/bin/mailout: The full path and script name of the command to run; notice that the output is thrown away to /dev/dull. We end with a ‘#’ comment on what the script does.

For completeness, here is the script in question:

!/bin/sh                                                    
#mailout
/usr/sbin/sendmail ‑t <<mayday
From: hostname
To: rs6admins
Subject: hostname P‑Series is up
The AIX hostname is now up, please check services.
.
mayday

关于java - 如何在 AIX 中将 jar 文件作为服务运行,以便在崩溃时自动重新启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56815640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com