将Spring Boot Web应用程序作为服务部署到Ubuntu

时间:2018-01-23 12:36:12

标签: java ubuntu spring-boot

我有一个Spring Boot应用程序,我想开始使用System V Init。我的jar文件在/var/my-app/my-app-0.0.1-SNAPSHOT.jar。所以,我使用下面的命令创建了一个符号链接

sudo ln -s /var/my-app/my-app-0.0.1-SNAPSHOT.jar /etc/init.d/my-app-0.0.1-SNAPSHOT

没有任何问题。但是,当我尝试

sudo service my-app-0.0.1-SNAPSHOT start

我收到错误:

/etc/init.d/my-app-0.0.1-SNAPSHOT: 1: /etc/init.d/myapp-0.0.1-SNAPSHOT: Syntax error: Unterminated quoted string

有没有人知道我做错了什么?感谢。

1 个答案:

答案 0 :(得分:2)

符号链接与服务有什么关系?没什么:)

首先必须定义Upstart脚本(在Ubuntu 14.04的情况下),它位于/ etc / init /并以.conf结尾。 (http://upstart.ubuntu.com/cookbook/

# <service name>.conf
start on filesystem
exec /usr/bin/java -jar /path_to/program

如果是Ubuntu 16.06+(你可以找到好文章here

sudo vim /etc/systemd/system/my-webapp.service

然后你可以运行它:

sudo service <your service name> start

希望有所帮助。