在 ubuntu 14.04.1 上部署 SpringBoot jar 作为服务后出现语法错误 [英] Syntax Error After deploy SpringBoot jar as service on ubuntu 14.04.1

查看:23
本文介绍了在 ubuntu 14.04.1 上部署 SpringBoot jar 作为服务后出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个打包为 jar 文件的 springboot web 应用程序.产品服务器是Ubuntu 14.04.1,安装了openjdk-8-jdk.

I have a springboot web application packaged as a jar file. And the product server is Ubuntu 14.04.1 with openjdk-8-jdk installed.

我可以使用以下方法成功运行应用程序:

I can successfully run the application using:

sudo java -jar /home/myUser/my_web_app.jar

然后我通过以下命令将此应用程序作为 SystemV 服务:

Then I make this appliaction as a SystemV service by following commands:

sudo useradd webUser
sudo passwd webUser
sudo chown webUser:webUser /home/myUser/my_web_app.jar
sudo chmod 500 /home/myUser/my_web_app.jar
sudo ln -s /home/myUser/my_web_app.jar /etc/init.d/my_web_app

在那之后,当我运行时:

After that, when I run:

sudo service my_web_app start

错误提示为:

/etc/init.d/my_web_app: 1: /etc/init.d/my_web_app: Syntax error: ")" unexpected.

我想知道是什么导致了这个错误以及如何重新处理它.谢谢.

I wonder what cause this error and how to reslove it. Thanks.

顺便说一句,同样的方法适用于我的开发机器(Ubuntu 14.04.6).

BTW, Same method works on my devlopment machine (Ubuntu 14.04.6).

推荐答案

问题是这两行:

sudo chmod 500 /home/myUser/my_web_app.jar
sudo ln -s /home/myUser/my_web_app.jar /etc/init.d/my_web_app

问题 #1:常规的可执行 JAR 文件不是操作系统可识别的可执行格式1.

Problem #1: regular executable JAR files are not an executable format that the OS recognizes1.

在常规 JAR 文件上设置执行位无济于事.操作系统内核不知道如何运行它.要运行常规 JAR,您必须执行命令 java -jar/path/to/the.jar.如有必要,您可以创建一个简单的包装器脚本来执行此操作.

Setting the execute bit on a regular JAR file won't help. The OS kernel does not know how to run it. To run a regular JAR, you have to execute the command java -jar /path/to/the.jar. If necessary, you can create a simple wrapper script to do this.

1 - 有一种方法可以生成一个特殊的完全可执行"的 SpringBoot JAR 文件,该文件前面有一个 shell 脚本;参见 安装 Spring Boot 应用程序".这是解决此问题的一种方法,尽管文档指出这些特殊的 JAR 文件会导致某些工具出现问题.

1 - There is a way to generate a special "fully executable" SpringBoot JAR file which has an shell script prepended to it; see "Installing Spring Boot Applications". This is one way to get around this problem, though the documentation states that these special JAR files cause problems for some tools.

问题#2: /etc/init.d 中的文件应该是服务脚本.

Problem #2: The files in /etc/init.d are supposed to be service scripts.

它们不仅仅是服务的可执行文件.这些脚本应该是能够理解诸如 startstoprestartreload 等动词的 shell 脚本上.并且(AFAIK)它们必须被编码为 sh 兼容的 shell 脚本.这里有一篇文章描述了服务脚本的结构:

They are not simply the executable for a service. The scripts are supposed to be shell scripts that understand verbs such as start, stop, restart, reload and so on. And (AFAIK) they must be coded as sh compatible shell scripts. Here is an article that describes the structure of service scripts:

(但请先阅读第 4 题!!)

(But read Problem #4 first!!)

问题 #3:以 root 身份运行服务可能存在安全风险.

Problem #3: Running a service as root can be a security risk.

最好创建一个(非特权)服务帐户来运行服务.如果服务暴露在网络中,这一点尤其重要.(如果坏人可以通过网络入侵"该服务并导致它做一些不受欢迎的事情,那么它以 root 身份运行的事实会使整个系统处于危险之中.)

It is better to create a (non-privileged) service account to run the service. This is especially important if the service is exposed to the network. (If the bad guys can "hack" the service over the network and cause it to do undesirable things, the fact that it is running as root places the entire system at risk.)

问题 #4: /etc/init.d/ 脚本已经过时.

如果您使用的是最近的 Ubuntu 版本(15.04 或更高版本),那些 /etc/init.d/ 脚本是传统"的配置方式.initd 机制的当前迭代是 systemd.它使用 systemd 单元文件而不是服务脚本.以下文章提供了更多信息:

If you are using a recent Ubuntu release (15.04 or later), those /etc/init.d/ scripts are the "legacy" way of configuring. The current iteration of the initd mechanism is systemd. It uses systemd unit files files rather than service scripts. The following article gives more information:

systemd 服务包括用于遗留服务脚本,但它们不像单元文件那样强大、灵活和……简洁…….

The systemd service includes for legacy service scripts, but they are not as powerful, flexible and ... concise ... as unit files.

问题 #5: Ubuntu 14.04 LTS 已停产.

Problem #5: Ubuntu 14.04 LTS has reached end-of-life.

您应该升级到 16.04 LTS 或最好是 18.04 LTS.为您的生产服务器使用报废的操作系统是不明智的.

You should upgrade to 16.04 LTS or preferably 18.04 LTS. It is unwise to use an end-of-life operating system for your production server(s).

请注意,网络上有很多文档和许多关于配置服务的新旧方法的文章.(谷歌是你的朋友.)

Note that there is a lot of documentation, and many articles on the web about both the old and new ways of configuring services. ( Google is your friend. )

这篇关于在 ubuntu 14.04.1 上部署 SpringBoot jar 作为服务后出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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