Linux 启动时启动 java 程序(EC2 实例) [英] Linux Launch java program on startup (EC2 instance)
问题描述
我的服务器程序需要在 EC2 实例启动时启动.此刻,我只是使用以下命令从我的 SSH 启动它:
my server program needs to be launched on the startup of an EC2 instance. At the minute im just launching it from my SSH with the following commands:
java -jar ~/DocumentManager/DocumentServer-0.2.jar
我尝试将其添加到 .bashrc 和/etc/rc.local 文件中,但它们似乎只在我通过 ssh 进入时才起作用.
I tried adding this to the .bashrc and /etc/rc.local files but they only seem to work when i ssh in.
有人知道如何在计算机启动时启动我的应用程序实例吗?
Anyone know how to make it so an instance of my application is launched when the computer boots?
谢谢,
本
推荐答案
你可以像这样创建一个 java_server_launch.sh
脚本:
It's possible you can create a script java_server_launch.sh
like this:
#! /usr/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
JAVA=/usr/bin/java
MY_SERVER=/home/your_username/DocumentManager/DocumentServer-0.2.jar
USER=your_username
/bin/su - $USER -c "$JAVA -jar $MY_SERVER &"
把你的脚本放在/etc/init.d目录下,然后使用命令:
Put your script under /etc/init.d directory, and then use the command:
update-rc.d java_server_launch.sh defaults
更多关于 update-rc.d 命令的信息,请使用 man update-rc.d
.
more on update-rc.d command by using man update-rc.d
.
希望对您有所帮助.
问候.
这篇关于Linux 启动时启动 java 程序(EC2 实例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!