Start a jar file like service in linux [closed]

2020-02-07 19:33发布

I want to start and stop my jar file as follows

service myService start

service myService stop

my current jar file running as follows

cd /home/alex/IdeaProjects/myService
java -jar target/myService-SNAPSHOT-1.jar server config.yml

What should I do?

3条回答
叛逆
2楼-- · 2020-02-07 19:54

If you want to try the DIY way, you can place a startup script in your /etc/init.d directory as said here.

http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/

However, to implement a clean yourScript stop command, I would recommend that you split your functionality into a launcher and a daemon, and make your launcher able to start or communicate with your existing daemon in order to send orders to it. Then your startup script would only invoke your launcher, which in its turn would start a new daemon, or send orders to the existing one.

查看更多
唯我独甜
4楼-- · 2020-02-07 20:04

You need a Service Wrapper to run the Jar file.

There are examples and instructions for init.d here. or for systemd (ubuntu 16+) here

查看更多
登录 后发表回答