Linux Launch java program on startup (EC2 instance)

前端 未结 2 808
心在旅途
心在旅途 2020-12-21 16:15

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 -         


        
相关标签:
2条回答
  • 2020-12-21 16:29

    Add ampersand(symbol '&') at the end of the command. For example, in your case, java -jar ~/DocumentManager/DocumentServer-0.2.jar &

    Old question, but my answer might be helpful for people who look in future.

    0 讨论(0)
  • 2020-12-21 16:36

    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 &"
    

    Put your script under /etc/init.d directory, and then use the command:

    update-rc.d java_server_launch.sh defaults
    

    more on update-rc.d command by using man update-rc.d.

    Hope this help.

    Regards.

    0 讨论(0)
提交回复
热议问题