Linux的启动java程序在启动时(EC2实例) [英] Linux Launch java program on startup (EC2 instance)

查看:261
本文介绍了Linux的启动java程序在启动时(EC2实例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器程序需要在一个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

更多关于更新-的rc.d 的命令,用男人更新-的rc.d

希望这有助于。

问候。

这篇关于Linux的启动java程序在启动时(EC2实例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆