在系统启动时在Ubuntu上运行Jar文件


-2

我正在尝试在Ubuntu机器上启动时运行.jar文件,但我没有得到任何地方。我试过这里的说明https://askubuntu.com/questions/99232/how-to-make-a-jar-file-run-on-startup-and-when-you-log-out,我'尝试使用Upstart网站和食谱中的信息,但他们没有工作。我已经尝试了旧的SysV和新的Upstart方法,但它们都没有在系统启动时启动.jar。

这是运行.jar的shell脚本

#!/bin/bash

java -jar TransformationServer.jar

SysV启动方法的文件

#!/bin/bash
# Transformation Server
# 
# Description: Transforms incoming messages on a given port and forwards them

case $1 in
    start)
        /bin/bash /usr/local/bin/ServerStart.sh
    ;;
    stop)
        /bin/bash /usr/local/bin/ServerStop.sh
    ;;
    restart)
        /bin/bash /usr/local/bin/ServerStop.sh
        /bin/bash /usr/local/bin/ServerStart.sh
    ;;
esac
exit 0

UpStart方法

# transformationserver - transforms incoming http messages, and redirects them
#
# This service intercepts incoming http messages on a given port, and
# transforms them into an acceptable format in order to be received
# by a 3rd party service

start on runlevel [345]
stop on runlevel [!2345]

respawn

script
    exec /bin/bash /home/ubuntu/TransformationServer/ServerStart.sh
    # Also trying the below as well
    #exec /bin/java -jar /home/ubuntu/TransformationServer/TransformationServer.jar
end-script

有更多使用这些方法的经验的人可以查看我的文件,并可能指出我正确的方向吗?这项服务是必需的,因此我们的公司系统可以成功接收来自我们客户的通信。

提前致谢。

Answers:


1

你怎么用crontab?

作为您希望jar运行的用户,运行以下命令:

crontab -e

添加行:

@reboot /path/to/your/ServerStart.sh

保存。这将使服务器在重新启动后重新启动时,它将运行您的shell脚本。

这是您的crontab,您可以通过man crontab或Wikipedia页面了解所有相关内容:https//en.wikipedia.org/wiki/Cron

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.