英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论