我正在尝试在 Ubuntu 中将一个简单的 jar 文件作为服务运行。
下面是运行 jar 的 bash 脚本(/opt/ashish/ser/my-webapp.sh)的内容
#!/bin/sh
sudo /usr/bin/java -jar Main.jar
以下是我的服务文件中的文本
[Unit]
Description=My Webapp Java REST Service
[Service]
User=administrator
# The configuration file application.properties should be here:
#change this to your workspace
WorkingDirectory=/opt/ashish/ser
#path to executable.
#executable is a bash script which calls jar file
ExecStart=/bin/bash /opt/ashish/ser/my-webapp.sh
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
以下是我尝试运行该服务时收到的错误。
sudo: no tty present and no askpass program specified
pam_unix(sudo:auth): conversation failed
pam_unix(sudo:auth): auth could not identify password for [administrator]
下面是我用来创建服务的参考链接。
https://dzone.com/articles/run-your-java-application-as-a-service-on-ubuntu