Jar as a Service in RHEL 8.2 – Not Starting

huangapple go评论82阅读模式
英文:

Jar as a Service in RHEL 8.2 - Not Starting

问题

我有一个Spring Boot的Uber JAR文件,需要在RHEL 8.2环境中作为服务运行。

/etc/systemd/system/myapp.service中创建的服务文件内容如下:

[Unit]
Description=myapp

[Service]
User=appuser
WorkingDirectory=/home/appuser 
ExecStart=/usr/bin/java -Xmx256m -jar -Dspring.profiles.active=test /home/appuser/myapp.jar 
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

现在,当我尝试启动服务并使用以下命令检查状态时,出现以下错误:

[root@myappdev01 /etc/systemd/system]# sudo systemctl status myapp
myapp.service - myapp
   Loaded: loaded (/etc/systemd/system/myapp.service; disabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2020-09-11 23:48:26 +04; 5s ago
  Process: 273497 ExecStart=/usr/bin/java -jar -Dspring.profiles.active=test /home/appuser/myapp.jar (code=exited, status=1/FAILURE)
 Main PID: 273497 (code=exited, status=1/FAILURE)

Sep 11 23:48:26 myappdev01.server systemd[1]: myapp.service: Main process exited, code=exited, status=1/FAILURE
Sep 11 23:48:26 myappdev01.server systemd[1]: myapp.service: Failed with result 'exit-code'.

使用journatlctl -u myapp.service也没有提供太多帮助。

我在这里做错了什么?

英文:

I have a spring boot uber jar that I need to run as a service in RHEL 8.2 environment.

The service file created in /etc/systemd/system/myapp.service is as simple as this:

[Unit]
Description=myapp

[Service]
User=appuser
WorkingDirectory=/home/appuser 
ExecStart=/usr/bin/java -Xmx256m -jar -Dspring.profiles.active=test /home/appuser/myapp.jar 
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Now when I try to start the service and check the status using the below commands I get the below error:

[root@myappdev01 /etc/systemd/system]# sudo systemctl status myapp
myapp.service - myapp
   Loaded: loaded (/etc/systemd/system/myapp.service; disabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2020-09-11 23:48:26 +04; 5s ago
  Process: 273497 ExecStart=/usr/bin/java -jar -Dspring.profiles.active=test /home/appuser/myapp.jar (code=exited, status=1/FAILURE)
 Main PID: 273497 (code=exited, status=1/FAILURE)

Sep 11 23:48:26 myappdev01.server systemd[1]: myapp.service: Main process exited, code=exited, status=1/FAILURE
Sep 11 23:48:26 myappdev01.server systemd[1]: myapp.service: Failed with result 'exit-code'.

journatlctl -u myapp.service also doesn't help much.

What have I done wrong here?

答案1

得分: 1

The jar you're using needs to come directly after the -jar flag:

ExecStart=/usr/bin/java -Xmx256m -Dspring.profiles.active=test -jar /home/appuser/myapp.jar
英文:

The jar you're using needs to come directly after the -jar flag:

ExecStart=/usr/bin/java -Xmx256m -Dspring.profiles.active=test -jar /home/appuser/myapp.jar 

huangapple
  • 本文由 发表于 2020年9月12日 04:04:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63853623.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定