问题原文
原帖链接 · Janith · CC BY-SA 4.0
I want to start java application on system boot using systemd. I tried to do by adding above scripts. But service is not starting.
my-startup.service
[Unit]
Description=Startup
[Service]
ExecStart=/usr/local/sbin/my-startup.sh
[Install]
WantedBy=multi-user.target
my-startup.sh
cd /var/www/test.com
nohup java -jar *.jar>test.out 2>test.err &
But application not starting when server starting.
● my-startup.service - Startup
Loaded: loaded (/etc/systemd/system/my-startup.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Wed 2018-12-12 16:22:52 +0530; 27s ago
Process: 650 ExecStart=/usr/local/sbin/my-startup.sh (code=exited, status=0/SUCCESS)
Main PID: 650 (code=exited, status=0/SUCCESS)
Dec 12 16:22:52 localhost.localdomain systemd[1]: Started Startup.
Dec 12 16:22:52 localhost.localdomain systemd[1]: Starting Startup...
已采纳解答
原帖链接 · John Mahowald · CC BY-SA 4.0
Using systemd directives in place of shell results in a more consistent environment. This includes not relying on $PATH or the working directory by providing full paths where they are known.
Neither & for job control, nor managing SIGHUP is needed. systemd service units are already backgrounded.
Assuming the program doesn't fork, in other words the java exec keeps running, that's Type=simple
[Unit]
Description=something
[Service]
ExecStart=/usr/bin/java -jar /var/www/test.com/something.jar
StandardOutput=file:/var/log/something.out.txt
StandardError=file:/var/log/something.err.txt
Type=simple
WorkingDirectory=/var/www/test.com
[Install]
WantedBy=multi-user.target
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
