有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在AIX中将jar文件作为服务运行,如果崩溃,它将自动重启?

我有几个jar文件,希望在AIX上作为服务运行。如果服务崩溃/结束,则必须自动重新启动。我怎样才能做到这一点

我有一个shell脚本,它是这样的

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

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


共 (1) 个答案

  1. # 1 楼答案

    您可以检查this page关于AIX中的autostart/restart service/daemon

    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