使用Linux的systemd运行jar包

mtain 2023年03月07日 739次浏览

服务定义文件

vi /lib/systemd/system/[APP_NAME].service

[Unit]
Description=[APP_NAME]

[Service]
WorkingDirectory=/opt
PrivateTmp=true
Restart=always
Type=simple
ExecStart=/opt/jdk1.8.0_161/bin/java -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -jar /opt/[APP_NAME].jar --spring.profiles.active=prod
ExecStop=/usr/bin/kill -15  $MAINPID

[Install]
WantedBy=multi-user.target


启动命令

systemctl daemon-reload
systemctl enable [APP_NAME]
systemctl start [APP_NAME]
systemctl status [APP_NAME]